<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Nipun Parekh</title>
    <description>The latest articles on Forem by Nipun Parekh (@nipun214).</description>
    <link>https://forem.com/nipun214</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F478885%2F935fb7f0-c76b-4732-9b35-ba2846839a9d.png</url>
      <title>Forem: Nipun Parekh</title>
      <link>https://forem.com/nipun214</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nipun214"/>
    <language>en</language>
    <item>
      <title>Deploying a Static Website In a Container and  Ship it any Anywhere </title>
      <dc:creator>Nipun Parekh</dc:creator>
      <pubDate>Wed, 27 Oct 2021 05:15:21 +0000</pubDate>
      <link>https://forem.com/nipun214/deploying-a-static-website-in-a-container-and-ship-it-any-anywhere-4b68</link>
      <guid>https://forem.com/nipun214/deploying-a-static-website-in-a-container-and-ship-it-any-anywhere-4b68</guid>
      <description>&lt;p&gt;What is Docker?&lt;/p&gt;

&lt;p&gt;Ans: Docker is a set of platform as a service products that use virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files.&lt;/p&gt;

&lt;p&gt;Steps that we are going to perform:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creating Docker file&lt;/li&gt;
&lt;li&gt;Create an image of our static website with use of Docker file&lt;/li&gt;
&lt;li&gt;Push that image to Docker Hub&lt;/li&gt;
&lt;li&gt;Run that container on Server&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Creating Docker File:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM nginx:latest
COPY . /usr/share/nginx/html
EXPOSE 80
CMD [“nginx”,”-g”,”daemon off;”]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;FROM — is where we are pulling our official image from nginx is an official image provided by Docker&lt;/p&gt;

&lt;p&gt;COPY — is taking our all file from out local directory were are working in and moves it into the /usr/share/nginx/html directory(of NGINX) in our container.&lt;/p&gt;

&lt;p&gt;EXPOSE- is a instruction letting the container know we are exposing the port 80 (TCP)&lt;/p&gt;

&lt;p&gt;CMD- provide defaults for an executing container&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create an image of our static website with use of Docker file:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For that we have to execute command and that is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t "&amp;lt;name of image you have to put&amp;gt;" .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command means :&lt;/p&gt;

&lt;p&gt;-t = Tag&lt;br&gt;
"" = your image name &lt;br&gt;
. = it will take dockerfile form present location.&lt;/p&gt;

&lt;p&gt;So in my case, I am going to give image name as nipun2020/docker-community-rajkot&lt;/p&gt;

&lt;p&gt;command will be for me :)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t nipun2020/docker-community-rajkot .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Push that image to Docker Hub&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To push our image in docker hub for that we will use this command&lt;/p&gt;

&lt;p&gt;docker push &lt;/p&gt;

&lt;p&gt;in my case it will be -&amp;gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker push nipun2020/docker-community-rajkot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Run that container on Server&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Login into your server and make sure docker is installed on your server.&lt;/p&gt;

&lt;p&gt;and just hit this command and your container will be running on your server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -p 80:80 nipun2020/docker-community-rajkot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So by use of this command your static website will be running with the use of Docker.&lt;/p&gt;

&lt;p&gt;Demo of static site is hosted:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz3rudnw7sdkcekc0vdth.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz3rudnw7sdkcekc0vdth.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading this blog, hope you learned some new thing.&lt;/p&gt;

&lt;p&gt;If, you have any doubt you can contact me on LinkedIn&lt;br&gt;
LinkedIn: &lt;a href="https://www.linkedin.com/in/nipun-parekh-6006a0152/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/nipun-parekh-6006a0152/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
      <category>webdev</category>
    </item>
    <item>
      <title>CDN Invalidation using AWS Lambda Function</title>
      <dc:creator>Nipun Parekh</dc:creator>
      <pubDate>Sat, 22 May 2021 08:29:42 +0000</pubDate>
      <link>https://forem.com/aws-builders/cdn-invalidation-using-aws-lambda-function-2pg4</link>
      <guid>https://forem.com/aws-builders/cdn-invalidation-using-aws-lambda-function-2pg4</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdrglrlo6m6w9bjyijpbm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdrglrlo6m6w9bjyijpbm.png" alt="Alt Text" width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Steps to create Invalidation using lambda function are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a Lambda Function and write a code.&lt;/li&gt;
