<?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 Noor ul Hoda on Medium]]></title>
        <description><![CDATA[Stories by Noor ul Hoda on Medium]]></description>
        <link>https://medium.com/@noor563?source=rss-79d099624a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fhHCKAJxLOGYK4Fq</url>
            <title>Stories by Noor ul Hoda on Medium</title>
            <link>https://medium.com/@noor563?source=rss-79d099624a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 08:13:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@noor563/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[Install & Update the AWS CLI version 1 on MacOS M1 chip from scratch without brew :]]></title>
            <link>https://medium.com/@noor563/install-update-the-aws-cli-version-1-on-macos-m1-chip-from-scratch-without-brew-63415b3a6e16?source=rss-79d099624a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/63415b3a6e16</guid>
            <dc:creator><![CDATA[Noor ul Hoda]]></dc:creator>
            <pubDate>Wed, 12 Jun 2024 11:39:41 GMT</pubDate>
            <atom:updated>2024-06-12T11:39:41.798Z</atom:updated>
            <content:encoded><![CDATA[<h3>Install &amp; Update the AWS CLI version 1 on MacOS M1 chip from scratch without brew :</h3><p>You can install the AWS Command Line Interface (AWS CLI) version 1 and its dependencies on macOS by using the bundled installer or pip</p><h3>Prerequisites</h3><blockquote>Before you can install the AWS CLI version 1 on macOS, be sure you have Python 3.8 or later installed. If Python is not installed on your machine then download the latest package from the <a href="https://www.python.org/downloads/"><strong>link</strong></a>:</blockquote><p>To check if the installation is successful:</p><blockquote>which python3</blockquote><p><strong>Install, update and uninstall the AWS CLI version 1 using pip</strong></p><p>pip3 — version</p><p>If pip3 is installed, then download the awscli version 1 using the below command</p><pre>$ pip3 install awscli --upgrade --user</pre><p><strong>Setup</strong></p><p>Download the terraform binary : <a href="https://www.terraform.io/downloads.html">https://www.terraform.io/downloads.html</a></p><p>After downloading Terraform, unzip the package. Terraform runs as a single binary named terraform.</p><p>echo $PATH</p><p>mv ~/Downloads/terraform /usr/local/bin/</p><p>Terraform — version</p><p><strong>If any error for zsh :</strong></p><p>terraform -install-autocomplete</p><p><strong>AWS CLI setup: Terraform code base access</strong></p><ul><li><strong>Download the latest version of the AWS CLI:</strong> <a href="https://awscli.amazonaws.com/AWSCLIV2.pkg">https://awscli.amazonaws.com/AWSCLIV2.pkg</a></li><li><strong>Configure the “~/.aws/credentials” (Note: The .aws directory will only be created once you do the “aws configure” .)</strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63415b3a6e16" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DevOps:2 — Part-I: Creating a Secure AWS VPC using Terraform: Exploring Subnets, Internet Gateways…]]></title>
            <link>https://medium.com/@noor563/part-i-creating-a-secure-aws-vpc-using-terraform-exploring-subnets-internet-gateways-and-beyond-3561ee3758b1?source=rss-79d099624a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3561ee3758b1</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws-cloud]]></category>
            <category><![CDATA[vpc]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[subnet]]></category>
            <dc:creator><![CDATA[Noor ul Hoda]]></dc:creator>
            <pubDate>Fri, 12 May 2023 09:46:08 GMT</pubDate>
            <atom:updated>2023-05-13T08:09:28.685Z</atom:updated>
            <content:encoded><![CDATA[<h3>DevOps:2 — <strong>Part-I: Creating a Secure AWS VPC using Terraform: Exploring Subnets, Internet Gateways, and Beyond</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h-MkqEZ89jB22vkIReF5Bg.png" /></figure><p>Creating a secure and robust cloud infrastructure is a vital responsibility for any organization. Amazon Web Services (AWS) provides various services to help you accomplish this goal, and the most fundamental component of AWS networking is the Virtual Private Cloud (VPC). In this article, we will discuss VPC and its main elements. In our previous article, we learned about <a href="https://medium.com/@noor563/devops-1-efficiently-deploying-aws-infrastructure-with-terraform-a-step-by-step-guide-to-5ccc4caeeb28"><strong>DevOps: 1 — Efficiently Deploying AWS Infrastructure with Terraform: A Step-by-Step Guide to Building a Robust Development/Production Environment — Prerequisite</strong></a></p><p>In this two-part article, we will first explore some VPC concepts. In the second part, we will use Terraform to create our own VPC with public and private subnets as shown in the diagram above.</p><h3>What is AWS VPC?</h3><p>The Amazon Virtual Private Cloud (VPC) is an essential building block of the AWS cloud infrastructure that allows you to create a logically isolated section of the AWS Cloud. Here, you can launch various resources such as Amazon Elastic Compute Cloud (EC2) instances, Amazon Relational Database Service (RDS) instances, and other AWS resources in a virtual network that you define. The AWS VPC is necessary to provide a secure and isolated environment for your applications to run in the cloud. VPC enables you to define and control the network topology, IP address range, and network gateways, making it easy to configure and manage the network infrastructure. You can create multiple subnets with their security group, providing a layer of security to your resources. Also, you can use Network Access Control Lists (NACLs) to add an extra layer of security to your network.</p><p>VPC provides a private network in the cloud, which provides a more secure and isolated environment for your applications. You can connect your on-premises network to the cloud using VPN or Direct Connect. VPC also enables you to create subnets, which allows you to divide your network into smaller, more manageable parts.</p><p>VPC is made up of various components and concepts, and in this article, we will briefly examine some of them.</p><ol><li><strong>CIDR:</strong></li></ol><p>CIDR notation enables you to represent an IP address range using a single IP address and a slash followed by the number of bits in the network prefix. This allows you to specify IP addresses and their associated routing prefix. For instance, 10.0.0.0/16 represents the range of IP addresses from 10.0.0.0 to 10.0.255.255, and the CIDR block 10.0.0.0/8 represents the range from 10.0.0.0 to 10.0.0.255. The number following the slash indicates the number of IP addresses in the CIDR block, such as 2⁸, which means 256 IP addresses, and 2¹⁶ which means 65,536 addresses. The first four IP addresses and the last IP address in each CIDR block are reserved and cannot be used.</p><p><strong>2. Subnet:</strong></p><p>A subnet is a range of IP addresses that you can allocate to your resources in your VPC. Each subnet is associated with a particular Availability Zone (AZ) and can have up to 256 IP addresses by default. Subnets are used to segregate resources in a VPC and apply network security policies.</p><p><strong>3. Route Table:</strong></p><p>A route table contains a set of rules called routes that determine where network traffic is directed. Each subnet in a VPC must be associated with a route table, and the rules in the route table are used to determine how traffic is routed within the VPC. The default route table in a VPC allows all resources in the VPC to communicate with each other. A route table can be created for each subnet in the VPC.</p><p><strong>4. Internet Gateway (IGW):</strong></p><p>An Internet Gateway (IGW): is a vital component of a VPC that enables bidirectional communication between instances in the VPC and the Internet. It’s a horizontally scaled, redundant, and highly available service that serves as a target for all internet-bound traffic in the VPC</p><p><strong>5. Public and Private subnet :</strong></p><p>Within a VPC, you can create subnets that serve different purposes. Public subnets are connected to an IGW and have a route to the Internet, allowing instances in them to have public IP addresses and be accessible from the Internet. In contrast, private subnets don’t have a direct internet route, but can access the internet via a NAT Gateway.</p><p><strong>6. Nat Gateway:</strong></p><p>A NAT Gateway is a managed AWS service that lets instances in a private subnet connect to the internet without revealing their private IP addresses. It functions as a translator between the private and public IP address spaces and resides in a public subnet that has internet access.</p><p><strong>7. NACL:</strong></p><p>A Network Access Control List (NACL) is a security feature in a VPC that filters traffic to and from subnets based on user-defined rules. It’s a stateless firewall that allows or denies traffic based on criteria such as protocol, port, and IP addresses.</p><p><strong>8. Security Groups:</strong></p><p>Security Groups are virtual firewalls that regulate inbound and outbound traffic for instances in a VPC. They’re associated with a VPC and allow or deny traffic based on user-defined rules. You can configure Security Groups to specify which ports are open, which IP addresses are allowed to access your instances and other settings.</p><p>In summary, AWS VPC provides a secure and customizable network environment in the cloud that lets you launch various resources such as EC2 instances, RDS databases, and ELBs.</p><p>In the next article, we’ll demonstrate how to use Terraform to provision a VPC with both public and private subnets, create route tables for each subnet, and set up a NAT Gateway for private subnet access to the internet.</p><p>In conclusion, if you found this article helpful and informative, consider following me on <a href="https://medium.com/@noor563"><strong>Medium</strong></a> and <a href="https://github.com/noorul-hoda/terraform-workshop-aws/tree/main/infrastructure"><strong>GitHub</strong></a> for access to additional content on cloud computing, DevOps, and related topics. On Medium, you can discover a plethora of articles, and on GitHub, you can explore my open-source projects and code samples. By staying up-to-date with my latest work and best practices for managing infrastructure with Terraform and other cloud tools, you can continue to improve your skills and knowledge in this field. Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3561ee3758b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DevOps: 1 — Efficiently Deploying AWS Infrastructure with Terraform: A Step-by-Step Guide to…]]></title>
            <link>https://medium.com/@noor563/devops-1-efficiently-deploying-aws-infrastructure-with-terraform-a-step-by-step-guide-to-5ccc4caeeb28?source=rss-79d099624a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ccc4caeeb28</guid>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[dynamodb]]></category>
            <category><![CDATA[cloud-infrastructure]]></category>
            <dc:creator><![CDATA[Noor ul Hoda]]></dc:creator>
            <pubDate>Wed, 03 May 2023 08:39:13 GMT</pubDate>
            <atom:updated>2024-06-14T11:01:13.487Z</atom:updated>
            <content:encoded><![CDATA[<h3>DevOps: 1 — Efficiently Deploying AWS Infrastructure with Terraform: A Step-by-Step Guide to Building a Robust Development/Production Environment — Prerequisite</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/1*7XMvUxcrG_gLvE9D475L5Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/192/1*Y0fHjQbjs2qMHNNTrc18PA.png" /></figure><p>As a widely-used open-source tool for managing and provisioning cloud infrastructure, Terraform is an essential tool for many organizations. If you’re just getting started with Terraform, setting up a development environment is your first step. This tutorial will guide you through the process of creating the necessary infrastructure for managing Terraform state on an AWS backend. In addition, we’ll also cover how to set up other prerequisite infrastructure that will prove useful in the future when provisioning new infrastructure.</p><p>In addition to the necessary infrastructure for managing Terraform state on an AWS backend, we’ll also create a couple of other essential pieces of infrastructure. These include a “Hello World” ECR repository, which will serve as our initial image when provisioning an Image Lambda Function. Additionally, we’ll set up a Route53 Hosted Zone to use as our default DNS zone whenever we provision a new Route53 record.</p><p>You can find all the code related to this article on my <a href="https://github.com/noorul-hoda/terraform-workshop-aws/tree/main/infrastructure/01-terraform-prerequisite-configurations"><strong>GitHub Terraform Repository</strong></a><strong>.</strong></p><h3>Prerequisites:</h3><p>Before diving into the tutorial, there are a few prerequisites you should have in place. First and foremost, you’ll need an AWS account to work with. Additionally, you should have the AWS CLI installed and an AWS Access Key configured. Lastly, you should ensure that Terraform is installed on your system.</p><h3>Infrastructure for Terraform Backend State Management</h3><p>When working with Terraform, it’s essential to manage the state of the resources created by the tool, including dependencies, properties, and metadata. This state is used by Terraform to plan and implement infrastructure changes. To effectively manage Terraform state on AWS, several factors need to be considered. In this article, we’ll cover best practices for managing Terraform state on AWS, including creating an S3 bucket and DynamoDB table, configuring the backend, and handling state changes.</p><p>While both services can be used independently, utilizing them together provides added benefits, such as improved security and data consistency. By encrypting the S3 bucket and enabling versioning, you can safeguard the Terraform state information and track and manage changes over time. Additionally, using DynamoDB to store metadata ensures that Terraform always has access to the latest state information, even if a specific version of the S3 object is unavailable.</p><p>To create the required infrastructure, we’ll use Terraform <a href="https://registry.terraform.io/namespaces/terraform-aws-modules"><strong>AWS modules</strong></a> from <a href="https://github.com/antonbabenko"><strong>Anton Babenko</strong></a> in this tutorial.</p><ul><li><a href="https://registry.terraform.io/modules/terraform-aws-modules/s3-bucket/aws/latest">S3 Bucket Module</a></li><li><a href="https://registry.terraform.io/modules/terraform-aws-modules/dynamodb-table/aws/latest">DynamoDB Module</a></li><li><a href="https://registry.terraform.io/modules/terraform-aws-modules/ecr/aws/latest">ECR Module</a></li><li><a href="https://registry.terraform.io/modules/terraform-aws-modules/route53/aws/latest">Route53 Module</a></li><li><a href="https://registry.terraform.io/modules/cloudposse/label/null/latest">Null Label Module</a></li></ul><h3>1. Setting up Terraform variables for required infrastructure</h3><p>Initially, we will create the variables.tf file that will encompass all the variable definitions.</p><pre>variable &quot;project&quot; {<br>  type = string<br>}<br><br>variable &quot;environment&quot; {<br>  type = string<br>}<br><br>variable &quot;region&quot; {<br>  type = string<br>}<br><br>variable &quot;profile&quot; {<br>  type = string<br>}<br><br>variable &quot;domain_name&quot; {<br>  type = string<br>}</pre><p>Afterwards, we will create the terraform.tfvars file which will hold the values for the variables utilized in the Terraform configuration.</p><pre>##Variables<br>region      = &quot;eu-west-2&quot;<br>project     = &quot;CodeInsight&quot;<br>environment = &quot;dev&quot; <br>domain_name = &quot;CodeInsight.techlens.io&quot; #Format =&gt; &lt;project&gt;.&lt;company-name&gt;.&lt;domain-extensions&gt;<br>profile     = &quot;aws-access-key-profile-name&quot; # </pre><p>In this case, the “project” variable can be perceived as a product offered by your company, CodeInsight. To adapt the aforementioned values to your specific scenario, make the necessary modifications.</p><p>Then set the provider in main.tf file:</p><pre>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>  profile = &quot;aws-access-key-profile-name&quot;<br>}</pre><h3>2. Create an S3 Bucket</h3><p>Initially, an S3 bucket will be established for storing the Terraform state file. In the subsequent block of code, we will create a null label to assign a name to the S3 bucket. We will then employ the terraform-aws-s3 module to generate the S3 bucket, restricting all public access and forbidding access to the bucket without HTTPS. Additionally, we will enable versioning for the bucket.</p><pre>## Label for S3 bucket for backend<br>module &quot;s3-label&quot; {<br>  source = &quot;../../modules/terraform-null-label&quot;<br><br>  namespace   = var.project<br>  environment = var.environment<br>  name        = &quot;backend-tfstate&quot;<br><br>  label_order = [&quot;namespace&quot;, &quot;name&quot;, &quot;environment&quot;]<br><br>  additional_tag_map = {<br>    ManagedBy = &quot;Terraform&quot;<br>  }<br>}<br><br>## S3 bucket for backend<br>module &quot;s3_bucket&quot; {<br>  source = &quot;../../modules/terraform-aws-s3&quot;<br><br>  bucket                                = module.s3-label.id<br>  acl                                   = &quot;private&quot;<br>  attach_deny_insecure_transport_policy = true<br>  block_public_acls                     = true<br>  block_public_policy                   = true<br>  ignore_public_acls                    = true<br>  restrict_public_buckets               = true<br><br>  versioning = {<br>    enabled = true<br>  }<br><br>}</pre><h3>3. Create a DynamoDB Table</h3><p>Following this, a DynamoDB table will be generated for storing the locking details. The design of the DynamoDB table utilized for Terraform state is intended to store the state information in an organized manner that is easy to access and modify. Each entry in the table represents a resource managed by Terraform, and the attributes contain pertinent information about the resource, including its configuration and dependencies.</p><p>Utilizing DynamoDB as a backend provides several advantages, including built-in support for high availability and durability. DynamoDB automatically replicates data across numerous availability zones, guaranteeing that the state information remains accessible even in the event of a regional outage.</p><pre>## Label for dynamodb table for backend<br>module &quot;dynamodb-label&quot; {<br>  source = &quot;../../modules/terraform-null-label&quot;<br><br>  namespace   = var.project<br>  environment = var.environment<br>  name        = &quot;tfstate-lock&quot;<br><br>  label_order = [&quot;namespace&quot;, &quot;name&quot;, &quot;environment&quot;]<br><br>  additional_tag_map = {<br>    ManagedBy = &quot;Terraform&quot;<br>  }<br>}<br><br>## dynamodb table for backend<br>module &quot;dynamodb_table&quot; {<br>  source = &quot;../../modules/terraform-aws-dynamodb-table&quot;<br><br>  name     = module.dynamodb-label.id<br>  hash_key = &quot;LockID&quot;<br><br>  attributes = [<br>    {<br>      name = &quot;LockID&quot;<br>      type = &quot;S&quot;<br>    }<br>  ]<br>}</pre><p>The previous block of code involved creating a null label for the DynamoDB table, followed by generating the DynamoDB table itself.</p><p>This concludes the establishment of the infrastructure necessary for storing the Terraform state in the backend and locking it.</p><h3>Other pieces of Infrastructure (optional):</h3><h3>4. Setting Hello World ECR Repository:</h3><p>There are two additional optional infrastructure components that we will be addressing.</p><p>The first component involves setting up a Hello World ECR Repository. This will create an ECR repository that will function as our primary image for the Image Lambda Functions. To complete this step, ensure that Docker is installed on your machine.</p><p>Initially, the ECR Repository will be established.</p><pre>## Sample hello world ECR repository<br>module &quot;ecr&quot; {<br>  source = &quot;../../modules/terraform-aws-ecr&quot;<br><br>  name                    = &quot;sample-hello-world&quot;<br>  scan_images_on_push     = false<br>  enable_lifecycle_policy = true<br>  max_image_count         = &quot;1&quot;<br>  image_tag_mutability    = &quot;MUTABLE&quot;<br><br>  tags = {<br>    Project     = var.project<br>    Environment = var.environment<br>  }<br>}</pre><p>Then we will create a Dockerfile in the same directory as these terraform manifests with the following contents:</p><pre>FROM hello-world<br>CMD [&quot;echo&quot;, &quot;hello world&quot;]</pre><p>In conclusion, we will invoke the Terraform module responsible for constructing and uploading the Docker Image to our ECR Repository.</p><pre>## Data source to get current account id<br>data &quot;aws_caller_identity&quot; &quot;current&quot; {}<br><br>## Sample hello world image to ECR<br>module &quot;ecr_image&quot; {<br>  source             = &quot;../../modules/terraform-aws-ecr-image&quot;<br>  dockerfile_dir     = &quot;./&quot;<br>  ecr_repository_url = module.ecr.repository_url<br>  region             = var.region<br>  profile            = var.profile<br>  account_id         = data.aws_caller_identity.current.account_id<br>}</pre><h3>5. Route53 Zone</h3><p>The last infrastructure component that we will be generating is a hosted Route53 zone that will function as the default DNS zone when creating a new Route53 record. A hosted zone represents a collection of DNS records for a given domain. By generating a hosted zone in Route 53, we are essentially establishing a container that contains relevant data pertaining to the domain name and its associated DNS records.</p><pre>module &quot;zones&quot; {<br>  source = &quot;../../modules/terraform-aws-route53/zones&quot;<br><br>  zones = {<br>    &quot;main-domain&quot; = {<br>      domain_name = &quot;${var.domain_name}&quot;<br>    }<br>  }<br>}</pre><h3>6. Outputs File</h3><p>In the last phase, we will generate the outputs.tf file for the infrastructure that has been established. Within Terraform, the outputs.tf file serves to define the output values produced by your infrastructure. These output values may be utilized by other elements of your infrastructure or by external systems.</p><pre> output &quot;s3_bucket_id&quot; {<br>  value = module.s3_bucket.s3_bucket_id<br>}<br><br>output &quot;dynamodb_table_id&quot; {<br>  value = module.dynamodb_table.dynamodb_table_id<br>}<br><br>output &quot;repository_url&quot; {<br>  value = module.ecr.repository_url<br>}<br><br>output &quot;repository_arn&quot; {<br>  value = module.ecr.repository_arn<br>}<br><br>output &quot;ecr_image_url&quot; {<br>  value = module.ecr_image.ecr_image_url<br>}<br><br>output &quot;route53_zone_name_servers&quot; {<br>  value = module.zones.route53_zone_name_servers<br>}</pre><p>Having completed the infrastructure, it is now time to implement these Terraform manifests.</p><h3>Apply the Terraform code:</h3><p>We will now utilize the Terraform manifest file that we have constructed to allocate the infrastructure.</p><p>Initially, we will initialize the Terraform manifest directory. This will facilitate the download of the necessary provider plugins, as well as configure the backend for state storage.</p><pre>terraform init</pre><p>Next, we will verify the syntax and format of the Terraform configuration files. This process assesses your code for any errors or warnings.</p><pre>terraform validate</pre><p>In the third stage, we will execute the “plan” command, which will generate an execution plan. This plan demonstrates the actions that Terraform will perform when you apply your configuration. It displays the resources that will be constructed, altered, or deleted.</p><pre>terraform plan -var-file=./terraform.tfvars</pre><p>Then finally after checking and verifying the execution plan, we will apply the changes defined.</p><pre>terraform apply -var-file=./terraform.tfvars</pre><p>Having reached this final stage, we have successfully concluded this tutorial, and now we can utilize our recently established infrastructure as our Terraform state backend. In the upcoming article, we will explore how we can utilize this Terraform state backend to create and store our infrastructure state.</p><h3>Conclusion:</h3><p>To summarize, the process of setting up a development environment for Terraform on AWS requires careful planning and consideration of the infrastructure needed to manage the Terraform state, such as S3 bucket and DynamoDB table. Additional components like Route53 hosted zone and ECR repository can enhance the infrastructure provisioning workflow. Adhering to the best practices outlined in this article can improve your efficiency and maintainability when working with Terraform on AWS.</p><p>It is important to regularly review and update your infrastructure code to ensure it stays in sync with your evolving infrastructure needs. With Terraform and AWS’s powerful features, you can create a flexible and scalable infrastructure that can be easily managed and updated over time.</p><h3>Final Note:</h3><p>If you found this article helpful and enjoyed reading it, don’t forget to follow me on Medium and GitHub. On Medium, you can explore more of my articles related to cloud computing, DevOps, and similar topics.</p><p>On GitHub, you can access my open-source projects and code samples. By staying connected with me on these platforms, you can keep yourself updated on my latest work and learn more about the best practices for managing infrastructure using Terraform and other cloud technologies. Thank you for taking the time to read this!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ccc4caeeb28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS CodePipeline to deploy backend Lambda — Scripts]]></title>
            <link>https://medium.com/@noor563/aws-codepipeline-to-deploy-backend-lambda-scripts-235462985ab2?source=rss-79d099624a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/235462985ab2</guid>
            <category><![CDATA[cicd-pipeline]]></category>
            <category><![CDATA[cicd-lambda]]></category>
            <category><![CDATA[aws-codebuild]]></category>
            <category><![CDATA[aws-codepipeline]]></category>
            <dc:creator><![CDATA[Noor ul Hoda]]></dc:creator>
            <pubDate>Tue, 21 Mar 2023 11:12:24 GMT</pubDate>
            <atom:updated>2023-03-21T11:12:24.946Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS CodePipeline to deploy backend Lambda — Scripts</h3><p>This story will mainly cover which all scripts file will be required to deploy the backend AWS lambda:</p><p>Please follow below directory structure and the script file names:</p><p><strong>lambda</strong> → Directory for all the AWS lambda functions code</p><p><strong>scripts</strong> → Contains the build_script.sh which will build the docker image for lambda and deploy the latest image to the lambda function and push the image to ECR repository.</p><p><strong>buildspec.yml</strong> → This contains the build steps for the AWS codeBuild.</p><p><strong>buildconfig.yml</strong> → This yml file will contain the below things:</p><pre>## ECR Repository name<br>##Path to the lambda function code<br>##Name of the lambda functions associated with code and ECR</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*dbUkokZnGaE-hFkyWZudzg.png" /></figure><p>Example:</p><p>buildspec.yml</p><pre>version: 0.2<br>phases:<br>  pre_build:<br>    commands:<br>      - echo &quot;Installing YAML parser yq....&quot;<br>      - pip3 install yq<br>      - echo &quot;Deployment of backend lambda....&quot;<br>      - echo &quot;Logging in to Amazon ECR....&quot;<br>      - aws --version<br>      - aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com<br>      - chmod +x scripts/build_script.sh<br>      - cp -p scripts/build_script.sh /usr/local/bin/deploy.sh<br><br>  build:<br>    commands:<br>      - /usr/local/bin/deploy.sh</pre><p>buildconfig.yml</p><pre><br>lambda:<br>  ## ECR Repository name<br>  ecr-repo-1:<br>    ##Path to the lambda function code<br>    - lambda/lambda-code-1<br>    ##Name of the lambda functions associated with code and ECR<br>    - functions:<br>        - name-of-lambda-function-1<br>        - name-of-lambda-function-2<br>  ecr-repo-2:<br>    - lambda/lambda-code-2<br>    - functions:<br>        - name-0f-lambda-function-3</pre><p>scripts/build_script.sh</p><pre>#!/bin/bash<br><br>##Exit Status Function<br>function exit_status () {<br>    if [ $? -eq 0 ]<br>        then<br>            echo -e &quot; [INFO] Success: $1&quot;<br>        else<br>            echo -e &quot;\n [ERROR] Errors detected: $1&quot;<br>        exit 1<br>    fi<br>}<br><br>function check_yq_jq() {<br>    # Make sure yq is installed<br>    if ! command -v yq &amp;&gt; /dev/null; then<br>        echo &quot;yq not found. Please install it before running this script.&quot;<br>        exit 1<br>    fi<br>    # Make sure jq is installed<br>    if ! command -v jq &amp;&gt; /dev/null; then<br>        echo &quot;jq not found. Please install it before running this script.&quot;<br>        exit 1<br>    fi<br>}<br><br>function log_info() {<br>    echo -e &quot;===========================================================&quot;<br>    echo -e &quot; [INFO] $1&quot;<br>    echo -e &quot;===========================================================&quot;<br>}<br><br>function log_major_info() {<br>    echo -e &quot;\n\n========================================================================================&quot;<br>    echo -e &quot;\t\t[INFO] $1&quot;<br>    echo -e &quot;========================================================================================\n&quot;<br>}<br><br>function log_simple_info() {<br>    echo &quot; [INFO] $1&quot;<br>}<br><br># Docker Image Build and Upload Function<br>function build_and_upload_image() {<br>    log_major_info &quot;Building Docker Image for: $ECR_REPO&quot;<br>    # Build Docker Image<br>    log_info &quot;Building Docker Image&quot;<br>    docker build -t &quot;$ECR_REPO&quot;:&quot;$BUILD_VERSION&quot; .<br>    exit_status &quot;Docker Build For $ECR_REPO&quot;;<br>    # After the build completes, tag image so we can push the image to the ECR repo<br>    IMAGE_URI=$REPOSITORY_URI/$ECR_REPO:$BUILD_VERSION<br>    LATEST_IMAGE_URI=$REPOSITORY_URI/$ECR_REPO:latest<br>    docker tag &quot;$ECR_REPO&quot;:&quot;$BUILD_VERSION&quot; &quot;$IMAGE_URI&quot;<br>    docker tag &quot;$ECR_REPO&quot;:&quot;$BUILD_VERSION&quot; &quot;$LATEST_IMAGE_URI&quot;<br>    # Push this image to the ECR<br>    log_simple_info &quot;Pushing the Docker Image to ECR&quot;<br>    docker push &quot;$REPOSITORY_URI/$ECR_REPO&quot; --all-tags<br>    exit_status &quot;Pushed the Docker Image to ECR for: $IMAGE_URI&quot;;<br>}<br><br># Function to update the lambda function code with the latest ecr image <br>function deploy_lambda_code() {<br>    log_simple_info &quot;Publishing the code to Lambda: $FUNCTION_NAME&quot;<br>    CURRENT_VERSION=$(aws lambda get-alias \<br>                        --function-name &quot;$FUNCTION_NAME&quot; \<br>                        --name &quot;$ENVIRONMENT&quot; | jq -r .FunctionVersion<br>    );<br>    log_simple_info &quot;Current Version: $CURRENT_VERSION&quot;<br>    aws lambda update-function-code \<br>                --function-name &quot;$FUNCTION_NAME&quot; \<br>                --image-uri &quot;$IMAGE_URI&quot; \<br>                --publish --region=&quot;$REGION&quot; &gt; &quot;$BUILD_DIR&quot;/output.json;<br>    exit_status &quot;Published Code For: $FUNCTION_NAME&quot;;<br>    LATEST_VERSION=$(jq -r &#39;.Version&#39; &quot;$BUILD_DIR&quot;/output.json);<br>    log_simple_info &quot;New Lambda Version for $FUNCTION_NAME = $LATEST_VERSION&quot;;<br>    aws lambda update-alias \<br>                --function-name &quot;$FUNCTION_NAME&quot; \<br>                --function-version &quot;$LATEST_VERSION&quot; \<br>                --name &quot;$ENVIRONMENT&quot; &gt; /tmp/output.json;<br>    exit_status &quot;Alias Updated For: $FUNCTION_NAME&quot;;<br>    echo -e &quot;$FUNCTION_NAME:$LATEST_VERSION&quot; &gt;&gt; &quot;$ROOT_DIR&quot;/All_Lambda_Versions ;<br>}<br><br># Function that Build and Deploy Lambda Functions<br>function build_deploy_lambda_functions(){<br>    log_major_info &quot;Building and Deploying Lambda Functions&quot;<br>    # Read the YAML file<br>    data=$(yq . &quot;$BUILD_CONFIG_FILE&quot;)<br><br>    lambda_data=$(echo &quot;$data&quot; | jq &#39;.lambda&#39;)<br>    # Loop over the keys and values<br>    for key in $(echo &quot;$lambda_data&quot; | jq -r &#39;keys[]&#39;); do<br>        # extracting value (array) from the key.<br>        key_data=$(echo &quot;$lambda_data&quot; | jq &#39;.[&quot;&#39;&quot;$key&quot;&#39;&quot;]&#39;)<br>        # extracting values from the array.<br>        # dir_name=$(echo &quot;$key_data&quot; | jq &#39;.[0]&#39; | sed &#39;s/&quot;//g; s/&#39;\&#39;&#39;//g&#39;)<br>        dir_name=$(echo &quot;$key_data&quot; | jq &#39;.[0]&#39; | tr -d &#39;&quot;&#39;\&#39;)<br>        <br>        ECR_REPO=&quot;$PROJECT-$key-$ENVIRONMENT&quot;<br>        BUILD_DIR=&quot;$ROOT_DIR/$dir_name&quot;<br>        # Check if the directory has changes in the current commit only then build and deploy the lambda function<br>        if [[ $CHANGED_DIRECTORIES == *&quot;$dir_name&quot;* ]]; then<br>            echo -e &quot;Directory: &#39;$dir_name&#39; has changes!&quot;<br>            # Change Directory<br>            cd &quot;$BUILD_DIR&quot; || exit_status &quot;Changing Directory to $BUILD_DIR&quot;<br>            # Build and Upload Docker Image<br>            build_and_upload_image<br>            # Deploy Lambda Functions<br>            log_info &quot;Deploying Lambda Functions for: $ECR_REPO&quot;<br>            for function_key in $(echo &quot;$key_data&quot; | jq &#39;.[1].functions[]&#39;); do<br>                FUNCTION_NAME=$(echo &quot;$PROJECT-$function_key-$ENVIRONMENT&quot; | tr -d &#39;&quot;&#39;\&#39;)<br>                deploy_lambda_code<br>                echo &quot;&quot;<br>            done<br>            log_info &quot;Build &amp; Deploy Completed for: $ECR_REPO&quot;<br>            echo -e &quot;\n\n&quot;<br>        else<br>            echo -e &quot;Directory: &#39;$dir_name&#39; does not have changes!&quot;<br>        fi<br>    done<br>} <br><br># Function to get the list of directories that have changes in the current commit<br>function get_changed_directories() {<br>    # Get the list of files that have changed in the current commit<br>    CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r &quot;$CODEBUILD_RESOLVED_SOURCE_VERSION&quot;)<br>    # Get the list of directories that have changed in the current commit<br>    # CHANGED_DIRECTORIES=$(echo &quot;$CHANGED_FILES&quot; | sed &#39;s/[^/]*$//&#39; | sort -u)<br>    CHANGED_DIRECTORIES=$(echo &quot;$CHANGED_FILES&quot; | xargs -n1 dirname | sort | uniq)<br>    # Print the list of directories that have changed in the current commit<br>    log_major_info &quot;Changed Directories:&quot;<br>    echo &quot;$CHANGED_DIRECTORIES&quot;<br>}<br><br><br># Main Function<br>function main() {<br>    # Check if yq and jq are installed<br>    check_yq_jq<br><br>    # Set Environment Variables<br>    BUILD_CONFIG_FILE=&quot;buildconfig.yml&quot;<br>    COMMIT_HASH=$(echo &quot;$CODEBUILD_RESOLVED_SOURCE_VERSION&quot; | cut -c 1-7)<br>    BUILD_VERSION=${COMMIT_HASH:=latest}<br>    ##Variables<br>    ROOT_DIR=$(pwd)<br>    ##Commit ID<br>    log_info &quot;Build Commit ID: $CODEBUILD_RESOLVED_SOURCE_VERSION&quot;<br>    echo &quot;Project Name: $PROJECT&quot;<br>    echo &quot;AWS Environment: $ENVIRONMENT&quot;<br>    echo &quot;Build Version: $BUILD_VERSION&quot;<br>    echo &quot;Root Directory: $ROOT_DIR&quot;<br>    echo &quot;Build Config File: $BUILD_CONFIG_FILE&quot;<br>    echo &quot;Root Directory Contents: $(ls -l)&quot;<br><br>    # Get the list of directories that have changes in the current commit<br>    get_changed_directories<br>    # Build and Deploy Lambda Functions<br>    build_deploy_lambda_functions<br><br>    log_info &quot;Build Completed Successfully&quot;<br>}<br><br># Call Main Function<br>main</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=235462985ab2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[API Gateway Resource policy to restrict the API Endpoints based on whitelisted IP addresses]]></title>
            <link>https://medium.com/@noor563/api-gateway-resource-policy-to-restrict-the-api-endpoints-based-on-whitelisted-ip-addresses-ec6629f4b33d?source=rss-79d099624a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec6629f4b33d</guid>
            <category><![CDATA[aws-ip-whitelisting]]></category>
            <category><![CDATA[aws-api-gateway]]></category>
            <category><![CDATA[api-gateway-endpoint]]></category>
            <category><![CDATA[api-resource-policy]]></category>
            <category><![CDATA[api-gateway]]></category>
            <dc:creator><![CDATA[Noor ul Hoda]]></dc:creator>
            <pubDate>Tue, 21 Feb 2023 13:31:48 GMT</pubDate>
            <atom:updated>2023-02-22T11:49:12.394Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Requirement:</strong> By default, the API gateway allows all the IP addresses to invoke the API endpoints once it&#39;s deployed. If we want to restrict access to a set of whitelisted IP addresses, then an API resource policy is a good option. One can use the below policy for the same.</p><pre>## AWS IAM : API gateway resource policy<br><br>resource &quot;aws_api_gateway_rest_api_policy&quot; &quot;test&quot; {<br>  rest_api_id = aws_api_gateway_rest_api.api.id<br>  policy = &lt;&lt;EOF<br>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Principal&quot;: {<br>        &quot;AWS&quot;: &quot;*&quot;<br>      },<br>      &quot;Action&quot;: &quot;execute-api:Invoke&quot;,<br>      &quot;Resource&quot;: &quot;${aws_api_gateway_rest_api.api.execution_arn}/*/*/*&quot;<br>    },<br>    {<br>        &quot;Effect&quot;: &quot;Deny&quot;,<br>        &quot;Principal&quot;: {<br>             &quot;AWS&quot;: &quot;*&quot;<br>        },<br>        &quot;Action&quot;: &quot;execute-api:Invoke&quot;,<br>        &quot;Resource&quot;: &quot;${aws_api_gateway_rest_api.api.execution_arn}/*/*/*&quot;,<br>        &quot;Condition&quot;: {<br>            &quot;NotIpAddress&quot;: {<br>                &quot;aws:SourceIp&quot;: [<br>                    &quot;1.2.3.4/32&quot;,<br>                    &quot;5.6.7.8/24&quot;<br>                ]<br>            }<br>        }<br>    }   <br>  ]<br>}<br>EOF<br>}</pre><p><strong>For the custom message on the error page, the Following changes required</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8mDHnDL88UZbIDF0gusz2g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec6629f4b33d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Cloud: React Frontend web hosting on AWS EC2 server with CICD deployment using Terraform IAC…]]></title>
            <link>https://medium.com/@noor563/aws-cloud-react-frontend-web-hosting-on-aws-ec2-server-with-cicd-deployment-using-terraform-iac-fb2183cbc5cb?source=rss-79d099624a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb2183cbc5cb</guid>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[load-balancer]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[aws-codepipeline]]></category>
            <dc:creator><![CDATA[Noor ul Hoda]]></dc:creator>
            <pubDate>Mon, 20 Feb 2023 12:52:26 GMT</pubDate>
            <atom:updated>2023-02-20T12:52:26.880Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS Cloud: React Frontend web hosting on AWS EC2 server with CICD deployment using Terraform IAC: Part-1</h3><p><strong>Requirement:</strong> Hosting a react web application on an EC2 server with a CICD pipeline to deploy the changes from bitbucket to the EC2 server.</p><p><strong>Architectural Diagram:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qE_aFzHyEtPdYXOfQLgguA.png" /></figure><p><strong>Part 1:</strong> In part 1, we will be provisioning the below resources for the AWS EC2 web hosting:</p><pre>##################################################<br>####Resources created as part of this medium post<br>#AWS ACM<br>#AWS EC2 SSH key<br>#AWS S3 Artifact Bucket<br>#AWS EC2 instance role<br>#AWS EC2 server<br>#AWS EC2 security group<br>#ALB Security Group<br>#AWS ALB<br>#AWS Rroute53 record<br>##################################################</pre><pre><br>#AWS ACM<br>module &quot;acm_test_alb&quot; {<br>  source = &quot;terraform-aws-modules/acm/aws&quot;<br><br>  domain_name = var.test-domain-name<br>  zone_id     = data.aws_route53_zone.domain.zone_id<br>  subject_alternative_names = [<br>    &quot;*.${var.test-domain-name}&quot;,<br>  ]<br>  wait_for_validation = true<br>  tags = {<br>    Name = var.test-domain-name<br>  }<br>}</pre><pre>#AWS EC2 SSH key<br>module &quot;test-server_ssh_key_pair&quot; {<br>  source = &quot;terraform-aws-modules/key-pair/aws&quot;<br><br>  tenant                = var.project<br>  environment           = var.environment<br>  name                  = &quot;test-ec2&quot;<br>  label_order           = [&quot;tenant&quot;, &quot;name&quot;, &quot;environment&quot;]<br>  ssh_public_key_path   = &quot;./secrets&quot;<br>  generate_ssh_key      = &quot;true&quot;<br>  private_key_extension = &quot;.pem&quot;<br>  public_key_extension  = &quot;.pub&quot;<br>}</pre><pre>#AWS S3 Artifact Bucket<br>module &quot;s3label-test-pipeline-artifacts&quot; {<br>  source         = &quot;cloudposse/label/null&quot;<br>  tenant         = var.project<br>  environment    = var.environment<br>  name           = &quot;test-pipeline-artifacts&quot;<br>  delimiter      = &quot;-&quot;<br>  label_order    = [&quot;tenant&quot;, &quot;name&quot;, &quot;environment&quot;]<br>  labels_as_tags = [&quot;name&quot;, &quot;environment&quot;]<br><br>  additional_tag_map = {<br>    &quot;Project&quot;   = var.project<br>    &quot;Owner&quot;     = var.owner<br>    &quot;ManagedBy&quot; = &quot;Terraform&quot;<br>  }<br>}<br><br>module &quot;s3-test-pipeline-artifacts&quot; {<br>  source = &quot;terraform-aws-modules/s3-bucket/aws&quot;<br><br>  bucket                                = module.s3label-test-pipeline-artifacts.id<br>  acl                                   = &quot;private&quot;<br>  block_public_acls                     = true<br>  block_public_policy                   = true<br>  ignore_public_acls                    = true<br>  restrict_public_buckets               = true<br>  attach_deny_insecure_transport_policy = true<br><br>  server_side_encryption_configuration = {<br>    rule = {<br>      apply_server_side_encryption_by_default = {<br>        kms_master_key_id = data.aws_kms_alias.s3.arn<br>        sse_algorithm     = &quot;aws:kms&quot;<br>      }<br>    }<br>  }<br><br>  versioning = {<br>    enabled = true<br>    #mfa_enabled = false<br>  }<br><br>  tags = module.s3label-test-pipeline-artifacts.tags<br>}</pre><pre>#AWS EC2 instance role and policy<br>module &quot;access_test_s3_policy&quot; {<br>  source = &quot;terraform-aws-modules/iam-policy/aws&quot;<br><br>  name        = &quot;access_test_s3-policy&quot;<br>  description = &quot;test s3 artifact Policy&quot;<br>  path        = &quot;/&quot;<br><br>  policy = &lt;&lt;EOF<br>{ <br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Action&quot;: &quot;s3:*&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Resource&quot;: [<br>            &quot;${module.s3-test-pipeline-artifacts.s3_bucket_arn}&quot;,<br>            &quot;${module.s3-test-pipeline-artifacts.s3_bucket_arn}/*&quot;<br>            ]        <br>        }         <br>    ]<br>}<br>EOF<br>}<br><br>resource &quot;aws_iam_role&quot; &quot;access_test_s3_Role&quot; {<br>  name                 = &quot;Access_test_s3_Role&quot;<br>  max_session_duration = &quot;14400&quot;<br><br>  assume_role_policy = &lt;&lt;EOF<br>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Action&quot;: &quot;sts:AssumeRole&quot;,<br>      &quot;Principal&quot;: {<br>        &quot;Service&quot;: &quot;ec2.amazonaws.com&quot;<br>      },<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Sid&quot;: &quot;&quot;<br>    }<br>  ]<br>}<br>EOF<br>}<br><br>resource &quot;aws_iam_policy_attachment&quot; &quot;test_s3_RolePolicy&quot; {<br>  name       = &quot;RolePolicy_attachment&quot;<br>  roles      = [aws_iam_role.access_test_s3_Role.name]<br>  policy_arn = module.access_test_s3_policy.arn<br>}<br><br>resource &quot;aws_iam_instance_profile&quot; &quot;ec2_test_instance&quot; {<br>  name = &quot;test-s3-access&quot;<br>  role = aws_iam_role.access_test_s3_Role.name<br>}</pre><pre>#AWS EC2 server<br>module &quot;ec2-test-appserver&quot; {<br>  source = &quot;terraform-aws-modules/ec2-instance/aws&quot;<br><br>  name          = module.test_appserver_label.id<br>  key_name      = module.test-server_ssh_key_pair.key_name<br>  ami           = &quot;ami-00826bd51e68b1487&quot;<br>  instance_type = &quot;t3.medium&quot;<br>  iam_instance_profile        = aws_iam_instance_profile.ec2_test_instance.name<br>  associate_public_ip_address = false<br>  vpc_security_group_ids      = [module.test_appserver_sg.security_group_id]<br>  subnet_id                   = module.vpc.private_subnets[0]<br>  disable_api_termination     = true<br>  #user_data = templatefile(&quot;./userdata/bootstrap.tpl&quot;, {<br>  #s3_access_rolein_striad_arn = var.s3_access_rolein_striad_arn<br>  #})<br><br>  root_block_device = [{<br>    encrypted   = true<br>    volume_size = 30<br>  }]<br><br>  ebs_block_device = [<br>    {<br>      device_name = &quot;/dev/sdb&quot;<br>      volume_size = 50<br>      encrypted   = true<br>    }<br>  ]<br><br>  tags = module.appserver_label.additional_tag_map<br>}<br><br><br>#AWS EC2 security group<br>module &quot;test_appserver_label&quot; {<br>  source = &quot;cloudposse/label/null&quot;<br><br>  namespace      = var.project<br>  environment    = var.environment<br>  name           = &quot;test_appserver&quot;<br>  delimiter      = &quot;-&quot;<br>  label_order    = [&quot;namespace&quot;, &quot;name&quot;, &quot;environment&quot;]<br>  labels_as_tags = [&quot;name&quot;, &quot;environment&quot;]<br>  additional_tag_map = {<br>    &quot;Project&quot;   = var.project<br>    &quot;Owner&quot;     = var.owner<br>    &quot;ManagedBy&quot; = &quot;Terraform&quot;<br>  }<br>}<br><br>module &quot;test_appserver_sg&quot; {<br>  source = &quot;terraform-aws-modules/security-group/aws&quot;<br><br>  name            = module.test_appserver_label.id<br>  use_name_prefix = false<br>  description     = &quot;Security group for test_appserver instance&quot;<br>  vpc_id          = module.vpc.vpc_id<br><br>  egress_rules = [&quot;all-all&quot;]<br><br>  ingress_with_source_security_group_id = [<br>    {<br>      from_port                = 22<br>      to_port                  = 22<br>      protocol                 = &quot;tcp&quot;<br>      description              = &quot;SSH access from Bastion&quot;<br>      source_security_group_id = module.bastion-sg.security_group_id<br>    }<br>  ]<br><br>  tags = module.prodigy_label.additional_tag_map<br>}</pre><pre>#ALB Security Group<br>module &quot;test_appserver_alb_label&quot; {<br>  source = &quot;cloudposse/label/null&quot;<br><br>  namespace      = var.project<br>  environment    = var.environment<br>  name           = &quot;test-alb&quot;<br>  delimiter      = &quot;-&quot;<br>  label_order    = [&quot;namespace&quot;, &quot;name&quot;, &quot;environment&quot;]<br>  labels_as_tags = [&quot;name&quot;, &quot;environment&quot;]<br>  additional_tag_map = {<br>    &quot;Project&quot;   = var.project<br>    &quot;Owner&quot;     = var.owner<br>    &quot;ManagedBy&quot; = &quot;Terraform&quot;<br>  }<br>}<br><br>module &quot;test_appserver_alb_sg&quot; {<br>  source = &quot;terraform-aws-modules/security-group/aws&quot;<br><br>  name                = module.test_appserver_alb_label.id<br>  use_name_prefix     = false<br>  description         = &quot;Allows HTTPS access to ALB which proxies requests to test_appserver EC2&quot;<br>  vpc_id              = module.vpc.vpc_id<br>  ingress_cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  ingress_rules       = [&quot;http-80-tcp&quot;, &quot;https-443-tcp&quot;]<br>  egress_rules        = [&quot;all-all&quot;]<br>  tags                = module.test_appserver_alb_label.additional_tag_map<br>}<br><br>module &quot;test_appserver_alb_sg_rule&quot; {<br>  source = &quot;terraform-aws-modules/security-group/aws&quot;<br><br>  create_sg         = false<br>  security_group_id = module.test_appserver_sg.security_group_id<br>  ingress_with_source_security_group_id = [<br>    {<br>      description              = &quot;alb to test_appserver EC2&quot;<br>      from_port                = 80<br>      to_port                  = 80<br>      protocol                 = &quot;tcp&quot;<br>      source_security_group_id = module.test_appserver_alb_sg.security_group_id<br>    },<br>  ]<br>}</pre><pre>#AWS ALB<br>module &quot;test_appserver_alb&quot; {<br>  source = &quot;terraform-aws-modules/alb/aws&quot;&quot;<br><br>  name                       = module.test_appserver_alb_label.id<br>  load_balancer_type         = &quot;application&quot;<br>  vpc_id                     = module.vpc.vpc_id<br>  subnets                    = flatten([module.vpc.public_subnets])<br>  security_groups            = [module.test_appserver_alb_sg.security_group_id]<br>  drop_invalid_header_fields = true<br>  target_groups = [<br>    {<br>      name             = &quot;${var.project}-test-${var.environment}&quot;<br>      backend_protocol = &quot;HTTP&quot;<br>      backend_port     = 80<br>      target_type      = &quot;instance&quot;<br>      health_check = {<br>        enabled             = true<br>        interval            = 30<br>        path                = &quot;/health&quot;<br>        port                = &quot;traffic-port&quot;<br>        healthy_threshold   = 5<br>        unhealthy_threshold = 3<br>        protocol            = &quot;HTTP&quot;<br>      }<br>      targets = [<br>        {<br>          target_id = module.ec2-test-appserver.id<br>          port      = 80<br>        },<br>      ]<br>    }<br>  ]<br>  https_listeners = [<br>    {<br>      port               = 443<br>      protocol           = &quot;HTTPS&quot;<br>      certificate_arn    = module.acm_test_alb.acm_certificate_arn<br>      target_group_index = 0<br>    }<br>  ]<br>  http_tcp_listeners = [<br>    {<br>      port               = 80<br>      protocol           = &quot;HTTP&quot;<br>      target_group_index = 0<br>      action_type        = &quot;redirect&quot;<br>      redirect = {<br>        port        = &quot;443&quot;<br>        protocol    = &quot;HTTPS&quot;<br>        status_code = &quot;HTTP_301&quot;<br>      }<br>    }<br>  ]<br>  https_listener_rules = [<br>    {<br>      actions = [{<br>        type               = &quot;forward&quot;<br>        target_group_index = 0<br>      }]<br>      conditions = [{<br>        host_headers = [&quot;${data.aws_route53_zone.domain.name}&quot;]<br>      }]<br>    },<br>  ]<br>}</pre><pre>#AWS Rroute53 record<br>resource &quot;aws_route53_record&quot; &quot;test_appserver-records&quot; {<br>  zone_id         = data.aws_route53_zone.domain.zone_id<br>  name            = var.test-domain-name<br>  type            = &quot;A&quot;<br>  allow_overwrite = true<br>  alias {<br>    name                   = module.test_appserver_alb.lb_dns_name<br>    zone_id                = module.test_appserver_alb.lb_zone_id<br>    evaluate_target_health = true<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb2183cbc5cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Cloud: Different ways to connect to AWS RDS Database (Postgres)]]></title>
            <link>https://medium.com/@noor563/aws-cloud-different-ways-to-connect-to-aws-rds-database-postgres-7520ecfe2da4?source=rss-79d099624a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/7520ecfe2da4</guid>
            <category><![CDATA[aws-rds-postgress]]></category>
            <category><![CDATA[bastion-to-rds-postgres]]></category>
            <category><![CDATA[python-connect-postgres]]></category>
            <category><![CDATA[pgadmin-ssh-postgres]]></category>
            <category><![CDATA[ssh-to-ec2-bastion]]></category>
            <dc:creator><![CDATA[Noor ul Hoda]]></dc:creator>
            <pubDate>Wed, 08 Feb 2023 12:22:35 GMT</pubDate>
            <atom:updated>2023-02-08T12:22:35.714Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Requirements: </strong>Accessing AWS RDS Postgres engine Database which is deployed in a private subnet of a VPC from your local machine/Bastion server(Deployed in the public subnet of the VPC)</p><p><strong>Challenges: </strong>Since Database is deployed in the private subnet, can’t be accessible through public-facing internet.</p><p><strong>Different ways someone can connect to RDS.</strong></p><ol><li>Connecting from the PGAdmin4 client</li><li>Connecting using an ssh tunnel from your local machine</li><li>Connecting through Python package psycopg2</li></ol><p><strong>First setting up SSH key into Bastion Host:</strong></p><p>Create your ssh key using the below command:</p><pre>&gt; ssh-keygen ~/.ssh/&lt;key-name&gt;</pre><p>2. First-time login with AWS EC2 key-pair. Add your public key (key-name.pub) to the Bastion server authorized_keys.</p><pre>&gt; vi ~/.ssh/authorized_keys</pre><p>3. Whitelist your local IP address into the bastion server security group (bastion is restricted to IP addresses).</p><p>4. log in to the bastion server now with your private ssh key:</p><pre>ssh -i ~/.ssh/&lt;key-name&gt; &lt;user-name&gt;@&lt;public-ipv4-address&gt;</pre><p>Note:- <a href="/service/mailto:ec2-user@18.133.78.174">&lt;user-name&gt;</a> dependent on the ami image you are selecting (eg:- AmazonEC2 — ec2-user, UbuntuEC2- ubuntu).</p><ol><li><strong>Connecting from the PGAdmin4 client:</strong></li></ol><p>a. Download and install PgAdmin from the following URL</p><p>pgAdmin Download</p><p>b. Open the pgAdmin4 client application and click on “Register server”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*_yoPzMyUBEKe3lXNaBY7VA.png" /></figure><p>c. Enter the name of the database you want to keep:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*xWLuro_HvzYSYgjjXe9zOg.png" /></figure><p>d. Enter the Connection details as mentioned below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*4J_qDH5qCXdh-LeheU3nbA.png" /></figure><p>e. Enter the ssh-Tunnel details as mentioned below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*aLqB2O7F0d760Y4M2XDaBg.png" /></figure><p>f. Finally click on <strong>save</strong> and the RDS PG instance will be connected if all the details are valid.</p><p>The second way of connecting to RDS database:</p><p><strong>2. Connecting using an ssh tunnel from your local machine:</strong></p><p>a. Create an ssh tunnel from your local machine to RDS using the Bastion server:</p><pre>nohup ssh -i &quot;&lt;key-name&gt;&quot; -NL 8886:&lt;postgres-rds-endpoint&gt;:5432 ec2-user@&lt;bastion-public-ipv4-address&gt; &amp;</pre><p>b. Check if the tunnel is established correctly or not:</p><pre>ps -ef |grep ssh</pre><p>netstat -nta tcp | grep -i LISTEN | grep 8886</p><p>c. Test is RDS is connecting or not:</p><p>psql -h &lt;rds-endpoint&gt; -p5432 -U &lt;user-name&gt; -d postgres</p><p>d. Provide your &lt;rds-password&gt; runtime</p><p>The third way of connecting to RDS database:</p><p><strong>3. Connecting through Python package psycopg2:</strong></p><p>a. Ensure the psycopg2 package is installed in your machine:</p><pre>import psycopg2<br>def connect_to_postgres_db():<br>    conn = psycopg2.connect(<br>        host=&quot;&lt;db-endpoint&gt;&quot;,<br>        database=&quot;postgres&quot;,<br>        user=&quot;&lt;user-name&gt;&quot;,<br>        password=&quot;&lt;db-password&gt;#&quot;,<br>        port=5432)<br>    return conn<br>conn = connect_to_postgres_db()</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7520ecfe2da4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[01. Migrating AWS RDS data encrypted with KMS key from the source account to the target account]]></title>
            <link>https://medium.com/@noor563/01-migrating-aws-rds-data-encrypted-with-kms-key-from-the-source-account-to-the-target-account-73fa2c056aae?source=rss-79d099624a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/73fa2c056aae</guid>
            <category><![CDATA[s3-bucket]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[km]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[rds]]></category>
            <dc:creator><![CDATA[Noor ul Hoda]]></dc:creator>
            <pubDate>Wed, 30 Nov 2022 10:05:58 GMT</pubDate>
            <atom:updated>2023-07-24T11:11:27.175Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Requirement</strong>: Copying encrypted Amazon RDS snapshot from source account to target account and restoring it with the existing running Amazon RDS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OjZoyLq3YFbbr4G7rbmkWw.png" /></figure><p><strong>Challenges</strong>: You can’t share an RDS snapshot that’s encrypted using the default AWS KMS encryption key.</p><p><strong>Why Not Amazon Data Migration Services: </strong>The main issue with DMS was when creating tables does not copy across primary keys, foreign keys, indexing, etc., and where the tables are created already DMS docs recommend disabling PKs, FKs, indexes, etc. The validation step of DMS was showing that the copied data wasn’t a 100% match, possibly because the row IDs were being changed.</p><h4><strong>Resolution</strong>:</h4><h4>Allowing access to the target account on the AWS KMS key of the source account</h4><p>1. Log in to the source account, and then open the <a href="https://console.aws.amazon.com/kms">AWS KMS console</a> in the same AWS Region as the DB snapshot.</p><p>2. Choose Customer managed keys from the navigation pane.</p><p>3. Choose the name of your customer-managed key, or choose to Create key, if you don’t yet have one. For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html">Creating keys</a>.</p><p>4. From the Key administrator’s section, Add the AWS Identity and Access Management (IAM) users and roles who can administer the AWS KMS key.</p><p>5. From the Key user’s section, Add the IAM users and roles who can use the AWS KMS key (KMS key) to encrypt and decrypt data.</p><p>6. In the Other AWS accounts section, choose to Add another AWS account and then enter the AWS account number of the target account. For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-modifying-external-accounts.html">Allowing users in other accounts to use a KMS key</a>.</p><h4>Copy and share the snapshot (In the source account)</h4><p>1. Open the <a href="https://console.aws.amazon.com/rds">Amazon RDS console</a>, and then choose Snapshots from the navigation pane.</p><p>2. Choose the name of the snapshot that you created, choose Actions, and then choose <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CopySnapshot.html">Copy Snapshot</a>.</p><p>3. Choose the same AWS Region that your KMS key is in, and then enter a New DB Snapshot Identifier.</p><p>4. In the Encryption section, choose the KMS key that you created.</p><p>5. Choose Copy Snapshot.</p><p>6. <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ShareSnapshot.html#USER_ShareSnapshot.Sharing">Share the copied snapshot</a> with the target account.</p><h4>Copy the shared DB snapshot (In the target account)</h4><p>1. Log in to the target account, and then open the<a href="https://console.aws.amazon.com/rds"> Amazon RDS console</a>.</p><p>2. Choose Snapshots from the navigation pane.</p><p>3. From the Snapshots pane, choose the Shared with Me tab.</p><p>4. Select the DB snapshot that was shared.</p><p>5. Choose Actions, and then choose Copy Snapshot to copy the snapshot into the same AWS Region</p><p>6. Enter the KMS key ARN from the source account (option — <strong>Enter a key ARN</strong>)</p><p>7. Snapshot is now available in the target account.</p><h4>Challenge 2: Restoring a snapshot to the existing Postgres RDS (In Target account)</h4><p><strong>1. Create a temporary Postgres RDS instance from the copied snapshot.</strong></p><blockquote>a. Go to snapshot from the navigation.</blockquote><blockquote>b. From Action, select Restore snapshot and select the required configuration.</blockquote><blockquote>c. Restore DB instance.</blockquote><p><strong>2. Spin up an EC2 server with psql and pg_dump packages installed and connect to the RDS instance.</strong></p><blockquote>a. psql -h &lt;rds-endpoint&gt; -p5432 -U&lt;user-name&gt; -d postgres</blockquote><p>Note — test with your existing target RDS connection</p><p><strong>3. Creating the backup.sql dump: Use the pg_dump command to create the backup of the temporary RDS instance in the ec2 server (Bastion-server).</strong></p><p>Note → Make sure your ec2 server is having enough to backup the data</p><blockquote>a. nohup pg_dump postgresql://&lt;temp-username&gt;:&lt;password&gt;@&lt;host&gt;:&lt;port&gt;/&lt;database&gt; &gt; backup.sql &amp;</blockquote><p>Note — &lt;temp-username&gt;/&lt;password&gt; → your source username and password</p><p>&lt;host&gt; → your temp rds endpoint</p><p>&lt;database&gt; → name of the database (project_db_environment)</p><p><strong>4. Restoring the backup.sql using psql command: Restore the backup to the existing RDS instance.</strong></p><blockquote>a. nohup psql postgresql://&lt;username&gt;:&lt; password&gt;@&lt;host&gt;:&lt;port&gt;/&lt;database&gt; -f backup.sql &amp;</blockquote><p>Note — &lt;username&gt;/&lt;password&gt; → your destination db username and password</p><p>&lt;database&gt; → name of the database (project_db_environment)</p><h4><strong>Note:</strong></h4><p><strong>1. If the existing RDS is having old data in it, then after connecting to RDS</strong></p><blockquote>a. DROP DATABASE &lt;data_base_name&gt;;</blockquote><blockquote>b. CREATE DATABASE &lt;data_base_name&gt;;</blockquote><p><strong>2. Some handy commands to verify:</strong></p><blockquote>a. \l — list database</blockquote><blockquote>b. \c — switch to a particular database</blockquote><blockquote>c. \dt –list database tables</blockquote><blockquote>d. \du –list users</blockquote><blockquote>e. \dn — list schema</blockquote><blockquote>f. \l+ — show the size of the tables</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73fa2c056aae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>