<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anurag Kumar on Medium]]></title>
        <description><![CDATA[Stories by Anurag Kumar on Medium]]></description>
        <link>https://medium.com/@anuragabcr?source=rss-d9babe26592c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*iEBNAdg7SeDHcVNz</url>
            <title>Stories by Anurag Kumar on Medium</title>
            <link>https://medium.com/@anuragabcr?source=rss-d9babe26592c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 19:17:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anuragabcr/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Host Your Static Website on AWS S3 with Terraform]]></title>
            <link>https://aws.plainenglish.io/host-your-static-website-on-aws-s3-with-terraform-43efb2be90fc?source=rss-d9babe26592c------2</link>
            <guid isPermaLink="false">https://medium.com/p/43efb2be90fc</guid>
            <category><![CDATA[hosting]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[s3-bucket]]></category>
            <dc:creator><![CDATA[Anurag Kumar]]></dc:creator>
            <pubDate>Mon, 18 Mar 2024 05:32:38 GMT</pubDate>
            <atom:updated>2024-03-19T04:01:21.672Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_XXZUU1pMYYJn2fb.jpeg" /></figure><p>In this step-by-step guide, we’ll dive into deploying a static website on AWS S3 using Terraform! We’ll walk through the process of:</p><ul><li><strong>Automating S3 Bucket Creation:</strong> Terraform will handle creating the S3 bucket where your website files will reside.</li><li><strong>Effortless Website Upload:</strong> We’ll configure Terraform to skip manual uploads by referencing your website files locally.</li><li><strong>Public Access for All:</strong> Terraform will configure the S3 bucket policy to grant public read access, ensuring anyone can access your website.</li><li><strong>Enabling Web Hosting:</strong> Terraform will transform your S3 bucket into a fully functional static website, ready to serve your content to the world.</li></ul><p>By the end, you’ll have a Terraform script that automates the entire deployment process, saving you time and ensuring a secure and accessible website.</p><blockquote>You can get the complete code <a href="https://github.com/anuragabcr/terraform/tree/main/day-7"><strong><em>here</em></strong></a>.</blockquote><p><strong>Step 1: Setup the Terraform</strong></p><p>Create a ‘terraform.tf’ file to set up the terraform and provider.</p><pre># Terraform<br>terraform {<br>  required_version = &quot;1.7.4&quot;<br>  required_providers {<br>    aws = {<br>        source = &quot;hashicorp/aws&quot;<br>        version = &quot;5.40.0&quot;<br>    }<br>  }<br>}<br><br>#Provider<br>provider &quot;aws&quot; {<br>  profile = &quot;default&quot;<br>  region = &quot;ap-south-1&quot;<br>}</pre><p><em>Terraform Configuration Block:</em></p><ul><li>terraform { ... }: This block defines the Terraform configuration itself.</li><li>required_version = &quot;1.7.4&quot;: This line specifies the minimum Terraform version required to run this configuration. Ensure your Terraform installation meets or exceeds this version.</li><li>required_providers { ... }: This section defines the external providers required for this infrastructure.</li></ul><p><em>AWS Provider Block:</em></p><ul><li>provider &quot;aws&quot; { ... }: This block further configures the AWS provider we defined earlier.</li><li>profile = &quot;default&quot;: This tells Terraform to use the default AWS profile configured in your local AWS credentials. Make sure you have a proper AWS profile set up with the necessary permissions to create S3 buckets and configure web hosting.</li><li>region = &quot;ap-south-1&quot;: This line specifies the AWS region where your infrastructure will be deployed.</li></ul><p><strong>Step 2: Configuration for S3 bucket</strong></p><p>Create a ‘bucket.tf’ file to store the terraform configuration related to the S3 bucket.</p><pre># Create S3 Bucket<br>resource &quot;aws_s3_bucket&quot; &quot;terraform-demo-43234&quot; {<br>  bucket = &quot;terraform-demo-43234&quot;<br>}<br><br># Upload file to S3<br>resource &quot;aws_s3_object&quot; &quot;terraform_index&quot; {<br>  bucket = aws_s3_bucket.terraform-demo-43234.id<br>  key = &quot;index.html&quot;<br>  source = &quot;index.html&quot;<br>  content_type = &quot;text/html&quot;<br>  etag = filemd5(&quot;index.html&quot;)<br>}<br><br># S3 Web hosting<br>resource &quot;aws_s3_bucket_website_configuration&quot; &quot;terraform_hosting&quot; {<br>  bucket = aws_s3_bucket.terraform-demo-43234.id<br><br>  index_document {<br>    suffix = &quot;index.html&quot;<br>  }<br>}</pre><p><em>Create S3 Bucket (resource “aws_s3_bucket” “terraform-demo-43234”)</em></p><ul><li>This block creates a new S3 bucket named “terraform-demo-43234”. This bucket will store all the files for your website.</li></ul><p><em>Upload File to S3 (resource “aws_s3_object” “terraform_index”)</em></p><ul><li>This block uploads a specific file, “index.html”, to the S3 bucket created earlier.</li><li>It references the bucket using aws_s3_bucket.terraform-demo-43234.id. Terraform automatically retrieves the bucket&#39;s unique identifier after creating it.</li><li>It sets the key to &quot;index.html&quot;, which acts like a filename within the S3 bucket.</li><li>The source property tells Terraform where to find the &quot;index.html&quot; file on your local machine.</li><li>It sets the content_type as &quot;text/html&quot; to properly identify the file as HTML content.</li><li>The etag property calculates a hash of the local file, ensuring data integrity during upload.</li></ul><p><em>S3 Web Hosting (resource “aws_s3_bucket_website_configuration” “terraform_hosting”)</em></p><ul><li>This block configures the S3 bucket for website hosting.</li><li>It references the same bucket again using aws_s3_bucket.terraform-demo-43234.id.</li><li>Within the index_document block, it specifies that the &quot;index.html&quot; file (identified by its suffix) should be the default file served when someone visits the website.</li></ul><p><strong>Step 3: Configuration for bucket Policy</strong></p><p>Create a ‘policy.tf’ file to store the terraform configuration related to the bucket policy for public access.</p><pre># S3 public access<br>resource &quot;aws_s3_bucket_public_access_block&quot; &quot;terraform-demo&quot; {<br>    bucket = aws_s3_bucket.terraform-demo-43234.id<br>  block_public_acls = false<br>  block_public_policy = false<br>}<br><br># S3 public Read policy<br>resource &quot;aws_s3_bucket_policy&quot; &quot;open_access&quot; {<br>  bucket = aws_s3_bucket.terraform-demo-43234.id<br><br>  policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Id      = &quot;Public_access&quot;<br>    Statement = [<br>      {<br>        Sid = &quot;IPAllow&quot;<br>        Effect = &quot;Allow&quot;<br>        Principal = &quot;*&quot;<br>        Action = [&quot;s3:GetObject&quot;]<br>        Resource = &quot;${aws_s3_bucket.terraform-demo-43234.arn}/*&quot;<br>      },<br>    ]<br>  })<br>  depends_on = [ aws_s3_bucket_public_access_block.terraform-demo ]<br>}</pre><p><em>S3 Public Access Block (resource “aws_s3_bucket_public_access_block” “terraform-demo”)</em></p><ul><li>This block temporarily disables S3’s default Block Public Access settings for this specific bucket. This is necessary because we’ll be applying a custom policy to grant public read access, and the default block could override those permissions.</li><li>bucket = aws_s3_bucket.terraform-demo-43234.id: References the S3 bucket we created earlier.</li><li>block_public_acls = false: Disables blocking of public access control lists (ACLs).</li><li>block_public_policy = false: Disables blocking of public bucket policies.</li></ul><p><em>S3 Public Read Policy (resource “aws_s3_bucket_policy” “open_access”)</em></p><ul><li>This block defines a custom bucket policy that grants public read access to the objects within the bucket.</li><li>bucket = aws_s3_bucket.terraform-demo-43234.id: References the S3 bucket again.</li><li>policy = jsonencode({ ... }): Specifies the actual policy document in JSON format.</li><li>depends_on = [ aws_s3_bucket_public_access_block.terraform-demo ]: Ensures the public access block is applied before the policy, as they interact with each other.</li></ul><p><strong>Step 4: Configuration for Output variable</strong></p><p>This is an optional step. We are doing this to get a static website URL which we can also get through AWS Console. Create an ‘output.tf’ to print out the URL to access the website.</p><pre># Website URL<br>output &quot;website_url&quot; {<br>  value = &quot;http://${aws_s3_bucket.terraform-demo-43234.bucket}.s3-website.${aws_s3_bucket.terraform-demo-43234.region}.amazonaws.com&quot;<br>}</pre><p><strong>Step 5: Initialize Terraform</strong></p><p>Open the command prompt or terminal &amp; navigate to the folder where the terraform file is located and run the below command.</p><pre>terraform init</pre><p>It essentially prepares Terraform’s working directory for managing infrastructure. It downloads and installs any required provider plugins based on your configuration like hashicorp/aws provider.</p><p><strong>Step 6: Terraform Validate</strong></p><pre>terraform validate</pre><p>It performs a static analysis of your Terraform configuration files and validates the overall syntax of your Terraform code, ensuring it adheres to the Terraform language rules.</p><p><strong>Step 7: Terraform Plan</strong></p><pre>terraform plan</pre><p>It is used for understanding and reviewing the intended changes to your infrastructure before actually applying them.</p><p><strong>Step 8: Terraform Apply</strong></p><pre>terraform apply</pre><p>The Terraform apply command in Terraform is the one that actually executes the actions outlined in the plan generated by the Terraform plan. It’s the final step in making the desired infrastructure changes a reality.</p><p>If it runs successfully you can go ahead and open the AWS console to verify the open EC2 instance is created.</p><p><strong>Step 9: Destroy</strong></p><pre>terraform destroy</pre><p>The terraform destroy command in Terraform serves the purpose of tearing down the infrastructure resources that your Terraform configuration currently manages.</p><p><strong>Conclusion:</strong></p><p>In this comprehensive guide, we have walked through the process of deploying a static website on AWS S3 using Terraform. By following the step-by-step instructions outlined above, you can automate the creation of S3 buckets, effortlessly upload your website files, configure public access policies, and enable web hosting with ease.</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a><strong> | </strong><a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://stackademic.com/"><strong>Stackademic</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a><strong> | </strong><a href="https://blog.cubed.run/"><strong>Cubed</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43efb2be90fc" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/host-your-static-website-on-aws-s3-with-terraform-43efb2be90fc">Host Your Static Website on AWS S3 with Terraform</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform Your VPC: Create Public, Private & Database Subnets in Two AZs]]></title>
            <link>https://medium.com/@anuragabcr/terraform-your-vpc-create-public-private-database-subnets-in-two-azs-f7359ff8cd2e?source=rss-d9babe26592c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7359ff8cd2e</guid>
            <category><![CDATA[vpc]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Anurag Kumar]]></dc:creator>
            <pubDate>Thu, 14 Mar 2024 05:20:23 GMT</pubDate>
            <atom:updated>2024-03-14T05:20:23.711Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/581/0*keFdB6l5kJ1b4nhZ.png" /></figure><p>In this walkthrough, we’ll embark on a journey to build a robust and secure network foundation for your applications in the vast world of AWS. We’ll achieve this by constructing a Virtual Private Cloud (VPC) with dedicated subnets, each catering to a specific role within your application architecture.</p><p><strong>Step 1: Create a Setup terraform file</strong></p><p>Create a ‘setup.tf’ file for configuring the terraform.</p><pre># Terraform block<br>terraform {<br>  required_version = &quot;~&gt; 1.7.4&quot;<br>  required_providers {<br>    aws = {<br>        source = &quot;hashicorp/aws&quot;<br>        version = &quot;5.40.0&quot;<br>    }<br>  }<br>}<br><br># Provider block<br>provider &quot;aws&quot; {<br>  profile = &quot;default&quot;<br>  region = &quot;ap-south-1&quot;<br>}</pre><p><em>1. Terraform Block:</em></p><p>This block specifies the required Terraform version (~&gt; 1.7.4) and declares the necessary providers needed for this configuration. Here, it requires the aws provider.</p><ul><li>required_version: Ensures Terraform version compatibility with the configuration.</li><li>required_providers: Defines the providers needed to interact with cloud platforms (AWS in this case).</li></ul><p><em>2. Provider Block:</em></p><p>This block configures the aws provider with details for interacting with AWS services:</p><ul><li>profile: Specifies the AWS credentials profile to use (set to &quot;default&quot; here).</li><li>region: Defines the AWS region where resources will be created (set to &quot;ap-south-1&quot; in this instance).</li></ul><p><strong>Step 2: Create a VPC terraform file</strong></p><p>Create a ‘vpc.tf’ file to define the VPC-related configuration.</p><pre># Create VPC module<br>module &quot;vpc&quot; {<br>  source  = &quot;terraform-aws-modules/vpc/aws&quot;<br>  version = &quot;5.5.3&quot;<br><br>  # VPC basic  details<br>  name = &quot;vpc-dev&quot;<br>  cidr = &quot;10.10.0.0/16&quot;<br>  azs = [&quot;ap-south-1a&quot;, &quot;ap-south-1b&quot;]<br>  public_subnets = [&quot;10.10.1.0/24&quot;, &quot;10.10.2.0/24&quot;]<br>  private_subnets = [&quot;10.10.3.0/24&quot;, &quot;10.10.4.0/24&quot;]<br><br>  # Database Subnets<br>  create_database_subnet_group = true<br>  create_elasticache_subnet_route_table = true<br>  database_subnets = [&quot;10.10.5.0/24&quot;, &quot;10.10.6.0/24&quot;]<br><br>  # NAt Gateway - Outbound communication<br>  enable_nat_gateway = true<br>  single_nat_gateway = true<br><br>  # DNS Parameters<br>  enable_dns_hostnames = true<br>  enable_dns_support = true<br><br>  # Subnets tags<br>  public_subnet_tags = {<br>    Type = &quot;public-subnets&quot;<br>  }<br>  private_subnet_tags = {<br>    Type = &quot;private-subnets&quot;<br>  }<br>  database_subnet_tags = {<br>    Type = &quot;database-subnets&quot;<br>  }<br>  tags = {<br>    Owner = &quot;Anurag&quot;<br>    Env = &quot;dev&quot;<br>  }<br>  vpc_tags = {<br>    Type = &quot;vpc-dev&quot;<br>  }<br>}</pre><p><em>1. Module Configuration:</em></p><ul><li>source: Specifies the location of the external module.</li><li>version: Defines the specific version of the module to use.</li></ul><p><em>2. VPC Basic Details:</em></p><ul><li>name: Sets the name for the VPC.</li><li>cidr: Defines the CIDR block for the VPC.</li><li>azs: Specifies the availability zones within the region where resources will be placed.</li><li>public_subnets: Lists the CIDR blocks for the public subnets within the VPC.</li><li>private_subnets: Lists the CIDR blocks for the private subnets within the VPC.</li></ul><p><em>3. Database Subnets:</em></p><ul><li>create_database_subnet_group: Enables the creation of a dedicated subnet group for database resources.</li><li>create_elasticache_subnet_route_table: Creates a separate route table for the database subnet group if using ElastiCache.</li><li>database_subnets: Lists the CIDR blocks for the database subnets.</li></ul><p><em>4. NAT Gateway — Outbound Communication:</em></p><ul><li>enable_nat_gateway: Enables the creation of a NAT Gateway for outbound internet access for resources in private subnets.</li><li>single_nat_gateway: Deploy a single NAT Gateway for this VPC.</li></ul><p><em>5. DNS Parameters:</em></p><ul><li>enable_dns_hostnames: Enables hostname resolution within the VPC.</li><li>enable_dns_support: Enables DNS resolution using Amazon Route 53.</li></ul><p><em>6. Tags:</em></p><ul><li>public_subnet_tags, private_subnet_tags, and database_subnet_tags: Assign a &quot;Type&quot; tag to each subnet type for easy identification.</li></ul><p><strong>Step 3: Initialize Terraform</strong></p><p>Open the command prompt or terminal &amp; navigate to the folder where the terraform file is located and run the below command.</p><pre>terraform init</pre><p>It essentially prepares Terraform’s working directory for managing infrastructure. It downloads and installs any required provider plugins based on your configuration like hashicorp/aws provider.</p><p><strong>Step 4: Terraform Validate</strong></p><pre>terraform validate</pre><p>It performs a static analysis of your Terraform configuration files and validates the overall syntax of your Terraform code, ensuring it adheres to the Terraform language rules.</p><p><strong>Step 5: Terraform Plan</strong></p><pre>terraform plan</pre><p>It is used for understanding and reviewing the intended changes to your infrastructure before actually applying them.</p><p><strong>Step 6: Terraform Apply to Create EC2 Instanc</strong>e</p><pre>terraform apply</pre><p>The Terraform apply command in Terraform is the one that actually executes the actions outlined in the plan generated by the Terraform plan. It’s the final step in making the desired infrastructure changes a reality.</p><p>If it runs successfully you can go ahead and open the AWS console to verify the open EC2 instance is created.</p><p><strong>Step 7: Destroy EC2 Instance</strong></p><pre>terraform destroy</pre><p>The terraform destroy command in Terraform serves the purpose of tearing down the infrastructure resources that your Terraform configuration currently manages.</p><h3>Conclusion</h3><p>In this walkthrough, we’ve demonstrated how to architect a robust and secure network infrastructure on AWS using Terraform. By following the provided steps, you’ve learned how to create a Virtual Private Cloud (VPC) with dedicated subnets for public, private, and database resources across multiple availability zones.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7359ff8cd2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Launch an HTTP Server on EC2 with Terraform]]></title>
            <link>https://aws.plainenglish.io/launch-an-http-server-on-ec2-with-terraform-09ad66f051cb?source=rss-d9babe26592c------2</link>
            <guid isPermaLink="false">https://medium.com/p/09ad66f051cb</guid>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ec2-instance]]></category>
            <dc:creator><![CDATA[Anurag Kumar]]></dc:creator>
            <pubDate>Wed, 13 Mar 2024 06:10:39 GMT</pubDate>
            <atom:updated>2024-03-14T09:10:31.752Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*jvbF_OGucGT3rLi5NLvDRg.png" /></figure><p>In this walkthrough, we are going to learn how to provision an AWS EC2 instance, create and set up a Security group to allow HTTP traffic, and install Apache Web Server to host a simple website all through Terraform.</p><p>You have to install the Terraform and AWS CLI on your local system. And you can find the Terraform code <a href="https://github.com/anuragabcr/terraform/tree/main/day-2"><strong><em>here</em></strong></a>.</p><h4><strong>Step 1: Create a Terraform file</strong></h4><p>Create a Terraform configuration file that defines the resources we want to provision on AWS, including an EC2 instance with the necessary security group configuration. The file name can be anything but the extension should be ‘<strong>.tf</strong>’ like ‘simpleWeb.tf’<strong>.</strong></p><pre># Terraform block<br>terraform {<br>  required_version = &quot;~&gt; 1.7.4&quot;<br>  required_providers {<br>    aws = {<br>      source = &quot;hashicorp/aws&quot;<br>      version = &quot;5.40.0&quot;<br>    }<br>  }<br>}<br><br># Provider block<br>provider &quot;aws&quot; {<br>  region = &quot;ap-south-1&quot;<br>  profile = &quot;default&quot;<br>}<br><br># Create Security Group - Web Traffic<br>resource &quot;aws_security_group&quot; &quot;vpc-web&quot; {<br>  name        = &quot;vpc-web&quot;<br>  description = &quot;VPC web&quot;<br>  ingress {<br>    description = &quot;Allow Port 80&quot;<br>    from_port   = 80<br>    to_port     = 80<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    description = &quot;Allow Port 443&quot;<br>    from_port   = 443<br>    to_port     = 443<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    description = &quot;Allow all ip and ports outbound&quot;<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}<br><br># Resource: EC2 Instance<br>resource &quot;aws_instance&quot; &quot;day2_ec2&quot; {<br>  ami = &quot;ami-0ba259e664698cbfc&quot;<br>  instance_type = &quot;t2.micro&quot;<br>  user_data = file(&quot;${path.module}/simpleWeb.sh&quot;)<br>  tags = {<br>    &quot;Name&quot; = &quot;EC2 Demo&quot;<br>  }<br>  vpc_security_group_ids = [ aws_security_group.vpc-web.id ]<br>}</pre><p><em>1. Terraform Block:</em></p><ul><li>required_version: Specifies the minimum Terraform version needed for this configuration.</li><li>required_providers: Defines the required providers, which are plugins for managing specific cloud platforms.</li></ul><p><em>2. Provider Block:</em></p><ul><li>provider &quot;aws&quot;: Configures the AWS provider with details:</li><li>region: Sets the AWS region where resources will be created.</li><li>profile: Specifies the AWS credentials profile to use.</li></ul><p><em>3. Security Group:</em></p><ul><li>resource &quot;aws_security_group&quot; &quot;vpc-web&quot;: Creates a security group named &quot;vpc-web&quot; with the following rules:</li></ul><p>Ingress Rules:</p><ul><li>Allows incoming TCP traffic on port 80 for HTTP.</li><li>Allows incoming TCP traffic on port 443 for HTTPS.</li></ul><p>Egress Rule:</p><ul><li>Allows all outbound traffic for the instance.</li></ul><p><em>4. EC2 Instance:</em></p><ul><li>resource &quot;aws_instance&quot; &quot;day2_ec2&quot;: Declares an EC2 instance with these attributes:</li><li>ami: Specifies the AMI (Amazon Machine Image) to use for launching the instance.</li><li>instance_type: Sets the instance type.</li><li>user_data: Specifies a startup script to run on instance launch.</li><li>tags: Assign a name tag &quot;EC2 Demo&quot; to the instance for identification.</li><li>vpc_security_group_ids: Associates the instance with the &quot;vpc-web&quot; security group for network traffic control.</li></ul><h4><strong>Step 2: Create a Bash file</strong></h4><p>Create a bash script file that defines what to do when the EC2 instance is created. The file name can be anything but the extension should be ‘<strong>.sh</strong>’ like ‘simpleWeb.sh’<strong>.</strong></p><p>You can find the bash script <a href="https://github.com/anuragabcr/terraform/blob/main/day-2/simpleWeb.sh"><strong><em>here</em></strong></a>.</p><p><em>1. System Updates:</em></p><ul><li>It starts by updating the package manager (yum) and the system itself to ensure the latest security patches and software versions.</li></ul><p><em>2. Web Server Installation:</em></p><ul><li>The script installs the httpd package, which is the Apache web server software.</li></ul><p><em>3. Web Server Configuration:</em></p><ul><li>It enables the httpd service to automatically start on instance boot, ensuring continuous web service availability.</li><li>The service is then started immediately to serve web content.</li></ul><p><em>4. Creating Web Content:</em></p><ul><li>The script creates two basic HTML files:</li><li>index.html in the default web directory (/var/www/html). This displays a simple “Welcome to Terraform — APP-1” message.</li><li>index.html within a subdirectory (/var/www/html/app1). This one includes more details like “Terraform Demo” and “Application Version: V1”.</li></ul><h4><strong>Step 3: Initialize Terraform</strong></h4><p>Open the command prompt or terminal &amp; navigate to the folder where the terraform file is located and run the below command.</p><pre>terraform init</pre><p>It essentially prepares Terraform’s working directory for managing infrastructure. It downloads and installs any required provider plugins based on your configuration like hashicorp/aws provider.</p><h4><strong>Step 4: Terraform Validate</strong></h4><pre>terraform validate</pre><p>It performs a static analysis of your Terraform configuration files and validates the overall syntax of your Terraform code, ensuring it adheres to the Terraform language rules.</p><h4><strong>Step 5: Terraform Plan</strong></h4><pre>terraform plan</pre><p>It is used for understanding and reviewing the intended changes to your infrastructure before actually applying them.</p><h4><strong>Step 6: Terraform Apply to Create EC2 Instanc</strong>e</h4><pre>terraform apply</pre><p>The Terraform apply command in Terraform is the one that actually executes the actions outlined in the plan generated by the Terraform plan. It’s the final step in making the desired infrastructure changes a reality.</p><p>If it runs successfully you can go ahead and open the AWS console to verify the open EC2 instance is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qSL4O15BP4HUvWzuoWZ-JQ.png" /></figure><blockquote>You can open the Public IP of the EC2 instance in a browser to see the output.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*MU-vATpsNjHUExxmXo2P5g.png" /></figure><h4><strong>Step 7: Destroy EC2 Instance</strong></h4><pre>terraform destroy</pre><p>The terraform destroy command in Terraform serves the purpose of tearing down the infrastructure resources that your Terraform configuration currently manages.</p><h4><strong>Conclusion</strong></h4><p>In this walkthrough, we’ve explored the process of launching an HTTP server on an EC2 instance using Terraform. By following the step-by-step instructions outlined above, you’ve learned how to provision an AWS EC2 instance, create and set up a Security Group to allow HTTP traffic and install the Apache Web Server to host a simple website — all through Terraform automation.</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a><strong> | </strong><a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://stackademic.com/"><strong>Stackademic</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a><strong> | </strong><a href="https://blog.cubed.run/"><strong>Cubed</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=09ad66f051cb" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/launch-an-http-server-on-ec2-with-terraform-09ad66f051cb">Launch an HTTP Server on EC2 with Terraform</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating AWS EC2 instance using Terraform]]></title>
            <link>https://medium.com/@anuragabcr/creating-aws-ec2-instance-using-terraform-25b0d0077b98?source=rss-d9babe26592c------2</link>
            <guid isPermaLink="false">https://medium.com/p/25b0d0077b98</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Anurag Kumar]]></dc:creator>
            <pubDate>Tue, 12 Mar 2024 06:47:06 GMT</pubDate>
            <atom:updated>2024-03-13T04:32:29.867Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*uf3LI8bhhjFO5yz9.png" /></figure><p>In this walkthrough, we are going to learn how we can create an AWS EC2 instance using the Terraform.</p><p>You have to install the Terraform and AWS CLI on your local system. And you can find the Terraform code <a href="https://github.com/anuragabcr/terraform/tree/main/day-1"><strong><em>here</em></strong></a>.</p><p><strong>Step 1: Create a terraform file</strong></p><pre># Terraform Settings Block<br>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      #version = &quot;~&gt; 3.21&quot; # Optional but recommended in production<br>    }<br>  }<br>}<br><br># Provider Block<br>provider &quot;aws&quot; {<br>  profile = &quot;default&quot; # AWS Credentials Profile configured on your local desktop terminal  $HOME/.aws/credentials<br>  region  = &quot;ap-south-1&quot;<br>}<br><br># Resource Block<br>resource &quot;aws_instance&quot; &quot;ec2demo&quot; {<br>  ami           = &quot;ami-0ba259e664698cbfc&quot; # Amazon Linux in ap-south-1, update as per your region<br>  instance_type = &quot;t2.micro&quot;<br>}</pre><p>Create a file with the extension tf like ‘<em>instance.tf</em>’ and put the above code.</p><p><strong>1. Terraform Settings Block (</strong>terraform { ... }<strong>)</strong></p><p>This block defines settings specific to Terraform itself.</p><ul><li>required_providers: This section specifies the external providers Terraform needs to interact with cloud services.</li></ul><p><strong>2. Provider Block (</strong>provider &quot;aws&quot; { ... }<strong>)</strong></p><p>This block configures how Terraform interacts with the AWS cloud platform.</p><ul><li>aws: This keyword defines the provider type as AWS.</li><li>profile = &quot;default&quot;: This tells Terraform to use the default profile for AWS credentials. which you must do when you install and configure the AWS CLI.</li></ul><p><strong>3. Resource Block (</strong>resource &quot;aws_instance&quot; &quot;ec2demo&quot; { ... }<strong>)</strong></p><p>This block defines an actual resource that Terraform will provision in your AWS account.</p><ul><li>resource &quot;aws_instance&quot; &quot;ec2demo&quot;: This line defines the resource type as an AWS instance and assigns it the name &quot;ec2demo&quot;.</li><li>ami = &quot;ami-0ba259e664698cbfc&quot;: This sets the Amazon Machine Image (AMI) ID for the instance.</li><li>instance_type = &quot;t2.micro&quot;: This defines the type of instance (size and capabilities) to be launched.</li></ul><p><strong>Step 2: Initialize Terraform</strong></p><p>Open the command prompt or terminal &amp; navigate to the folder where the terraform file is located and run the below command.</p><pre>terraform init</pre><p>It essentially prepares Terraform&#39;s working directory for managing infrastructure. It downloads and installs any required provider plugins based on your configuration like hashicorp/aws provider.</p><p><strong>Step 3: Terraform Validate</strong></p><pre>terraform validate</pre><p>It performs a static analysis of your Terraform configuration files and validates the overall syntax of your Terraform code, ensuring it adheres to the Terraform language rules.</p><p><strong>Step 4: Terraform Plan</strong></p><pre>terraform plan</pre><p>It is used for understanding and reviewing the intended changes to your infrastructure before actually applying them.</p><p><strong>Step 5: Terraform Apply to Create EC2 Instanc</strong>e</p><pre>terraform apply </pre><p>The Terraform apply command in Terraform is the one that actually executes the actions outlined in the plan generated by the Terraform plan. It’s the final step in making the desired infrastructure changes a reality.</p><p>If it runs successfully you can go ahead and open the AWS console to verify the open EC2 instance is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e3ZNMeGC7wiv8bcXpHIQkw.png" /></figure><p><strong>Step 6: Destroy EC2 Instance</strong></p><pre>terraform destroy</pre><p>The terraform destroy command in Terraform serves the purpose of tearing down the infrastructure resources that your Terraform configuration currently manages.</p><p><strong>Conclusion:</strong></p><p>In this walkthrough, we’ve covered the process of creating an AWS EC2 instance using Terraform. By following the outlined steps, you can efficiently manage your infrastructure as code, ensuring consistency and reproducibility across deployments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25b0d0077b98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hosting React app in Docker Container]]></title>
            <link>https://medium.com/@anuragabcr/hosting-react-app-in-docker-container-a753ba2ec21d?source=rss-d9babe26592c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a753ba2ec21d</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Anurag Kumar]]></dc:creator>
            <pubDate>Wed, 06 Mar 2024 05:58:57 GMT</pubDate>
            <atom:updated>2024-03-06T05:58:57.553Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/904/0*OVDRTxAsrV4oqMMq.png" /></figure><p>In this walkthrough, we are going to learn how to run the react application inside a docker container.</p><p>You can find the code of this walk-through <a href="https://github.com/anuragabcr/docker/tree/main/learning-ci-cd"><strong><em>here</em></strong></a>.</p><h4><strong>Running the Dev version inside the docker container</strong></h4><p><strong>Step 1:</strong> Create a Dockerfile.dev</p><p>First, we are going to create a dockerfile.dev to specify the configuration of our image.</p><pre>FROM node:16-alpine<br><br>WORKDIR &#39;/app&#39;<br>COPY package.json .<br>RUN npm install<br>COPY . .<br>CMD [ &quot;npm&quot;, &quot;run&quot;, &quot;start&quot; ]</pre><p>Line 1, The base image on which we are going to run our application.</p><p>Line 2, Creating a folder to store all our files.</p><p>Line 3, Copying the package.json file into the docker container.</p><p>Line 4, Installing all the required dependencies.</p><p>Line 5, Copying remaining front-end application into the container.</p><p>Line 6, Starting the application inside the container.</p><p><strong>Step 2:</strong> Build the docker image</p><pre>docker build -f Dockerfile.dev .</pre><p>Here we are building an image based on the ‘Dockerfile.dev’ configuration. ‘-f Dockerfile.dev’ is used to specify the docker file that we going to use to build this image and dot is used to specify the location of the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*kQzWEUijeGztzEWTG4v3BA.png" /></figure><p>If the docker image is built successfully you are going to get a docker image id. which we are going to use in the next step to run.</p><p><strong>Step 3</strong>: Run the docker container</p><pre>docker run -p 3000:3000 -v /app/node_modules -v $(pwd):/app &lt;image ID&gt;</pre><ul><li><strong>-p 3000:3000</strong>: it&#39;s port mapping to connect the outside internet into the isolated docker container.</li><li><strong>-v</strong>: it is used to specify the volume we want to copy into the running container. we are running a dev version of the react app and it’s going to keep on changing we want to see the changes without the need to rebuild the docker image and rerun the docker image.</li><li><strong>&lt;image id&gt;</strong>: you can copy and paste the image ID returned by the last step.</li></ul><p>The first ‘<strong>-v /app/node_moduels’ </strong>has only one file location because we don’t want to keep copying node_modules from the local drive to the docker container because its size is going to be large and we don’t to increase the rerun time. The downside to this approach is that any time we make any changes to the package.json or we install any new package we have to rebuild the docker image and rerun the image manually.</p><p>For the second ‘<strong>-v $(pwd):/app</strong>’, we are copying all the files in our current working directory into the docker container, and inside the container, it’s going to be inside a /app folder as specified by our Dockerfile.dev file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*8JHfVOvhi7nA_ZHhs-XSvA.png" /></figure><p>If it runs successfully, you can go ahead and the application running on the port you specified during the run time.</p><pre>localhost:3000</pre><p>And any changes you make are going to be reflected there. Sometimes you may have to refresh the page to see the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*eWENTlU_pWUOGSW7VAau6A.png" /></figure><blockquote>Our application is running in the docker and we can leave it there. But if we want to improve we don’t want to pass all that additional tags each time we build or run our docker image. We can create a docker-compose file and specify all the tags there.</blockquote><p><strong>Create a docker-compose.yml file</strong></p><pre>version: &#39;3&#39;<br><br>services:<br>  web: <br>    build: <br>      context: .<br>      dockerfile: Dockerfile.dev<br>    ports:<br>      - &#39;3000:3000&#39;<br>    volumes:<br>      - /app/node_modules<br>      - .:/app</pre><p>Line 1, Specify which version of YML we are using to write this file.</p><p>Line 2, To define all the services we are going to be running.</p><p>Line 3, Name of the docker container.</p><p>Line 4, The docker image we are going to use to build the docker container.</p><p>Line 5, The location where the Dockerfile is located.</p><p>Line 6, The Dockerfile that we are going to use to build the image.</p><pre>docker-compose up</pre><p>And we can simply use the above command to run the container. it’s going to take care of building the image and running the container with all the additional configuration requirements.</p><h4>Running the Prod version inside the docker container</h4><p>It’s quite simple as we don’t have to take care of any new changes.</p><p>We are going to use the built-in react command to build the static app from the current react app and we are going to use the ‘<strong>nginx’ </strong>server to serve the static content generated by the react build.</p><p><strong>Step 1</strong>: Create a Dockerfile</p><p>We are going to put our docker configuration inside a ‘<strong>Dockerfile’ </strong>without any extension and with the exact name as it’s the default docker file and we don’t have to specify the name when we build the docker image.</p><pre># First stage<br>FROM node:16-alpine as builder<br>WORKDIR &#39;/app&#39;<br>COPY package.json .<br>RUN npm install<br>COPY . .<br>RUN npm run build<br><br># second stage<br>FROM nginx<br>COPY --from=builder &#39;/app/build&#39; &#39;/usr/share/nginx/html&#39;</pre><p>We have to use two base images. First base image for node js to install all the node modules and build the static application from the react application.</p><p>The second base image provides us with the nginx server which is going to help us host and serve the static files. ‘<strong>nginx’ </strong>has a specific requirement where all the static files should be located for being hosted by the server. So basically, we are copying all the files created by the ‘npm run build’ command and pasting them inside the NGINX server to be hosted by it.</p><p><strong>Step 2</strong>: Build the docker image</p><pre>docker build .</pre><p>To build the docker image from the Dockerfile(no need to specify the name as it is the default name)</p><p><strong>Step 3</strong>: Run the docker container</p><pre>docker run -p 3000:3000 &lt;image id&gt;</pre><p>Run the docker image on a specific port.</p><h3>Conclusion</h3><p>In conclusion, deploying a React application within Docker containers provides a convenient and scalable solution for managing the application’s development and production environments. By containerizing the application, we ensure consistency across different environments and simplify the deployment process.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a753ba2ec21d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Website visits counter using Docker-Redis]]></title>
            <link>https://medium.com/@anuragabcr/website-visits-counter-using-docker-redis-f404a39f7a63?source=rss-d9babe26592c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f404a39f7a63</guid>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Anurag Kumar]]></dc:creator>
            <pubDate>Tue, 05 Mar 2024 05:43:45 GMT</pubDate>
            <atom:updated>2024-03-05T05:43:45.122Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*CSml5IkJ8bs67UiqQGVdHw.png" /></figure><p>In this walkthrough, we are going to see how we can implement a website visits counter using the in-memory datastore Redis. We are going to build and run our node application and Redis instance inside separate containers. The reason for running separately is to learn how we can establish a connection between two separate containers.</p><blockquote><strong>Note</strong>: All the instructions are going to be based on Express application in Node JS. Kindly change to the relevant code based on your programming language.</blockquote><p><strong>Step 1: Setting up the Front-End application</strong></p><p>If you don’t have a front-end application you can find a sample express application <a href="https://github.com/anuragabcr/docker/tree/main/visists"><strong><em>here</em></strong></a>.</p><p>Install the Redis library in your application.</p><pre>npm i redis</pre><p>Open the index page or the file where you want to display the visits counter and let’s set the Redis connection</p><pre>const redis = require(&quot;redis&quot;);<br><br>const client = redis.createClient({<br>  host: &quot;redis-server&quot;,<br>  port: 6379,<br>});<br><br>client.set(&quot;visists&quot;, 0);</pre><p>First, we are importing the Redis library into our application. then we create the connection. The hostname is the other Docker container name where we are going to run our Redis database (We will set it up in the later step) &amp; the port number is the default Redis database.</p><p>Then we are setting up the visits to Zero for the application if it runs for the very first time.</p><pre>client.get(&quot;visists&quot;, (err, visists) =&gt; {<br>    res.send(`Number of visists:- ${visists}`);<br>    client.set(&quot;visists&quot;, parseInt(visists) + 1);<br>  });</pre><p>We use the above code to fetch the no. of visits from the Redis database and display it after we increase the no. of visits by one.</p><p><strong>Step 2: Setting up the Dockerfile for Front-end</strong></p><p>We are going to create a Dockerfile to run the front-end application inside a container.</p><pre># Base library<br>FROM node:14-alpine<br><br>WORKDIR &#39;/app&#39;<br><br># install dependences<br>COPY package.json .<br>RUN npm install<br>COPY . .<br><br># default command<br>CMD [ &quot;npm&quot;, &quot;start&quot; ]</pre><p>Line 1, The base image on which we are going to run our application.</p><p>Line 2, Creating a folder to store all our files.</p><p>Line 3, Copying the package.json file into the docker container.</p><p>Line 4, Installing all the required dependencies.</p><p>Line 5, Copying remaining front-end application into the container.</p><p>Line 6, Starting the application inside the container.</p><p><strong>Step 3: Setting up the Docker-compose.yml</strong></p><p>Our application requires two docker containers to run together, one container for running the front-end application and a second one to run our Redis database. That’s why we are using the docker-compose to run both containers together and establish a network connection between each other.</p><pre>version: &#39;3&#39;<br><br>services:<br>  redis-server:<br>    image: &#39;redis&#39;<br>  node-app:<br>    build: .<br>    ports:<br>      - &quot;3000:3000&quot;</pre><p>Line 1, Specify which version of YML we are using to write this file.</p><p>Line 2, To define all the services we are going to be running.</p><p>Line 3, First Docker container to run our Redis database. If you notice the name is the same as the name we provided when we established the connection in the front-end application.</p><p>Line 4, We are using a publicly available docker image from the Docker hub to run the Redis instance.</p><p>Line 5, Second Docker container to run our front-end application.</p><p>Line 6, Build defines that we don’t have a docker image and we want docker-compose to build a docker image from a Dockerfile and the Dockerfile can be found in the current directory.</p><p>Line 7, Port mapping, to forward the outside connection port to inside the container port. As all the docker containers are isolated &amp; we can’t directly access applications running inside a container.</p><p><strong>Step 4: Running our application</strong></p><pre>docker-compose up</pre><p>Open your terminal &amp; move to the folder where your docker-compose.yml file is located and run the above command to start the application.</p><p>Now you should be able to run our see our application running on port 3000 and get the visits. Visits will increase as you refresh the page.</p><h3>Conclusion</h3><p>In conclusion, this walkthrough demonstrates how to implement a website visits counter using Redis and Docker containers. By separating the front-end application and the Redis database into individual containers, we learn how to establish a connection between them using Docker-compose.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f404a39f7a63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running an Express server in Docker]]></title>
            <link>https://medium.com/@anuragabcr/running-an-express-server-in-docker-8fa51fbd2b61?source=rss-d9babe26592c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fa51fbd2b61</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[express]]></category>
            <dc:creator><![CDATA[Anurag Kumar]]></dc:creator>
            <pubDate>Mon, 04 Mar 2024 11:10:22 GMT</pubDate>
            <atom:updated>2024-03-04T11:10:22.771Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i6HZIMBB0G896SPb" /></figure><p>In this walkthrough, we will see how to run an express server in the docker container.</p><p><strong>Step 1: Create an Express server</strong></p><p>If you have an express server that you want to run in the Docker container you can go ahead to step 2. Or you can download a simple express server from <a href="https://github.com/anuragabcr/docker/tree/main/simpleweb"><strong><em>here</em></strong></a><strong><em>.</em></strong></p><p>If you have downloaded the application then go ahead and extract the index.js and package.json files into a folder where you want to place the project.</p><p><strong>Step 2: Create a Dockerfile</strong></p><p>Create a Dockerfile in the same folder where you have all the express-related files. The file name must match “Dockerfile” including the capitalization of the first character.</p><p>Copy and paste the below code.</p><pre># Base Image<br>FROM node:14-alpine<br><br>WORKDIR /usr/app<br># install dependencies<br>COPY ./package.json ./<br>RUN npm install<br>COPY ./ ./<br><br># Default command<br>CMD [&quot;npm&quot;, &quot;start&quot;]</pre><p>Line 1, specifies which base image we want to use in our docker application. It’s like each docker has its own Linux-based OS which we use to build our application on the top of that base image. Here we are using ‘node:14-alpine’ because we are using express in our application and express runs on node and 14-alpine is the node image version which you can change and move to more latest version if needed.</p><p>Line 2, ‘WORKDIR’ specifies where we want to place our express files inside the docker container. Because it’s a Linux-based OS and it has ‘usr’ folder user-specific files, we are creating an app folder inside.</p><p>Line 3, ‘COPY’ command, we copy the ‘package.json’ inside the container which has all the express server-specific dependencies and other scripts for running the express server.</p><p>Line 4, ‘RUN’ command to install the dependencies listed inside the package.json files.</p><p>Line 5, ‘COPY’ command to copy all the remaining files related to the express server to be copied into the docker container.</p><p>Line 6, ‘CMD’ specifies which command to run when the docker container is started.</p><p><strong>Step 3: Build a Docker Image</strong></p><p>Open your terminal and move to the folder where the express server and all its files are located.</p><p>Our docker file is ready and we can now use the Dockerfile to build a docker image based on it.</p><pre>docker build -t anuragabcr/express .</pre><ul><li><strong>docker build</strong>: To specify that we are going to build an image.</li><li><strong>-t anuragabcr/express</strong>: To give the docker image a tag or a name. The naming convention is that the image name should be the user&#39;s Docker Hub username/project name: version.</li><li><strong>. </strong>: The dot is used to indicate where the Dockerfile is placed. it is placed in the same folder as our terminal that’s why we are using the dot only.</li></ul><p>This going to return us a docker image ID and Docker image tag name which we can use to run the docker image or create a container from that image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*38c_2RPu-cwNHuFA5eZb8Q.png" /><figcaption>Image build successfully</figcaption></figure><p><strong>Step 4: Run a Docker Image</strong></p><p>The docker image is ready and we can use the image ID or tag name to start the docker container.</p><pre>docker run -p 3000:3000 anuragabcr/express</pre><ul><li><strong>docker run</strong>: To specify that we are going to run a docker image</li><li><strong>-p 3000:3000</strong>: It is called port mapping. Docker containers are isolated and we can’t directly connect to them. We are specifying that our application is running on port 3000 <em>(changed based on your express server port)</em> inside the docker container and we want to make it public on port 3000 (the outside port can change and can be anything but the inside port no. for the container should be same as of the port specified on the express application).</li><li><strong>anuragabcr/express: </strong>The docker tag name that we specified in the last step. it can be a docker image ID also.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*lQOLsz_JyZDV20rNhdG_Xw.png" /><figcaption>Application is running inside container</figcaption></figure><p><strong>Step 5: Test on the browser</strong></p><p>Now we can open any browser and interact with our application on port 3000 (or on the port which you specified)</p><pre>localhost:3000</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*9ozbgmkhajon8_TiNmLbFg.png" /></figure><h3>Conclusion</h3><p>In this walkthrough, we have successfully learned how to run an Express server in a Docker container. We started by creating a simple Express server or downloaded one, followed by creating a Dockerfile that specified the base image, working directory, dependencies, and the command to run. We then built the Docker image using the Dockerfile and finally, ran the image to create a container. After port mapping, we were able to access the Express server running inside the container from our browser.</p><p>Happy Learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fa51fbd2b61" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generate Image Thumbnails on S3 Upload with AWS Lambda]]></title>
            <link>https://awstip.com/generate-image-thumbnails-on-s3-upload-with-aws-lambda-4cc8d4130dae?source=rss-d9babe26592c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cc8d4130dae</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[resize-images]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[s3-bucket]]></category>
            <category><![CDATA[s3]]></category>
            <dc:creator><![CDATA[Anurag Kumar]]></dc:creator>
            <pubDate>Tue, 02 Jan 2024 14:33:22 GMT</pubDate>
            <atom:updated>2024-01-03T16:54:34.993Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog dives deep into building a serverless Lambda function that magically generates thumbnails for every image uploaded to your S3 bucket. Wave goodbye to tedious resizing and optimize your website with instant thumbnails stored in a separate bucket.</p><p>We will use the AWS S3 bucket to store the images and the AWS Lambda function to convert the images into thumbnails. We will use the Node JS in our Lambda function.</p><p><strong>Step 1: Creating S3 buckets</strong></p><p>Open your AWS console and go to the S3 bucket page. Create two buckets, one for storing the original images and another for storing the thumbnails.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oRahCKpTwCZAImhfshKuPw.png" /></figure><p><strong>Step 2: Creating an IAM Role for the Lambda function</strong></p><p>Open the IAM page -&gt; Click on the “Policies” tab -&gt; Click on the “Create Policy” button -&gt; Click on the “JSON” Policy editor -&gt; Paste the JSON policy ( You can find the IAM Policy <a href="https://github.com/anuragabcr/aws-projects/blob/main/Thumbnails%20Maker/policy.json"><strong><em>here</em></strong></a>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vmwMevx9ZybQSGpSpj8nZg.png" /></figure><blockquote>Change the bucket names with your bucket names.</blockquote><p>Give the policy a name and click on the Create policy button.</p><p>Open the IAM page -&gt; Click on the “Roles” tab -&gt; Click on the “Create Role” button -&gt; Select “Aws Service” Trusted entity type -&gt; Choose “Lambda” as Use case -&gt; Search for the policy (The Policy you created previously) -&gt; Give the role a name -&gt; Create the Role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Ugz076YTQeZOYpGUuguPQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S7aaw1_6m_1Q4dVgbCBtdA.png" /></figure><p><strong>Step 3: Create the Lambda function</strong></p><p>Go to the AWS Lambda Function page -&gt; Click on the “Create Function” button -&gt; Select “Author from Scratch” -&gt; Give it a name -&gt; Select “Node JS 20” as Runtime -&gt; Exdends the Execution role section -&gt; Select “Use an existing Role” -&gt; Select the Role previously created -&gt; Create the Function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mq0_Z8_kLBkaKNlNxC27eg.png" /></figure><p>Now go to the code Section and upload the lambda function code (You can find the code <a href="https://github.com/anuragabcr/aws-projects/blob/main/Thumbnails%20Maker/Thumbnails%20Maker.zip"><strong><em>here</em></strong></a>).</p><p>Keep in mind that if you are writing your own Lambda function code to resize the image, you also have to upload the library you are using to resize the image. You have to zip the library file and index file (file size should be less than 10 Mb) and upload it to the AWS Lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8r3zbYoGSOHz_vVMitTWRQ.png" /></figure><p>If you are using my code then you have to provide an env variable. (DEST_BUCKET=&lt;destination_thumbnail_bucket_name&gt;)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PAZUtbQDt1Fp5x6OKWm1lQ.png" /></figure><p><strong>Step 3: Adding S3 event trigger</strong></p><p>Open your Lambda function -&gt; Click on “Add trigger” -&gt; Select “S3” as source -&gt; Select ‘source’ or ‘original’ image bucket -&gt; Check on the “Recursive invocation” -&gt; Click “Add” button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ulG7DTnKr0k8NZxh4mqF2A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*K5sgEuSliCAjegdbE26i8g.png" /></figure><p>Everything is done. If you followed correctly, You can go ahead and upload any images in your source S3 bucket and you can check that a new thumbnail is automatically generated and stored in the destination S3 bucket.</p><p>Congratulations! You’ve conquered the world of serverless image resizing with your very own Lambda function. Now, every upload to your S3 bucket seamlessly spawns a perfectly proportioned thumbnail, ready to boost your website’s performance and user experience.</p><p>Happy Coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cc8d4130dae" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/generate-image-thumbnails-on-s3-upload-with-aws-lambda-4cc8d4130dae">Generate Image Thumbnails on S3 Upload with AWS Lambda</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a React & GraphQL Full-Stack App on AWS: Choosing the Right Services]]></title>
            <link>https://awstip.com/deploying-a-react-graphql-full-stack-app-on-aws-choosing-the-right-services-cb68d0dba29a?source=rss-d9babe26592c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb68d0dba29a</guid>
            <category><![CDATA[hosting]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[full-stack]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Anurag Kumar]]></dc:creator>
            <pubDate>Sat, 30 Dec 2023 12:51:01 GMT</pubDate>
            <atom:updated>2024-01-01T11:15:18.771Z</atom:updated>
            <content:encoded><![CDATA[<p>In this walkthrough, we are going to learn how to Create and deploy a Full-Stack website on AWS using different AWS services. We are going to develop our Front-end using React JS and Back-end using GraphQL.</p><p>As for the AWS services, we are going to use AWS Amplify to deploy our front-end, AppSync to run our GraphQL back-end, DynamoDB to store our data, S3 bucket to store images, and Cognito to provide us with authentication. We are also going to use the AWS Amplify CLI to create and manage the AWS resources(So that we don’t have to create each service and do integration with our application manually, The Amplify CLI is going to help us with that).</p><blockquote>We are going to create a simple Photo sharing app called ‘Postagram’. if you want to follow along <a href="https://github.com/anuragabcr/aws-projects/tree/main/postagram"><strong><em>code is here</em></strong></a>.</blockquote><p><strong>Step 1: Configure Amplify CLI on our local machine</strong></p><p>Open your CMD and run the below command.</p><pre>npx create-react-app postagram<br>cd postagram<br>npm install -g @aws-amplify/cli</pre><p>The above command is going to first create a React JS project called “postagram”. Then we are going to move into that folder. After that, we are installing the AWS Amplify CLI library.</p><p>To configure, The Amplify CLI we need an IAM user’s Access Key and Secret Access Key.</p><p>Go to the AWS IAM page -&gt; Open the ‘Users’ section -&gt; Select the user under which you want to develop the project -&gt; Go to the ‘Security credentials’ tabs -&gt; Scroll down to the Access key section -&gt; Click on the ‘Create access key’ -&gt; Note down your Access Key &amp; Secret Access Key as it is not going to be shown again (you can always create another)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*rzRnSdehkficPxli1QQ65Q.png" /></figure><p>Go back to your CMD and run the below command</p><pre>amplify configure<br><br>- Specify the AWS Region: &lt;in which region you want to create the project&gt;<br>- accessKeyId: &lt;YOUR_ACCESS_KEY_ID&gt;<br>- secretAccessKey: &lt;YOUR_SECRET_ACCESS_KEY&gt;<br>- Profile Name: &lt;username or developer name&gt;</pre><p>The above configuration is going to allow the Amplify CLI to access and create resources on AWS through CLI.</p><pre>amplify init<br><br>- Enter a name for the project: &lt;your website name&gt;<br>- Initialize the project with the above configuration? (Y/n): y<br>- Select the authentication method you want to use: &lt;select your profile name&gt;</pre><p>In the above step, We are creating an empty Amplify project later on we are going to link and deploy the front-end (The purpose of this empty project is that it is going to have access to all the other AWS resources)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*zm5tvuSYhVwiAI42Qau0ng.png" /><figcaption>AWS architectural diagram After Step 1</figcaption></figure><p><strong>Step 2: Adding a GraphQL API</strong></p><p>Open your CMD and run the below command to add the API</p><pre>amplify add api<br><br>- Select from one of the below mentioned services: GraphQL<br>- Choose a schema template: Single object with fields<br>- Do you want to edit the schema now?: y</pre><p>We are selecting ‘GraphQL’ as a service if we select REST then we have to create Lambda functions for our API which we don’t want in this walkthrough. You can Select any template as we edit it immediately according to our application. lastly, we are opening the schema page to edit it.</p><p>You can write your own GraphQL schema based on your application. Or you can get it from <a href="https://github.com/anuragabcr/aws-projects/blob/main/postagram/amplify/backend/api/postagram/schema.graphql">here</a>.</p><p>After you are done with editing your schema file, run the build command to generate the JS files based on the GraphQL Schema.</p><pre>amplify build</pre><p>Now run the push command to create the underlying AWS resources based on GraphQL schema. It is going to use the AWS CloudFormation to create the service it needs to run the GraphQL on AWS like creating AWS AppSync for GraphQL API and DynamoDB table to store the data.</p><pre>amplify push -y (if you want to keep everything as default)<br>or<br>amplify push (to make changes in the deployment)</pre><p>Now you can Open your AppSync on AWS, where you are going to find one API that you just pushed. You can go to the Query section to run the GraphQL queries to test your API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4WXoMhLjHXYEVPC-7r2QwQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*QDEUls93QrdY_BnvBZPa0w.png" /><figcaption>AWS architectural diagram After Step 2</figcaption></figure><p><strong>Step 3: Query the GraphQL API from the Front-end React JS</strong></p><p>To query the API first install the aws-amplify library in your application.</p><pre>npm install aws-amplify</pre><p>Now open the src/index.js file and write the below configuration code</p><pre>import { Amplify } from &quot;aws-amplify&quot;;<br>import config from &quot;./aws-exports&quot;;<br>Amplify.configure(config);</pre><p>Open the page where you want to make the API queries. Here is the sample code to list all the ‘posts’. Make API queries based on your application.</p><pre>import { generateClient } from &#39;aws-amplify/api&#39;; <br>import { listPosts } from &quot;./graphql/queries&quot;; <br>// inside react function<br>function APP() {<br>  const client = generateClient();<br>  async function fetchPosts() {<br>    const postData = await client.graphql({ query: listPosts});<br>    // do your thing with the fetched data<br>  }<br>  // call the fetchPosts function inside useEffect()<br>}<br>// in the same way you can perform all the other CRUD operations</pre><p><strong>Step 4: Adding authentication using AWS Cognito</strong></p><p>Open the CMD and run the below commands</p><pre>amplify add auth<br><br>- Do you want to use the default authentication and security configuration?: &lt;Default configuration&gt;<br>- How do you want users to be able to sign in?: &lt;Select according to your app&gt;<br>- Do you want to configure advanced settings?: No, I am done.</pre><p>The above command is going to add and configure authentication in your application using AWS Cognito.</p><p>To create the resources on the AWS based on the above configuration run the push command.</p><pre>amplify push</pre><p>Now use authentication in the front-end, let’s install the library</p><pre>npm install @aws-amplify/ui-react</pre><p>To protect a page from unauthenticated access, wrap our default export with the withAuthenticator HOC</p><pre>function App({ signOut, user }) { // to access the user data &amp; sign out url<br>  /* existing code here, no changes */<br>}<br><br>/* src/App.js, change the default export to this: */<br>export default withAuthenticator(App);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*MI0A1dPBjfF3Y_GSnQxtyA.png" /><figcaption>AWS architectural diagram After Step 4</figcaption></figure><p><strong>Step 5: Image Storage with Amazon S3</strong></p><p>To add image storage, we’ll use Amazon S3, which can be configured and created via the Amplify CLI:</p><pre>amplify add storage<br><br>- Select from one of the below mentioned services: Content (Images, audio, video, etc.)<br>- Provide a friendly name for your resource that will be used to label this category in the project: &lt;anything&gt;<br>- Provide bucket name: &lt;use_the_default&gt;<br>- Who should have access: Auth and guest users<br>- What kind of access do you want for Authenticated users?: <br>✔ create/update<br>✔ read<br>✔ delete<br>- What kind of access do you want for Guest users?:<br>✔ read<br>Do you want to add a Lambda Trigger for your S3 Bucket?: N</pre><p>To deploy the service, run the following command:</p><pre>amplify push</pre><p>Now Open the newly created S3 bucket to attach and give permissions to public access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QhDDlyBpDTAIAq8uPbUQ1A.png" /></figure><p>Click on the edit bucket policy and write to policy to make the bucket publically accessible to only perform GET actions.</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Id&quot;: &quot;Policy1703912610376&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Sid&quot;: &quot;Stmt1703912607977&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: &quot;*&quot;,<br>            &quot;Action&quot;: &quot;s3:GetObject&quot;,<br>            &quot;Resource&quot;: &quot;&lt;your bucket ARN&gt;/*&quot;<br>        }<br>    ]<br>}</pre><p>To store an image on S3:</p><pre>import { uploadData } from &#39;aws-amplify/storage&#39;;<br><br>try {<br>        const result = await uploadData({<br>          key: image.name,<br>          data: image.fileInfo,<br>          options: {<br>            accessLevel: &#39;guest&#39;,<br>          }<br>        }).result;<br>        console.log(&#39;Succeeded: &#39;, result);<br> } catch (error) {<br>        console.log(&#39;Error : &#39;, error);<br>  }<br>// store the image name in your DB with other data, we are going to use it to access the image </pre><p>To access Images from S3:</p><pre>const imageURL = &quot;https://&quot;+&lt;your bucket name&gt;+&quot;.s3.&quot;+&lt;your bucket region&gt;+&quot;.amazonaws.com/public/&quot;+imageName.split(&quot; &quot;).join(&quot;+&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*66SlcfsRBuS5PPWpdyLLGw.png" /><figcaption>AWS architectural diagram After Step 5</figcaption></figure><p><strong>Step 6: Deploy Front-end React js on AWS Amplify</strong></p><p>Create a repository on GitHub and push your code on GitHub.</p><p>Open AWS Amplify -&gt; Select your application -&gt; Hosting environments -&gt; Select Github as Host app -&gt; Click on Connect Branch</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IeCrabQIPnSp2riVkqAtPQ.png" /></figure><p>Select the Right repository and create a role for it. And deploy it.</p><p>This will move your frontend from the local system to AWS amplify and give you a URL to access the website. Our backend is already deeply on AWS. So, we don’t have to do anything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*SGghX64T75r4-f6nP181nA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*lJXICGL4SvBSH1ndNkkO9Q.png" /><figcaption>Final AWS architectural diagram</figcaption></figure><p>Hope you find this walkthrough helpful.</p><p>Happy Coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb68d0dba29a" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/deploying-a-react-graphql-full-stack-app-on-aws-choosing-the-right-services-cb68d0dba29a">Deploying a React &amp; GraphQL Full-Stack App on AWS: Choosing the Right Services</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Serverless REST API using AWS Lambda]]></title>
            <link>https://awstip.com/creating-serverless-rest-api-using-aws-lambda-a9aaa462307b?source=rss-d9babe26592c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9aaa462307b</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[dynamodb]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[lambda]]></category>
            <dc:creator><![CDATA[Anurag Kumar]]></dc:creator>
            <pubDate>Mon, 25 Dec 2023 08:24:30 GMT</pubDate>
            <atom:updated>2023-12-27T18:55:59.574Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog will guide you through creating a Serverless REST API in AWS. We will use the Lambda function to implement the CRUD functionality and have our application business logic. We will use DynamoDB as our Database. We will use API Gate to create different routes and make our Lambda function accessible.</p><p><strong>Step 1: Create a DynamoDB table</strong></p><blockquote>We are using DynamoDB because it’s a NoSQL database, meaning there isn’t a predefined structure.</blockquote><p>Go to the AWS DynamoDB page -&gt; Click on the “Create Table” button -&gt; Give the table a name -&gt; Give Partition key name (which is an ID for each row, You can also think of it as a Primary key in SQL)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4iLJEguB9DwCe8khQ2YDNg.png" /></figure><p>Keep everything else as default and click on the “Create Table” button.</p><p>Step 2: Create a Lambda function</p><p>Go to the AWS Lambda page -&gt; Click on the “Create Function” button -&gt; Author from Scratch -&gt; Give the function a name -&gt; Choose the Runtime as Node.Js 16. (Node.js 16 if you are going to use my Lambda function code or Choose according to your application requirements)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HMpdsHYXv8YzlISmcVMJag.png" /></figure><p>Keep everything else as default and click on the “Create Function” button.</p><blockquote>Scroll Down to the Code Section and past your Lambda function code. (You can use <a href="https://github.com/anuragabcr/aws-projects/tree/main/REST%20API">my code as a sample</a>)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EyhGz0qrDoSTTkwmR2nCCA.png" /></figure><p><strong>Step 3: Assigning IAM role to Lambda function for Dynamodb access</strong></p><p>Open your Lambda function and scroll code to the code section -&gt; Click on the “Configuration” tab -&gt; Click on the Role name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*abzrbj3Usx42w5cRlDOgeg.png" /></figure><p>In the permissions tab -&gt; click on “Add permission” -&gt; Attach policies</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EbZInEDLN-VdObiAG4xUUA.png" /></figure><p>And attach the “AmazonDynamoDBFullAccess” permission. (This is going to allow Lambda to access DynamoDB) and Click “Add permissions”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7FRCRA6kp-LNi807QdoOTg.png" /></figure><p><strong>Step 4: Create API Gateway for Lambda function access</strong></p><p>Go to the AWS API Gateway page -&gt; Click on the “Create API” button -&gt; Click on the “Build” button in the REST API section -&gt; Select “New API” -&gt; Give the API a name -&gt; For API endpoint type either select ‘Regional’ or ‘Edge-optimized’ for public access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*baAPRUTzVM-r0YOUqA9INA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sIbo2SZxyO9RtLJyb-aC-g.png" /></figure><p>Click on the “Create method” button -&gt; Select the method type (Create all the methods that you have used in the Lambda function) -&gt; Select “Lambda function” as Integration Type-&gt; <strong>Enable the “Lambda proxy integration” button </strong>(This will allow the API Gateway to send request data to Lambda function like ‘request method’, request body, …)<strong> -&gt; </strong>Select the right Lambda function -&gt; Click on the “Create method” button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*vRjWukxmui9-VFN0Ha5y0Q.png" /></figure><p>Repeat the above step to create all the methods that you need and once you are done click on the “Deploy API” button. Select the stage as new and give the stage a name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*GgXy4ua8udSWBiUIlwj86w.png" /></figure><p>This will give you the API invoke URL to access all the routes. You can also find the API URL in the Stages tab in the left console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZQgni_N5_vXi-d7KM6pRHQ.png" /></figure><p><strong>Step 5: Finally test your API Endpoints.</strong></p><p>You can use Postman to test the endpoints or any tools you like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4lwFovAMFEb_9QNhaoukEQ.png" /></figure><p><em>In the End</em></p><p><em>I hope you find this guide helpful in learning and creating a Serverless REST API on AWS</em></p><p>Happy Coding</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9aaa462307b" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/creating-serverless-rest-api-using-aws-lambda-a9aaa462307b">Creating Serverless REST API using AWS Lambda</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>