&lt;li&gt;Create an API Gateway / API from which we are going to create 
 Invalidation of CDN&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step:1&lt;br&gt;
Creating a Lambda Function:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv4xagib2j0hbjys21a9e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv4xagib2j0hbjys21a9e.png" alt="Alt Text" width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just give a name of the function and use the Runtime of python 3.8 and put rest all things as it is.&lt;/p&gt;

&lt;p&gt;Now Click on Create Button and Your Function is created.&lt;/p&gt;

&lt;p&gt;When you go inside a function you will find this window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq8kks8mb44wurwrr8z7n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq8kks8mb44wurwrr8z7n.png" alt="Alt Text" width="800" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Paste this code inside the code area.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;from &lt;strong&gt;future&lt;/strong&gt; import print_function&lt;/p&gt;

&lt;p&gt;import boto3&lt;br&gt;
import time&lt;/p&gt;

&lt;p&gt;def lambda_handler(event, context):&lt;br&gt;
 client = boto3.client(‘cloudfront’)&lt;br&gt;
 path = “/*”&lt;br&gt;
 invalidation = client.create_invalidation(DistributionId=”Put your CDN ID”,&lt;br&gt;
   InvalidationBatch={&lt;br&gt;
    ‘Paths’: {&lt;br&gt;
    ‘Quantity’: 1,&lt;br&gt;
    ‘Items’: [path]&lt;br&gt;
   },&lt;br&gt;
   ‘CallerReference’: str(time.time())&lt;br&gt;
  })&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You will get your CDN ID from Cloudfront Dashboard like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftos5r6u6786smdwye0lg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftos5r6u6786smdwye0lg.png" alt="image" width="800" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now attach the Cloudfront full access policy to our lambda policy like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkmiikc3l6j0azuau3qz1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkmiikc3l6j0azuau3qz1.png" alt="image" width="800" height="85"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have completed step 1.&lt;/p&gt;

&lt;p&gt;Step:2&lt;/p&gt;

&lt;p&gt;Create an API for that you have to use AWS API Gateway Service.&lt;/p&gt;

&lt;p&gt;Create HTTP API. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbuxen5xjuq62zp7if882.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbuxen5xjuq62zp7if882.png" alt="image" width="800" height="528"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Integration, section adds lambda and selects your lambda function in my case it is an invalidation name of the function.&lt;/p&gt;

&lt;p&gt;And rest all thing keep as it is and create an API.&lt;/p&gt;

&lt;p&gt;We have successfully completed all the steps.&lt;/p&gt;

&lt;p&gt;Now come to the lambda function and reload our lambda function page and you will get our API Gateway in the trigger section like this &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fajy3145ppvw750odmify.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fajy3145ppvw750odmify.png" alt="image" width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now Click on API Gateway you will get something page like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh6kl1wr1vx52nydo4ye8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh6kl1wr1vx52nydo4ye8.png" alt="image" width="800" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on API Endpoint and execute this URL in the browser and here your CDN invalidation is created.&lt;/p&gt;

&lt;p&gt;You can check it like this:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgqnoukzoqnuvayp0saas.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgqnoukzoqnuvayp0saas.png" alt="image" width="800" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So here we Created a CND Invalidation using AWS Lambda Function.&lt;/p&gt;

&lt;p&gt;Thank you for reading this blog, hope you learned some new thing.&lt;/p&gt;

&lt;p&gt;Still, if you have any query you can refer to my video &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=sDT1sg72fUY" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=sDT1sg72fUY&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Still, you have any doubt you can contact me on LinkedIn&lt;/p&gt;

&lt;p&gt;LinkedIn: &lt;a href="https://www.linkedin.com/in/nipun-parekh-6006a0152/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/nipun-parekh-6006a0152/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cdn</category>
      <category>awslambda</category>
      <category>cloudskills</category>
    </item>
  </channel>
</rss>
