<?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>DEV Community: Akshay Jain</title>
    <description>The latest articles on DEV Community by Akshay Jain (@akshaykrjain).</description>
    <link>https://dev.to/akshaykrjain</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%2F191350%2Fa6876547-baf0-4560-bad6-c3034384779a.jpeg</url>
      <title>DEV Community: Akshay Jain</title>
      <link>https://dev.to/akshaykrjain</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akshaykrjain"/>
    <language>en</language>
    <item>
      <title>Deploy A Single Page Static Application on AWS CloudFront Distribution using Terraform</title>
      <dc:creator>Akshay Jain</dc:creator>
      <pubDate>Thu, 13 Aug 2020 16:50:34 +0000</pubDate>
      <link>https://dev.to/akshaykrjain/deploy-a-single-page-static-application-on-aws-cloudfront-distribution-using-terraform-oa7</link>
      <guid>https://dev.to/akshaykrjain/deploy-a-single-page-static-application-on-aws-cloudfront-distribution-using-terraform-oa7</guid>
      <description>&lt;h1&gt;
  
  
  Deploy A Single Page Static Application on AWS CloudFront Distribution using Terraform
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;A Terraform Module which will deploy a SPA on AWS CloudFormation backed by S3 Buckets&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  High-Level Architecture Diagram
&lt;/h2&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%2Fi%2Fopql0k36fck34lphv7cy.jpg" 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%2Fi%2Fopql0k36fck34lphv7cy.jpg" alt="Architecture" width="800" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Security Features and best practices used:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  S3 Bucket :
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Private &lt;/li&gt;
&lt;li&gt;Encrypted &lt;/li&gt;
&lt;li&gt;Versioning Enabled
### DNS : &lt;/li&gt;
&lt;li&gt;Bring your own domain &lt;/li&gt;
&lt;li&gt;DNS Records manageable in AWS Route53&lt;/li&gt;
&lt;li&gt;Failover with AWS itself&lt;/li&gt;
&lt;li&gt;ACM Certificates
### Security :&lt;/li&gt;
&lt;li&gt;IP Based Access Control&lt;/li&gt;
&lt;li&gt;Basic Auth using static user name and password (Utilized Powerful Lambda@Edge)&lt;/li&gt;
&lt;li&gt;AWS WAF the possibility to add advanced security rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;p&gt;Make sure you have the latest version of the following before deploying. (Or Your CI Platform is ready)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;node.js&lt;/code&gt;( or any other standard SPA framework)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;aws cli&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;terraform&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;The DNS Domain of Your Site&lt;/code&gt; (With edit rights to DNS Records)&lt;/li&gt;
&lt;li&gt;All &lt;code&gt;tf&lt;/code&gt; files copied from this repository (&lt;code&gt;git clone https://github.com/akshaykrjain/cloudfront_terrafrom.git&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Steps to Deploy
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. Build A Sample SPA (Skip if your SPA is already built and ready)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app my-app
cd my-app
npm run build 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;em&gt;Feel free to use &lt;a href="https://gohugo.io/"&gt;Hugo&lt;/a&gt; framework in the similar manner&lt;/em&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Obtain AWS ACM Certification
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Login to AWS Console&lt;/li&gt;
&lt;li&gt;Select US East (N. Virginia) region (Need to obtain Global Cert for CloudFront)&lt;/li&gt;
&lt;li&gt;Request or Import SSL Certificate to your domain&lt;/li&gt;
&lt;li&gt;Select Any suitable validation method (DNS or E Mail)&lt;/li&gt;
&lt;li&gt;Note down the arn of the issued certificate . (It can take few minutes to get it issued)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;&lt;em&gt;Note- This step can be automated using Terraform, but AWS can take up to 30 mins to issue which will create problems for our TF module deployment&lt;/em&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Provide Values of Variables.
&lt;/h2&gt;

&lt;p&gt;Edit &lt;a href="//variables.tf"&gt;&lt;code&gt;variables.tf&lt;/code&gt;&lt;/a&gt; and edit all the variables as per your wish&lt;/p&gt;

&lt;p&gt;Edit &lt;a href="//headers.js#L8"&gt;&lt;code&gt;headers.js&lt;/code&gt;&lt;/a&gt; and provide static user name and password to protect your site&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Deploy the Infrastructure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform init
terraform plan
terraform apply 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Copy the Application and Static Files to newly created buckets.
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Copy SPA Main application files
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws s3 cp --recursive build/ s3://&amp;lt;spa-app-bucket-name&amp;gt;/  --exclude "*static/*" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Copy Static Files to Bucket-2
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws s3 cp --recursive ./build/static/ s3://&amp;lt;static-data-bucket-name&amp;gt;/static/  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;~ Tip - &lt;code&gt;aws s3 sync&lt;/code&gt; can also be used for subsequent changes in application &lt;/p&gt;

&lt;h2&gt;
  
  
  Test
&lt;/h2&gt;

&lt;p&gt;Execute the following test cases to verify our deployment&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open &lt;a href="http://www.(domain"&gt;www.(domain&lt;/a&gt; name) (eg. &lt;a href="http://www.myapp.com"&gt;www.myapp.com&lt;/a&gt;) from the whitelisted IP ,User name and password should be prompted and webpage should be displayed if provided correctly otherwise an error page should be displayed&lt;/li&gt;
&lt;li&gt;repeat the same from another IP , error should be displayed&lt;/li&gt;
&lt;li&gt;S3 Bucket objects should not be accessed directly&lt;/li&gt;
&lt;li&gt;Application Updates should be replicated to edge locations within hours&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(TODO : Python Scripts or Terratest for the automatic test)&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>aws</category>
      <category>cloudformation</category>
      <category>spa</category>
    </item>
    <item>
      <title>Hosting a Sample Python Flask Application on AWS EC2 with AutoScaling and LoadBalancer(Ready CloudFormation)</title>
      <dc:creator>Akshay Jain</dc:creator>
      <pubDate>Mon, 08 Jul 2019 08:39:34 +0000</pubDate>
      <link>https://dev.to/akshaykrjain/hosting-a-sample-python-flask-application-on-aws-ready-cloudformation-1lda</link>
      <guid>https://dev.to/akshaykrjain/hosting-a-sample-python-flask-application-on-aws-ready-cloudformation-1lda</guid>
      <description>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open AWS Console (or aws cli)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a new stack&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use below cloud formation&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://github.com/akshaykrjain/coffee_with_code/blob/master/cloudformation/aws_cft.yaml"&gt;https://github.com/akshaykrjain/coffee_with_code/blob/master/cloudformation/aws_cft.yaml&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note-  - Change the user data part to your custome code. A sample code is already added in this cloud formation template.&lt;br&gt;
       - Make sure you have atleast 1 public and 1 private subnet ready.&lt;br&gt;
       - Private subnet must be able to connect to internet (Use Internet Gateway or NAT for that)&lt;/p&gt;

</description>
      <category>aws</category>
      <category>flask</category>
      <category>cloudfomation</category>
      <category>python</category>
    </item>
  </channel>
</rss>
