<?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"><channel><title><![CDATA[AWS X SUJAN]]></title><description><![CDATA[Let's simplify AWS.]]></description><link>https://sujanmagar.com.np</link><generator>RSS for Node</generator><lastBuildDate>Wed, 07 Oct 2026 00:54:40 GMT</lastBuildDate><atom:link href="https://sujanmagar.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Project: AWS Site to Site VPN]]></title><description><![CDATA[Hello Everyone,
In this blog, we'll be learning how to set up an AWS Site-to-Site VPN.
When connecting on-premises network to AWS, there are two main options: IPSec VPN and AWS Direct Connect.

IPSec VPN: This option sets up a secure VPN connection b...]]></description><link>https://sujanmagar.com.np/project-aws-site-to-site-vpn</link><guid isPermaLink="true">https://sujanmagar.com.np/project-aws-site-to-site-vpn</guid><category><![CDATA[AWS]]></category><category><![CDATA[AWS Site-to-Site VPN]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Fri, 16 Aug 2024 15:37:29 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1723818332126/2bc68f5b-2ea8-402d-9167-e50e5e1f2954.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello Everyone,</p>
<p>In this blog, we'll be learning how to set up an AWS Site-to-Site VPN.</p>
<p>When connecting on-premises network to AWS, there are two main options: IPSec VPN and AWS Direct Connect.</p>
<ol>
<li><p><strong>IPSec VPN:</strong> This option sets up a secure VPN connection between your AWS VPC and on-premises network, with traffic encrypted and transmitted over the internet. It's a popular choice for small to medium-sized companies due to its ease of setup. Once established, both networks can communicate seamlessly over private IP addresses.</p>
</li>
<li><p><strong>AWS Direct Connect:</strong> This is a dedicated, point-to-point physical connection between your on-premises network and an AWS data center. It offers a more stable and faster connection but requires more setup and is generally used by larger enterprises.</p>
</li>
</ol>
<p>In this blog, we will be setting up an AWS VPN connection.</p>
<hr />
<h3 id="heading-overview">Overview</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723805468401/67de3582-997b-4cd0-aafe-fec824549f47.png" alt class="image--center mx-auto" /></p>
<p>On the AWS side, we have a VPC and a Virtual Private Gateway (VGW), which function as the AWS-side endpoint for the VPN connection. On the on-premises side, we need a router, known as the Customer Gateway (CGW), which must be accessible over the internet and have a public IP address.</p>
<p>We can set up the AWS-side network in our chosen AWS region. Since we don't have access to an actual on-premises network, we'll simulate the corporate network.</p>
<p>We'll create another VPC in a different region and use an EC2 instance with Openswan software as our router. In a real-world scenario, well-known routers are typically used for VPN connections, but to minimize costs, we'll use this setup.</p>
<blockquote>
<p>Openswan is an open-source implementation of IPsec (Internet Protocol Security) for Linux. It enables secure communication between systems over an untrusted network, like the internet, by creating encrypted tunnels. It’s commonly used for setting up VPNs to protect data in transit.</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723807663697/37ad4b75-4dde-4862-8545-6aff6a36f129.png" alt class="image--center mx-auto" /></p>
<p>On the left side, we have the AWS network, and on the right side, the simulated corporate network. The EC2 instance on the AWS side does not need internet access, so we will create a private subnet in the VPC with an EC2 instance that has only a private IP address.</p>
<p>On the right side, we'll have a VPC with a public subnet because we need to launch an EC2 instance there and configure Openswan on it. To set up Openswan, we need to connect to this instance over the internet, which is why it must be placed in a public subnet.</p>
<p>The AWS-side instance can only be reached from the on-premises EC2 instance once the VPN connection is established.</p>
<hr />
<h3 id="heading-task-1-set-up-aws-infrastructure">Task 1: Set Up AWS Infrastructure</h3>
<p>Let's create VPC.</p>
<p>Search for <strong>VPC</strong> in the search box.</p>
<p>For the AWS side, I'm choosing Mumbai region.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723443396288/1ef135dd-c6fe-4bea-90dc-45c10233f02a.png" alt /></p>
<p>Provide a name &amp; CIDR range for your VPC.</p>
<p>Keeping all other configurations as is, click on <code>Create VPC</code>.</p>
<p>Now, it's time to create a private subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723444174328/f0ca7fe4-04e5-4dda-bd8d-d9a4d0df13b2.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723444240524/22b5d272-cd81-4b5e-accb-d40bb9db5626.png" alt /></p>
<p>Select your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723444256990/bb3aaa2e-ee08-48d6-ada6-10117ed3dec5.png" alt /></p>
<p>Provide the name and eligible CIDR value for your subnet, then click on <code>Create subnet</code>.</p>
<p>Let's create route table now.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723444353628/1733db76-7360-4c7d-ad09-d764ee1777f4.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723444424730/9e1a8abe-bc4c-494c-915c-df2269b36782.png" alt class="image--center mx-auto" /></p>
<p>Provide name for your route table, select your VPC and click on <code>Create route table</code>.</p>
<p>In the public subnet's route table, we need a route for the internet, and we add the corresponding entry. However, in this case, we don't need that but we need to associate this route table with the subnet we created.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723444515140/98950b48-7358-4300-a654-75a5fbdf24b2.png" alt /></p>
<p>Click on your route table and in the <strong>Subnet associations</strong> tab, click on <code>Edit subnet associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723444559959/8617377f-e11f-4603-85e7-d890628ece84.png" alt /></p>
<p>Select your subnet and click <code>Save associations</code>.</p>
<p>Alright, now it's time to create an EC2.</p>
<p>Go to the EC2 console.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723444649012/e3a09716-3f95-43f6-a55a-11cf638dbf05.png" alt /></p>
<p>Click on <code>Launch instances</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723444699579/675a1dae-e774-4cd9-ae5c-2e07358b26bf.png" alt /></p>
<p>Make sure to select the Amazon Linux 2 AMI, as the latest version (Amazon Linux 2023) does not support Openswan, which we are going to implement.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723444774535/3950b28a-406f-4aaf-bdc5-9c467ece4b6f.png" alt /></p>
<p>Create key pair for your instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723444838156/101e2ffc-7fa7-4c2a-9111-8598e34e01c4.png" alt /></p>
<p>Edit <strong>Network settings</strong>. Choose your VPC and subnet.</p>
<p>Keep <strong>Auto-assign public IP</strong> as default.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723445067653/aa801718-4ab6-4d46-9205-2656107fe62b.png" alt class="image--center mx-auto" /></p>
<p>When configuring the security group (SG), refer to the network diagram and ask yourself, <strong><em>'From where will this EC2 instance receive traffic?'</em></strong></p>
<p>Since the traffic will only come from the on-premises network <code>11.0.0.0.0/16</code>, we should allow all traffic from that network.</p>
<p>Allow all TCP traffic on every port from the on-premise network's CIDR range.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723445097841/fe6d1beb-4af7-42a3-a496-7492e5f441e3.png" alt class="image--center mx-auto" /></p>
<p>To enable ping from the on-premises EC2 to the AWS-side EC2, ensure that the ping protocol (ICMP) is also enabled.</p>
<p>Keeping all other configurations as is, click on <code>Launch instance</code>.</p>
<hr />
<h3 id="heading-task-2-setup-on-premise-infrastructures">Task 2: Setup On-premise Infrastructures</h3>
<p>Let's start by creating a VPC. This time, I am choosing a different region.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723445335972/77a14440-68b2-461c-9240-5d047665907d.png" alt /></p>
<p>Provide a name for your VPC and provide CIDR range.</p>
<blockquote>
<p><em>Note that your VPC's CIDR range must not overlap with each other.</em></p>
</blockquote>
<p>Click on <code>Create VPC</code>.</p>
<p>Since I need a public subnet, it's required to attach an Internet Gateway to the VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723445621000/80803482-ba89-4c7d-ad65-bc05eabec7f8.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723445729678/36facda9-d91f-4b50-91dd-aaa483435789.png" alt class="image--center mx-auto" /></p>
<p>Provide name for your Internet Gateway and click on <code>Create Internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723445768580/cf448679-be66-4f73-b2da-3f0fee16435e.png" alt /></p>
<p>After creating your internet gateway, attach it to your VPC.</p>
<p>Now, let's create our public subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723446119616/d37caae6-831b-4981-ba58-e679fda9ea43.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723446295263/f3b4d03f-3dad-47dd-af31-69105cb8d3f3.png" alt /></p>
<p>Select your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723447454448/aac5d18f-a741-4a21-ac8f-45176ddec750.png" alt /></p>
<p>Provide a suitable name, provide an eligible CIDR range and then click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723446594619/ebf06721-edeb-4b1a-868d-5ac24babe114.png" alt /></p>
<p>It's time to create route table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723446641401/1a586335-5e3b-4f7b-9fd3-37122e55261b.png" alt /></p>
<p>Provide a name for your route table, select your VPC and click on <code>Create route table</code>.</p>
<p>In the public subnet's route table, we need a route to the internet, so let's add the corresponding entry.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723446788726/0b8b1032-73c1-436e-bda1-370c4f7bb364.png" alt /></p>
<p>Click on <code>Save changes</code>.</p>
<p>Now, let's associate this route table to our subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723446885810/e0298686-349a-4613-b7f3-33eea5c8f6f9.png" alt /></p>
<p>Click on <code>Edit subnet associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723447539096/98c99f36-5b60-4b84-ac0e-6595e5fd4f00.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Save associations</code>.</p>
<p>Now that we have set up the VPC, subnet, and IGW, it's time to create an instance which will act as our Customer Gateway.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723447081306/2a874f75-cf92-476a-af60-d9b99e9e6643.png" alt /></p>
<p>Let's select the same AMI to ensure consistency.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723447131327/70621b11-6666-4cb5-80aa-273b1ad16f2b.png" alt /></p>
<p>Create key pair for your instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723447577632/cb8ae4d4-9dd0-46dc-b424-5d71785eecc7.png" alt /></p>
<p>Edit <strong>Network Settings</strong>. Choose your VPC and select your public subnet. Make sure to <strong>Enable</strong> Auto-assign public IP.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723447789276/6dddc534-8897-4966-8bf9-31983cb0ea02.png" alt /></p>
<p>In the security group, since we'll be logging into this EC2 instance from our machine, we need to set up an SSH connection, allowing traffic from our IP address. Additionally, we'll allow all TCP traffic from the other side of the network and enable the ping protocol.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723447909785/f4597d9a-1e7a-49e5-b7d1-6f3f4b48ac7e.png" alt /></p>
<p>With all other configurations unchanged, click on <code>Launch Instance</code>.</p>
<hr />
<h3 id="heading-task-3-set-up-vpn-connection">Task 3: Set up VPN Connection</h3>
<p>We've set up two VPCs, but they currently have no communication between them. The next step is to create and configure a Virtual Private Gateway (VGW) for the VPN. To do this, we need the public IP address of our EC2 instance acting as a router, as this is required to specify the location of the customer router while creating the VPN connection.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723448159440/4de423af-6c8e-41e2-9f93-b1daabc7b11b.png" alt /></p>
<p>Copy the public IP address and switch to the AWS network side.</p>
<p>Go to the VPC dashboard.</p>
<p>Scroll down to the <strong>Virtual private network</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723448297995/6f06ac57-beb7-40aa-a7c3-58b9665cc60d.png" alt /></p>
<p>Click on <code>Create virutal private gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723448445405/a90c6983-49d6-4d3b-bc86-dd64e7f4774c.png" alt /></p>
<p>Provide a name and click on <code>Create virtual private gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723448575623/078ab1ef-f217-4b3e-abe7-b5556c5458cb.png" alt class="image--center mx-auto" /></p>
<p>Attach to your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723448598634/59ec582f-85a6-4f48-9365-42178da71a20.png" alt class="image--center mx-auto" /></p>
<p>Now, it's time to create <strong>Customer Gateway</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723448729747/70a5031f-4009-4907-92b8-497ff3afcf0e.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Create customer gateway</code>.</p>
<p>The Customer Gateway (CGW) represents the on-premises side of the network and is not part of the AWS network. It is where we will configure the IP address associated with the on-premises network.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723449087515/a74c7852-94c0-47b1-8a96-4f179c50e25d.png" alt /></p>
<p>After configuring the details, click on <code>Create customer gateway</code>.</p>
<p>Now that we have both the VPGW and CGW, we can use them to create a site-to-site VPN connection.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723449199757/7e54b9fa-e44e-494f-89b7-d6cd893902de.png" alt /></p>
<p>On <strong>Site-to-Site VPN connections,</strong> click on <code>Create VPN connection</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723455340228/2a96376e-b29d-48d6-b269-f4a5793d752f.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723784381618/5dd87d2e-1b63-4bc5-9b94-ae86bd88279c.png" alt /></p>
<p>When setting up a VPN connection, we can use either static routing or dynamic routing to manage the paths data takes between networks.</p>
<ol>
<li><p><strong>Static Routing</strong></p>
<ul>
<li><p>Routes are manually configured by specifying the exact paths for traffic.</p>
</li>
<li><p>It's simple to implement and is typically used for small or straightforward networks.</p>
</li>
<li><p>Requires manual updates if network topology changes.</p>
</li>
</ul>
</li>
<li><p><strong>Dynamic Routing</strong></p>
<ul>
<li><p>Routes are automatically determined and adjusted by routing protocols like BGP (Border Gateway Protocol).</p>
</li>
<li><p>It's more complex but ideal for large or changing networks.</p>
</li>
<li><p>Automatically adapts to network changes, providing better scalability and resilience.</p>
</li>
</ul>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723784420615/f42b1505-96e2-4b19-a49a-1a9fb4c97f56.png" alt /></p>
<p><strong>Static IP Prefixes:</strong> It allows the Virtual Private Gateway (VGW) to recognize which IP prefixes belong to the on-premises network, ensuring that traffic destined for those addresses is correctly routed.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723455419809/a89b3e40-28dc-41f4-bd87-afc9d7026d92.png" alt /></p>
<p>For the local IPv4, provide your on-premises CIDR value. For the remote IPv4, provide the AWS-side network CIDR.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723449681315/d0db2f0c-8daa-463c-aced-571ad9c8dc76.png" alt class="image--center mx-auto" /></p>
<p>For the Tunnel options, we can either keep the default settings or configure specific options, such as the pre-shared key. AWS VPN creates two tunnels for high availability, and the connection uses the secure IPsec protocol. This process involves sharing a key between the two endpoints. We can set up our own pre-shared key, or if we choose not to, AWS will generate one for us.</p>
<p>We'll let AWS handle the configuration, click <code>Create VPN Connection</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723449806672/1fc78034-f7f9-44ba-ac84-908642bc11bd.png" alt class="image--center mx-auto" /></p>
<p>While this is pending, let's set up our Openswan server on the on-premises instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723450093958/e405c546-a044-4317-997c-e92202bb8b8e.png" alt /></p>
<p>Select your EC2 and click on <code>Connect</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723450152380/27dc5416-6617-4705-bf8f-8f072caaad7a.png" alt class="image--center mx-auto" /></p>
<p>We're establishing an SSH connection to our instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723450237354/4234d114-6036-4588-8adc-25e32a88295a.png" alt class="image--center mx-auto" /></p>
<p>Switch to the root user to ensure you have full permissions to install Openswan.</p>
<pre><code class="lang-bash"><span class="hljs-comment">#switching to root user</span>
sudo su
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment">#installing openswan</span>
yum install openswan -y
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723450403579/c718e3dc-28c0-4ae9-bf46-4feff07d09e0.png" alt /></p>
<p>Now, let's configure Openswan.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723450610985/b1bfaa9a-fd01-428b-9613-f2bf940a9994.png" alt /></p>
<p>In the <code>ipsec.conf</code> file, ensure there is an uncommented line at the end, allowing us to add additional files to this directory.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723450583108/0debb922-a641-49de-ad23-51feee1a62cb.png" alt /></p>
<p>The next step is to update the <code>/etc/sysctl.conf</code> file. This is necessary because this machine will act as a router, forwarding the traffic it receives to another machine within the same on-premises network. We need to configure specific settings by adding a couple of lines to this file.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723451015940/4b2c2857-dee2-4f22-a248-926567cf248f.png" alt /></p>
<pre><code class="lang-bash">vim /etc/sysctl.conf
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723450733240/56c76297-00b6-400d-8904-621ffbb03fee.png" alt /></p>
<p>Press <code>i</code> to enter into insert mode.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723450922215/25baca19-fba2-444c-a127-d5efe5c212c5.png" alt /></p>
<pre><code class="lang-bash"><span class="hljs-comment"># Enable IP forwarding for routing</span>
net.ipv4.ip_forward = 1

<span class="hljs-comment"># Disable acceptance of ICMP redirects</span>
net.ipv4.conf.all.accept_redirects = 0

<span class="hljs-comment"># Disable sending of ICMP redirects</span>
net.ipv4.conf.all.send_redirects = 0
</code></pre>
<p>After making the changes, press <code>Esc</code> to exit insert mode, then type <code>:wq!</code> to save and exit the file.</p>
<p>Now, we need to restart the network service.</p>
<pre><code class="lang-bash">service network restart
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723451060171/e530a081-0770-4441-a1f1-fdbd02a5db01.png" alt /></p>
<p>Next, we need to configure our IPsec VPN. So far, we've only installed the software but haven't configured it yet. We'll need to specify details such as the AWS side of the network, the pre-shared key, and other settings.</p>
<p>To obtain these settings, we can download a text file from AWS that contains all the necessary configuration details, which we can then use to configure the IPsec VPN.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723449884104/ef4c836e-d6d6-497c-95ad-0e631ef8c3c6.png" alt /></p>
<p>Select your VPN connection and click <code>Download configuration</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723451120735/757ed346-9870-4d2b-bfec-e7178ea06e29.png" alt /></p>
<p>If you open the file in a text editor, you'll find that it covers most of the configurations we've already completed. More importantly, it contains tunnel details.</p>
<p>Now, we need to create the file <code>/etc/ipsec.d/aws.conf</code> in our instance.</p>
<pre><code class="lang-bash">vim /etc/ipsec.d/aws.conf
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723451294571/bbafa5bb-17f6-48b6-bcf8-9c00327a379d.png" alt /></p>
<p>Simply copy the entire block of tunnel details from the downloaded file and paste it into the <code>/etc/ipsec.d/aws.conf</code> file.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723451558833/5a9118a2-fb2f-4c15-b707-c39b9f0546be.png" alt /></p>
<p>The default settings may cause issues with the VPN connection, particularly the line <code>auth=esp</code>, which is not supported. Be sure to delete this line from the file and then save your changes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723451594077/15d5d5b5-85d3-450b-9628-42efc0c821ea.png" alt class="image--center mx-auto" /></p>
<p>Similarly, we need to create the file <code>/etc/ipsec.secrets</code>. This file should contain the pre-shared key, as we mentioned earlier. Create the file and add the pre-shared key entry to it.</p>
<pre><code class="lang-bash">vim /etc/ipsec.d/aws.secrets
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723451738382/45a11245-b0ff-409a-bc33-f7082a0b8244.png" alt /></p>
<p>In the downloaded configuration file, look for your pre-shared key. Copy &amp; paste it into the created file.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723452091115/256df2a3-78c0-4bb5-a4f8-f81fb3f942f2.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723452057407/2eb900c0-38a1-4de2-a934-8b8938c921d9.png" alt class="image--center mx-auto" /></p>
<p>That's it. The <code>/etc/ipsec.conf</code> file will contain information for two tunnels because AWS provides two tunnels for high availability. While OpenSwan supports multiple VPN tunnels on a single host, careful configuration is essential to prevent conflicts. For this initial setup, we'll establish a single VPN tunnel to ensure a stable foundation.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723452155646/a64d749f-153b-487f-82de-1089b2441fea.png" alt /></p>
<p>The <code>leftid</code> field represents the IP address of the customer-side network, which in this case comes from the EC2 instance running OpenSwan. The <code>rightid</code> field represents the IP address at the other end of the connection, which is the AWS side.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723453009074/1174ec4e-0f26-4d98-bfa7-59f32b181e0e.png" alt /></p>
<pre><code class="lang-bash">vim /etc/ipsec.d/aws.conf
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723453059962/8ecd93fc-cd3e-4ad6-b13b-99850afd0ff5.png" alt /></p>
<p>Next, we need to configure the <code>leftsubnet</code> and <code>rightsubnet</code> values in the file. The <code>leftsubnet</code> represents the CIDR block of the corporate network side, while the <code>rightsubnet</code> represents the CIDR block of the AWS side. Update these values in your configuration file to reflect the correct CIDR blocks for each side of the network.</p>
<p>Next, we will configure the route table for the private subnet by adding a route that directs traffic destined for the on-premises CIDR block to the VGW.</p>
<p>For this, go to the AWS side route table. Instead of manually adding a route to the VGW, we will use route propagation. This allows the VGW to automatically update the route table with the CIDR blocks from the AWS side.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723453152558/e6852add-9ab1-4961-a4e8-76172ab22937.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Edit route propagation</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723453178111/dd38e268-2f13-4d23-9b60-c6d01e53de4e.png" alt class="image--center mx-auto" /></p>
<p>Enable route propagation and save the changes. Once the VPN tunnel is active, the route table will update automatically.</p>
<p>Ok so, we have completed the configuration of the IPsec configuration files and the secrets file. Now, it's time to start the VPN tunnel.</p>
<p>Go back to your terminal and run the command to initiate the VPN tunnel.</p>
<pre><code class="lang-bash">systemctl start ipsec
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723453304885/2be86e84-a59f-4936-be83-8e93a6301f17.png" alt /></p>
<p>Check the status of the IPsec service to confirm it's running.</p>
<pre><code class="lang-bash">systemctl status ipsec
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723453395923/95ec6ec0-80cb-4243-84fa-ca80835b32ea.png" alt /></p>
<p>To verify that the tunnel is functioning properly, it's important to remember that the VPN connection is always initiated from the customer side, not from AWS. If there is no traffic flowing from the customer side, the VPN tunnel may go down. To keep the tunnel active, ensure that you are sending keepalive packets or some form of traffic to maintain the connection.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723453418265/0b7fd819-c380-494d-8598-c657bcb670ce.png" alt class="image--center mx-auto" /></p>
<p>Now, let's return to the AWS Management Console and check the VPN connection status. Navigate to the Site-to-Site VPN connections section. You should see that the tunnel status is up, indicating that the VPN connection has been successfully established.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723453517716/d8d5bfd1-c0ee-4afe-855d-77f3902a933c.png" alt /></p>
<p>With the tunnel status showing as <strong>'Up'</strong>, the final test is to verify connectivity between the machines. From our current machine, let's attempt to ping the private IP address of the EC2 instance in the AWS network.</p>
<p>Copy the private IP of the EC2 instance and use the <code>ping</code> command to test connectivity.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723453625098/14c62fff-8751-4682-9844-75199c5e2c6b.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723455470062/d198458a-3ebd-464d-a52c-ea3d1ff0cb12.png" alt class="image--center mx-auto" /></p>
<p>If you see traffic flowing and responses coming through, it confirms that the VPN tunnel between the AWS network and the OpenSwan router has been successfully established.</p>
<hr />
<h3 id="heading-task-4-set-up-extended-infrastructure">Task 4: Set up Extended infrastructure</h3>
<p>Alright, now, let's proceed to set up our extended infrastructure.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723817934484/8674014d-75e5-43b5-aac1-129bfd38376a.png" alt class="image--center mx-auto" /></p>
<p>Switch over to your on-premise region.</p>
<p>Let's create a private subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723457692252/2e39d842-c5cb-4531-9675-0584aa6a703d.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723457790271/d13e22ff-ec03-4ff2-8c14-e7386c629b8e.png" alt /></p>
<p>Provide a name for your subnet, CIDR value then click on <code>Create subnet</code>.</p>
<p>After creating our private subnet, let's proceed to create route table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723457852376/bbab9e1b-45c9-4d4d-9972-c3f7bc3f4d78.png" alt /></p>
<p>Provide name for your route table, select your VPC and click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723457893130/92397b6e-c8bd-4c7b-84fb-c6184fdbbacb.png" alt class="image--center mx-auto" /></p>
<p>For now, we won't add any routes to this table. We'll specify the routes later. Just ensure that you associate this route table with the private subnet you created.</p>
<p>Now, let's create an EC2 instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723458018244/d27c0da5-0d04-4cfa-a2f9-56a983b8ba86.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723458035341/c4c96c1b-4049-4e6b-99b9-112fe026b73e.png" alt /></p>
<p>Create a new Key pair or use existing one for your instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723458065386/9762659f-8b36-4f72-80a7-2bdd8a8cc609.png" alt /></p>
<p>Edit <strong>Network settings</strong>. Select your VPC and choose your subnet.</p>
<p>Leave the <code>Auto-assign public IP</code> as default.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723459278564/b361a71d-dd60-4269-a0bc-b3a65198c9df.png" alt /></p>
<p>The only way to reach this server is through the Openswan server. We will log in to the Openswan server via SSH, and from there, we will access the server in the AWS network.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723459350753/385d63dc-61bb-4457-91eb-6138604588d9.png" alt class="image--center mx-auto" /></p>
<p>Also, configure the ping protocol to allow ICMP traffic.</p>
<p>Keeping all other configurations as default, click on <code>Launch instance</code>.</p>
<p>In the diagram, the OpenSwan server is configured as a router and must forward traffic that is not destined for itself. When we configure an instance to act as a router, like the OpenSwan server, we need to disable the <strong>source/destination check</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723458562906/92e3bb90-2c40-47b3-b6c8-34d50143ebf9.png" alt class="image--center mx-auto" /></p>
<p>Disabling source/destination check allows the instance to forward traffic that is not necessarily intended for itself, enabling it to route traffic between other instances.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723458603116/c4a999ce-1f3d-4d23-9a4e-aa23170e3ffa.png" alt /></p>
<p>Since this EC2 is acting as a router, it needs to handle all traffic flowing between instances. Therefore, it must accept traffic from the IP addresses of other instances.</p>
<p>To configure this, we need to update the security group associated with the Openswan server.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723458726413/9467758c-c7d4-4f0a-886d-8e3b2407d237.png" alt /></p>
<p>Click your instance and head to the <strong>Security</strong> tab &amp; click on your Security group.</p>
<p>Edit the inbound rules of the security group for the router instance.</p>
<p>Currently, there are rules for traffic from the AWS side of the network.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723795333774/b0b419b6-ff8d-4fec-bd35-ba4972492e92.png" alt class="image--center mx-auto" /></p>
<p>We need to add TCP and ICMP inbound rules to allow connections from our on-premise network and enable ping functionality for network diagnostics.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723458870269/b8ee1615-586e-4179-b584-e7c4aaf27e3a.png" alt /></p>
<p>Click on <code>Save rules</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723459454381/5c9b26c7-3497-4f92-b752-f8f1cb0b84ad.png" alt /></p>
<p>Let's verify the connectivity by attempting to ping the target instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723459503250/f4fc087b-3e4b-4e54-9648-a8f2c3517582.png" alt /></p>
<p>Ok, so we are able to ping our private instance.</p>
<p>Next, we need to SSH into our private EC2 instance.</p>
<p>On the router instance (Openswan), create a file named as your private EC2 key that you downloaded earlier. e.g., <code>your-key.pem</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723460195537/04128717-fbff-4769-ab93-2c1d67a7140c.png" alt /></p>
<p>Locate your key file in your device and open it using text editor.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723459761351/72c90ea2-222d-483b-b185-3080f351a7da.png" alt /></p>
<p>Copy the content and paste it into the created pem file in your terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723459872674/448b15e2-8c1f-4f8b-b378-be987e49b06e.png" alt /></p>
<p>Save and exit.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723796691695/14e0b8e8-c7cf-4c68-85f4-1d7cf60adcf2.png" alt /></p>
<p>Run the command to ensure your key is not publicly viewable.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723459963792/92cadb6e-8fb1-4b15-917c-da21f71a6bf6.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723796772442/fe55a31e-7d46-4acc-9a7b-1e37937d3d82.png" alt /></p>
<p>We have logged in to our private instance via SSH.</p>
<p>Now we've completed the configuration, but we still need to set up a route for the subnet. We need to specify that traffic from the private subnet should be routed through the EC2 instance acting as a NAT.</p>
<p>To do this, go to the route table for the private subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723460489084/873cd86e-ebed-429d-9077-9bb3404e2070.png" alt /></p>
<p>Edit the routes and add a new route indicating that traffic destined for <code>10.0.0.0/16</code> should be routed through the NAT instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723460566252/de58324f-75b6-424b-8497-186d1aec3bc2.png" alt class="image--center mx-auto" /></p>
<p>Save the updated routes.</p>
<p>Now, finally we have made the connection. Let's ping the AWS-side EC2 instance from on-premise EC2 instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723460666920/4d36d420-a345-43a8-9e47-1b490bda486d.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723460708693/bee61032-ce1a-4f2e-a384-1dcbcf047d5f.png" alt class="image--center mx-auto" /></p>
<p>We can see the traffic has started flowing as expected.</p>
<hr />
<h3 id="heading-conclusion">Conclusion</h3>
<p>We established a VPN connection between our on-premises network and AWS. Our on-premises environment includes a VPC with public and private subnets. An EC2 instance running OpenSwan is located in the public subnet, acting as the Customer Gateway (CGW). The AWS environment consists of a VPC with a private subnet and a private EC2 instance. We successfully configured the VPN tunnel and verified connectivity by pinging the AWS EC2 instance from the on-premises private network.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723818041605/5a8f9260-3bd5-448e-a7a6-3a2d2076e809.png" alt class="image--center mx-auto" /></p>
<p>The successful ping test confirms that the VPN tunnel is operational and traffic can be routed between the on-premises and AWS networks.</p>
<hr />
<h3 id="heading-task-5-clean-up">Task 5: Clean Up</h3>
<p>Let's clean up from on-premise side network.</p>
<ol>
<li><p><strong>Terminating instances.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723461111650/01b89b59-8ada-4bc7-b5a5-96cded58f638.png" alt /></p>
</li>
<li><p><strong>Deleting VPC.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723461203486/e7555016-b7b6-4dd2-a164-3b4d0d765d90.png" alt /></p>
<p> Deleting a VPC will remove all associated resources.</p>
</li>
</ol>
<p>Now, let's clean up resources from our AWS side.</p>
<ol start="3">
<li><p><strong>Terminating instance.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723461388291/f7816c0a-c5a6-4d98-ad96-a61baa36e537.png" alt /></p>
</li>
</ol>
<p>Go to <strong>VPC</strong> dashboard.</p>
<ol start="4">
<li><p><strong>Deleting VPN connection.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723461492634/af3619ac-075e-4910-85ae-df232be875fb.png" alt /></p>
<p> Select &amp; delete your Customer gateway.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723461525823/66f78942-1942-470b-9169-b2e79e6d951c.png" alt /></p>
<p> Detach your Virtual private gateway from your VPC.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723461577529/e790a7b0-2ba6-4d6d-beb0-47f8f537d4ef.png" alt /></p>
<p> Select your Virtual private gateway &amp; click <code>Delete Virtual private gateway</code>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723461457763/99262cc2-cc9d-4ea8-8315-f6fdc58a9394.png" alt /></p>
<p> Now, delete your VPN connection.</p>
</li>
<li><p><strong>Deleting VPC.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723461613891/bd5affed-7418-4237-8f0f-9113a40df979.png" alt /></p>
<p> Select your VPC and click <code>Delete VPC</code>.</p>
</li>
</ol>
<p>Now, we have cleaned up all the resources we used.</p>
<hr />
<p>Alright, I hope that was fruitful blog.</p>
<p>See you in the next one!</p>
]]></content:encoded></item><item><title><![CDATA[Securing API with Cognito User Pool]]></title><description><![CDATA[Hello Everyone,
In this blog, we’ll explore Amazon Cognito, a powerful AWS service for managing user authentication and access control in applications. We’ll also demonstrate how to use Amazon Cognito to secure APIs, ensuring that only authorized use...]]></description><link>https://sujanmagar.com.np/securing-api-with-cognito-user-pool</link><guid isPermaLink="true">https://sujanmagar.com.np/securing-api-with-cognito-user-pool</guid><category><![CDATA[AWS]]></category><category><![CDATA[Amazon Cognito]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Sat, 10 Aug 2024 15:39:53 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1723288967840/d01a0b7d-aa5c-4bda-bb15-5f600143b080.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello Everyone,</p>
<p>In this blog, we’ll explore Amazon Cognito, a powerful AWS service for managing user authentication and access control in applications. We’ll also demonstrate how to use Amazon Cognito to secure APIs, ensuring that only authorized users can access our resources.</p>
<hr />
<p>In this demo, we will secure an API deployed through API Gateway. By default, API Gateway does not provide authorization or security, which means anyone can access our endpoint.</p>
<p>We’ll use a Cognito Identity Pool to create users and configure an API that triggers a Lambda function. After successful sign-in, users will receive a token. API Gateway will validate this token to grant access to the request.</p>
<p>Additionally, we’ll use Postman to test our API. Postman allows us to send requests, configure details like headers, and view responses. It helps ensure that our API is properly secured and functioning as expected.</p>
<hr />
<h3 id="heading-task-1-creating-lambda-function">Task 1: Creating Lambda function</h3>
<p>First, let's set up our backend server, lambda.</p>
<p>Search for <strong>lambda</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723163984958/8a2f224c-5289-44ce-8574-18cdefc20832.png" alt /></p>
<p>Click on <code>Create a function</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723164028826/00e39c6d-ea32-4fa0-9ff9-36f0a15ec846.png" alt /></p>
<p>Provide name for your function and select <strong>Python</strong> as runtime.</p>
<p>Keeping all other configurations as is, click on <code>Create function</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723164159114/6287d816-2b0c-475a-aef8-7690951f133b.png" alt /></p>
<p>We are just returning a simple hello message from lambda.</p>
<p>Click on <code>Deploy</code>.</p>
<p>Now, click on <code>Test</code>. To test our function, we have to provide a test event, for now, just provide the name for test event and click on <code>Save</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723164282773/853addca-c3f4-47e0-ad79-a917083f4d8a.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723164405565/7426055a-7904-4ddc-82d7-d35b832990f2.png" alt /></p>
<p>Now, click on <strong>Test</strong> to see if the function is working as expected. We are getting the hello message.</p>
<p>Alright, that's the first job done.</p>
<hr />
<h3 id="heading-task-2-creating-an-api">Task 2: Creating an API</h3>
<p>We will be creating a simple REST GET API.</p>
<p>Search for <strong>API Gateway</strong> in the search box.</p>
<p>Scroll down to <strong>REST API</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723164561234/e65320a7-752d-4f70-b327-2338a5ded375.png" alt /></p>
<p>Click on <code>Build</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723164613047/18441c34-7bb8-4e80-83b5-afa268183987.png" alt /></p>
<p>Provide a name for your API and click on <code>Create API</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723164679219/bd3ccf4b-fd4d-4d38-97dd-e5ebea0f4c24.png" alt /></p>
<p>Now we are at the root (<code>/</code>) level.</p>
<p>Let's create a method. Click on <code>Create Method</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723164755542/ccc2ca9f-26e7-4dbf-b7c2-277120e12f2a.png" alt /></p>
<p>Configure Method type as <strong>GET</strong>, Integration type as <strong>Lambda function</strong> and select your created lambda function.</p>
<p>Click on <code>Create method</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723170129323/ee7f827a-dea8-402b-9f79-97305462fffc.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Deploy API</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723170162235/1dc22d49-4791-4cb8-9b9b-cd38c05b87f3.png" alt /></p>
<p>Choose New stage and provide a suitable Stage name.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723170206356/488a42ce-1f95-4851-a6ca-ea59078b425f.png" alt /></p>
<p>Select the GET method and copy the invoke URL from your stage section.</p>
<p>Let's head over to the Postman.</p>
<p><a target="_blank" href="https://www.postman.com/"><img src="https://imgs.search.brave.com/6aVW64lywy3pCZ92XZZWT4x2dCJZAfThpPqiODIo7gI/rs:fit:500:0:0:0/g:ce/aHR0cHM6Ly9jb21t/dW5pdHkuY2hvY29s/YXRleS5vcmcvY29u/dGVudC9wYWNrYWdl/aW1hZ2VzL3Bvc3Rt/YW4uMTEuMS4wLnBu/Zw" alt="Icon for package postman" class="image--center mx-auto" /></a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723170309809/1ed33646-d1b2-4100-9f2a-106f9962684a.png" alt class="image--center mx-auto" /></p>
<p>Select <strong>GET</strong> method in Postman, paste the copied URL and click on <code>Send</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723170390248/912c3c12-3550-4433-87fb-4365dd1eb85c.png" alt class="image--center mx-auto" /></p>
<p>We get the response from our lambda function.</p>
<p><strong><em>"Hello from Lambda"</em></strong></p>
<hr />
<h3 id="heading-task-3-creating-user-pool">Task 3: Creating User Pool</h3>
<p>Now, let's create a User Pool.</p>
<p>A <strong>User Pool</strong> is a user directory in Amazon Cognito that helps manage and authenticate users. When users sign up or sign in to your application, they interact with the user pool.</p>
<p>Search for <strong>Amazon Cognito</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723108871872/f856a8fd-52f1-432a-ab50-df063fc81679.png" alt /></p>
<p>Click on <code>Create user pool</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723108944572/c2ed76fc-eec8-48aa-ad0b-2c34f26991d8.png" alt class="image--center mx-auto" /></p>
<p>For sign-in options, select <strong>Email</strong>, then click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723110536606/5d8010d4-1823-4828-a339-8c64f1b55167.png" alt /></p>
<p>For password policy, we can go with defaults, but I made some changes to make easier requirements for password in the Custom mode.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723109851599/bd7e0dec-1506-40f2-8199-66b2a8a4ca54.png" alt /></p>
<p>We decided to go for <strong>No MFA</strong> this time.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723109952288/6a3acd70-554c-4d8b-9770-bdb2297d6631.png" alt class="image--center mx-auto" /></p>
<p>Leave the <strong>Self-service account recovery</strong> option as default.</p>
<p>This option configures how users will recover their account when they forget their password.</p>
<p>Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723110753096/a49476b3-293e-4437-b6df-5ae48604a990.png" alt class="image--center mx-auto" /></p>
<p>Keep the <strong>Self-registration</strong> option as is. This allows new users to register for an account themselves.</p>
<p>Scroll down to bottom, leaving all other configurations as default.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723111188943/03346be7-a230-4d74-b5c7-0cb8e4f684fe.png" alt /></p>
<p>We can choose the attributes that are required when a new user is created.</p>
<p>I added name as additional required attributes. You can select other attributes to add as you like.</p>
<p>Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723111909733/6094abea-6ff1-4fd8-b37c-e1a4f0fd701b.png" alt class="image--center mx-auto" /></p>
<p>Select the <strong>Send email with Cognito</strong> option. The <strong>FROM</strong> email address shows who sent the email, while the <strong>REPLY-TO</strong> address indicates where replies will be sent, which can be different from the <strong>FROM</strong> address.</p>
<p>Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723112807373/ce00e2f5-aa1f-4fad-b32e-1fa0d37ddd47.png" alt /></p>
<p>Provide a suitable name for your User pool.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723112850310/c24fb718-8955-446b-8ee4-d8810c7d91b1.png" alt /></p>
<p>Tick the <strong>Use the Cognito Hosted UI</strong> box. This allows us to use Amazon Cognito's built-in user interface for authentication and sign-up, simplifying the process of integrating user sign-in and sign-up into your application.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723128126723/3e95a815-3ea9-4b9c-a357-1ff8f071501b.png" alt /></p>
<p>Select the Cognito domain. We can use our custom domain, which involves configuring a custom domain name for the Cognito Hosted UI.</p>
<p>Essentially, this is the domain through which users will access the authentication interface for signing in or signing up.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723115682720/390f38d3-a493-442b-8b4b-4acfd92e90a0.png" alt /></p>
<p>Provide a suitable <strong>App client name</strong>. An initial app client in Amazon Cognito is essentially an identity for your application to interact with a user pool.</p>
<p></p><details><summary>App Client</summary><div data-type="detailsContent">An app client in Amazon Cognito represents a specific application's configuration for interacting with a user pool, including settings like OAuth flows, callback URLs, and authentication methods. The term "client" reflects the application's role in consuming the authentication service. Multiple app clients can be linked to the same user pool, each tailored for different applications, allowing them to use the same user credentials while maintaining distinct configurations.</div></details><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723275223772/1f8674c4-d107-42c8-b18e-c6a9ea611c74.png" alt /><p></p>
<p>The client secret helps ensure that the client making requests to the Cognito service is indeed the one that was registered.</p>
<p>We are not generating for now.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723113784501/0c190339-33e6-4f51-a931-4416aa65c81d.png" alt /></p>
<p>We are using <a target="_blank" href="http://example.com"><code>example.com</code></a> as our callback URL for demo purpose.</p>
<p>Callback URLs are the addresses where users are sent after they log in or complete an authentication process. They direct users back to your app with the authentication details.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723128021687/7c8173a8-c080-4d9e-89b9-4b6d25ba29d6.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723132390036/33eb912d-6ee8-4950-b43e-748a7203eb06.png" alt class="image--center mx-auto" /></p>
<p>In the <strong>Advanced client app</strong> settings, we can customize the values as required.</p>
<p>Scroll down to the <strong>OAuth 2.0 grant types</strong> section.</p>
<p>OAuth 2.0 grant types are methods for obtaining access tokens to access protected resources.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723134627879/68c9ec11-d1eb-4207-902b-b33d9267d108.png" alt class="image--center mx-auto" /></p>
<p>Let's explore the workflows briefly.</p>
<p><strong>Authorization Code Grant</strong></p>
<ul>
<li><p>The user logs in via the chosen authorization server (e.g., Amazon Cognito, Google Identity, or another OAuth 2.0 provider).</p>
</li>
<li><p>Authorization Server redirects back with an authorization code.</p>
</li>
<li><p>Your backend exchanges the code for tokens.</p>
</li>
<li><p>Use the tokens to access protected resources</p>
</li>
</ul>
<p><strong>Implicit Grant</strong></p>
<ol>
<li><p>User logs in via the chosen authorization server.</p>
</li>
<li><p>Authorization server redirects back with tokens in the URL.</p>
</li>
<li><p>Use the tokens directly to access resources.</p>
</li>
</ol>
<p>We are using <strong>Implicit Grant</strong> to obtain an access token directly from the authorization server.</p>
<p>Keeping all other configurations as default, click on <code>Next</code>.</p>
<p>Review your selections and click on <code>Create user pool</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723134873692/617b3c96-6089-4546-92a6-3440d57981b8.png" alt /></p>
<p>Our User pool has been created. Click on your created user pool.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723160844079/501b83b4-fb45-4a50-a095-24f0bf51fd6a.png" alt /></p>
<p>Let's create a user in the Users section.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723160950773/31057486-2280-4358-9644-127de41b24c5.png" alt /></p>
<p>Provide email address and set password, then click on <code>Create user</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723161158900/b00bf3f1-de9b-41cf-8dfb-aee1040d76d6.png" alt class="image--center mx-auto" /></p>
<p>A user has been created.</p>
<hr />
<h3 id="heading-task-4-creating-amp-testing-api-gateway-authorizer">Task 4: Creating &amp; testing API Gateway Authorizer</h3>
<p>It's time to add <strong>Authorizers</strong> in API Gateway that will authenticate and authorize requests to our API. This ensures that only users with valid credentials can access our API resources.</p>
<p>Let's go to the API Gateway.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723165014222/2c967172-407a-4cd7-8ba0-a30058829f18.png" alt class="image--center mx-auto" /></p>
<p>In the left panel, in <strong>Authorizers</strong>, click on <code>Create an authorizer</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723166191827/0aa6c08e-cfa6-43e9-b02c-f3d7c4b17967.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable name, select <strong>Cognito</strong> as Authorizer type, select your user pool and provide the header as <strong>Authorization</strong> in the <strong>Token source</strong>.</p>
<p>Click on <code>Create authorizer</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723284370385/5b734f79-0df2-4328-91b3-19ea3e29bd87.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-5-signing-in-and-testing-api-gateway-authorizer">Task 5: Signing in and Testing API Gateway Authorizer</h3>
<p>To test the authorizer, we need a token value, which is obtained after a successful sign-in. Therefore, let's proceed with the sign-in process.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723279373072/3a7255e6-d959-4ce0-a53f-acabede29bd7.png" alt class="image--center mx-auto" /></p>
<p>To view the sign-in page, we have two approaches: a direct link and a customized URL method. The direct link is simpler for basic use cases, while the customized URL method offers flexibility and customization for more complex scenarios and specific needs.</p>
<p><a target="_blank" href="https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-configuring-app-integration.html">Click to get the URL</a></p>
<p>Let's implement the customized URL approach first.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723161389070/8b349f3d-03d4-424a-a882-55e8be977382.png" alt /></p>
<p>There are two different URLs given, one for <strong>authorization code grant</strong> and another for <strong>implicit code grant</strong>.</p>
<p>We are using the second URL.</p>
<pre><code class="lang-xml">
https://your_domain/login?response_type=token&amp;client_id=your_app_client_id&amp;redirect_uri=your_callback_url
</code></pre>
<p>We need to replace <strong><em>your_domain, your_app_client_id</em></strong> &amp; <strong><em>your_callback_url</em></strong> fields with the original values.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723161718428/3d4a83f3-e1a4-402c-b718-983adb6ed54d.png" alt /></p>
<p>In the <strong>App integration</strong> tab, you'll find your domain link in the <strong>Domain</strong> section.</p>
<p>Copy and replace it with <strong><em>your_domain</em></strong> in the URL.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723161871867/9e9831c3-8eae-4897-8e9c-0cfa6a3c5e83.png" alt class="image--center mx-auto" /></p>
<p>In the same section, scroll to the bottom, and we'll find our App client list. Click on your App client.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723161928787/961503de-f090-4fb0-a467-9c6a32b9d0cc.png" alt class="image--center mx-auto" /></p>
<p>Copy your <strong>Client ID</strong> and replace with <strong><em>your_app_client_id</em></strong> in the URL.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723162336584/f0495690-c48e-4124-b137-d73db16981b0.png" alt /></p>
<p>Scroll down a bit, and you'll find your allowed callback URLs that we had provided earlier.</p>
<p>Copy that and paste it into the above URL in <strong><em>your_callback_URL</em></strong>.</p>
<pre><code class="lang-bash"><span class="hljs-comment">#My final URL</span>
https://demodomain1.auth.ap-south-1.amazoncognito.com/login?response_type=token&amp;client_id=6pv54rin409v9ngddqb932lade&amp;redirect_uri=https://example.com
</code></pre>
<p>Copy and paste the complete URL into a new browser tab to access the sign-in page.</p>
<p>Alternatively, we can use a direct link for a more straightforward approach.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723162812929/c35fe1b4-507e-48cb-9fba-773c5808c4ca.png" alt class="image--center mx-auto" /></p>
<p>In your <strong>App client</strong>, in <strong>Hosted UI</strong> section, in the top right corner, we can see <strong>View Hosted UI</strong>.</p>
<p>Click on that button.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723163077453/a643984e-0b7e-45c5-b50c-b36cceaac2a8.png" alt class="image--center mx-auto" /></p>
<p>Sign in with your configured email &amp; password.</p>
<p>We can also create new users using the <strong>Sign up</strong> link, as we have enabled Self-service sign-up option.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723163166649/d11b0131-9866-4f94-b32d-2b7e95132bbd.png" alt class="image--center mx-auto" /></p>
<p>Since this is my first time signing in, I need to set up a new password. Additionally, because I set the name as a required attribute, it also appears on this page.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723163326998/4f57c1b6-7bbb-4899-8e8a-530da2f7036c.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Send</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723163392126/5d7bf7a3-ef47-479e-9bda-15117f97a9ca.png" alt /></p>
<p>Our sign-in was a success, and we're directed to the callback URL that we had set up.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723198632136/b48320e6-f87d-4a8a-a502-85a7a3052686.png" alt /></p>
<p>Notice in the URL, there's a token provided by Cognito. We'll copy this token to test our Authorizer.</p>
<p>Copy the token and paste it into your text editor.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723198706827/f129d9e8-b476-44da-a328-d37f42370f07.png" alt class="image--center mx-auto" /></p>
<p>Only copy the <strong>#id_token</strong> value from the URL.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723198754111/5b7d399d-6780-4fd5-973c-b3bd3c16c9cb.png" alt class="image--center mx-auto" /></p>
<p>Paste the copied token in the Token value section and click on <code>Test authorizer</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723199035859/0077cb61-39f7-41f7-adf9-85a8a0bd8d78.png" alt /></p>
<p>We got this output, and this is what's known as the <strong>decoded JWT claims,</strong> or just <strong>JWT claims</strong>. It's the data returned by the API Gateway authorizer during testing, representing various details about the user contained within the token used for authorization.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723200803784/7b917f7c-7f7c-4033-9dc1-771a9a7a4046.png" alt /></p>
<p>We can pass an invalid token value to observe the response we receive.</p>
<hr />
<h3 id="heading-task-6-adding-authorizer-to-get-method">Task 6: Adding Authorizer to GET Method</h3>
<p>Now in our <strong>GET</strong> method, we have to add the authorization in the method request.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723166435030/c50ae45b-e451-4212-8c10-aae2a0867380.png" alt /></p>
<p>Click on <strong>Method request</strong> &amp; scroll a bit to see the body section.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723166473778/094d2706-0812-49d5-a46e-39cca7a52835.png" alt /></p>
<p>Click on <code>Edit</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723166510534/0e5ca2d2-5a4e-4077-ad2c-ebd1235022ef.png" alt /></p>
<p>Select your authorizer and click on <code>Save</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723171294388/95e55060-2b7d-4377-b0e2-0a4383100352.png" alt class="image--center mx-auto" /></p>
<p>After making the change, redeploy the API by clicking on <code>Deploy API</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723171335373/a39fcc36-9420-4416-8030-bfb12c2c9300.png" alt class="image--center mx-auto" /></p>
<p>After deploying the API, copy the URL and open Postman to test the <strong>GET</strong> request.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723171402500/cdeb6127-96ff-4d3f-a79d-150d8e94b439.png" alt class="image--center mx-auto" /></p>
<p>Paste the URL then click on <code>Send</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723171432249/f220a250-0cd4-4a52-bc8b-220cdba500dd.png" alt class="image--center mx-auto" /></p>
<p>This time, we see an <strong>“Unauthorized”</strong> error.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723173179047/dcb72794-a9a7-45e1-a866-251991f719b4.png" alt class="image--center mx-auto" /></p>
<p>In API Gateway, the authorizer is configured to expect the token in a header field called <strong>Authorization</strong>.</p>
<p>Let's copy our token again.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723198706827/f129d9e8-b476-44da-a328-d37f42370f07.png" alt /></p>
<p>In the Headers section, add <strong>Authorization</strong> as the key and paste the token as the value. Then, click on <code>Send</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723173244840/3963e1c6-4a6b-43f7-b06b-008d76cb2d5d.png" alt class="image--center mx-auto" /></p>
<p>Now that we have provided the token, the authorizer has validated it and granted access to the backend.</p>
<p><em>Note that if your token is not working, it may have expired. In this case, you will need to sign in again to obtain a new token.</em></p>
<hr />
<h3 id="heading-task-7-conclusion">Task 7: Conclusion</h3>
<p>In this blog, we secured an API with Amazon Cognito and API Gateway. We set up a Lambda function, deployed a REST API, configured a Cognito User Pool, and used API Gateway Authorizers. Finally, we tested the setup with Postman.</p>
<hr />
<h3 id="heading-task-8-clean-up">Task 8: Clean Up</h3>
<ol>
<li><p><strong>Deleting API.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723282518936/13932348-6e90-4ddc-a58e-e229458306b9.png" alt /></p>
<p> Select your API and click on Delete to delete your API.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723282582649/3a5ef08d-5ab6-4280-9379-5c586aabd870.png" alt /></p>
</li>
<li><p><strong>Deleting Lambda function.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723282640203/7460a2bd-81c1-4be4-8763-383e7b29d755.png" alt class="image--center mx-auto" /></p>
<p> Select your lambda function and in the <strong>Actions</strong> drop-down menu, click on <code>Delete</code>.</p>
</li>
<li><p><strong>Deleting User Pool.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723282758459/d668699a-b468-46a3-9651-c2201d04f7de.png" alt /></p>
<p> Select your User pool and click on <code>Delete</code>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723283109802/c650c99d-c902-44dc-ba7f-da8139d48589.png" alt /></p>
</li>
</ol>
<hr />
<p>Alright, that sums up our today's work.</p>
<p>See you later in the next one!</p>
]]></content:encoded></item><item><title><![CDATA[Project: Static website hosting on S3]]></title><description><![CDATA[Today, we will be creating a static website and host it in an S3 bucket.
Overview
We will use an S3 bucket to store our website files, CloudFront for content distribution & issue a certificate from AWS ACM for security. Finally, we will make updates ...]]></description><link>https://sujanmagar.com.np/project-static-website-hosting-on-s3</link><guid isPermaLink="true">https://sujanmagar.com.np/project-static-website-hosting-on-s3</guid><category><![CDATA[AWS]]></category><category><![CDATA[#aws projects]]></category><category><![CDATA[Static Website]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Sun, 23 Jun 2024 11:59:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1719143896374/8a66e0fa-bd05-4263-8080-5416812b8bdc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today, we will be creating a static website and host it in an S3 bucket.</p>
<h3 id="heading-overview">Overview</h3>
<p>We will use an S3 bucket to store our website files, CloudFront for content distribution &amp; issue a certificate from AWS ACM for security. Finally, we will make updates in DNS records to access our static site with custom domain name.</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<p>To complete this tutorial, we need a registered domain name. Amazon Route 53 (R53) provides domain registration and DNS management services, but we can choose separate providers like GoDaddy, Namecheap, or Google Domains for these services if desired.</p>
<p>I am expecting you already have your custom domain name before proceeding.</p>
<hr />
<h3 id="heading-task-1-creating-an-s3-bucket">Task 1: Creating an S3 bucket</h3>
<p>Search for <strong>S3</strong> in the search box.</p>
<p>Click on <code>Create bucket</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718873050042/4e59f75a-f1f1-4c20-be8f-b1551c75da88.png" alt /></p>
<p>Your bucket name should match the domain name exactly. For example, I'll be using <strong>"sujanmagar.com.np"</strong> so my bucket name needs to be <strong>"sujanmagar.com.np"</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718960480066/972dcad2-cb99-47af-8548-74f4a47b180d.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718873098590/5f815c5a-3db4-4bd1-a7d4-9d18379139aa.png" alt /></p>
<p>Scroll down and deselect the setting for "<strong>Block <em>all</em> public access</strong>". This is usually not recommended, but since we're creating a static website hosting, it required to disable this setting.</p>
<p>Tick on the acknowledgment box.</p>
<p>Use the defaults for the rest of the bucket settings and then click on <code>Create bucket</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718873303490/f01ce1fa-60db-4d58-ad27-1718b6d57d4b.png" alt /></p>
<p>Click on your bucket and on <strong>Properties tab</strong>, scroll down to <strong>Static website hosting</strong> section.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718873343432/d5e4ec79-b59c-477f-a00e-961e487e2935.png" alt /></p>
<p>Click on <code>Edit</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718873422847/8579111d-53d2-435b-8800-715695535fe2.png" alt /></p>
<p>Enable the Static website hosting and input <strong>index.html</strong> in the Index document field. This specifies the default home page for our site.</p>
<p>Leaving all other configurations as default, click on <code>Save changes</code>.</p>
<p>When we created the bucket, we said we didn't want to <strong>block all public access</strong>. But even with that setting, the default behavior of S3 is to <strong>"deny"</strong> everything. So if we don't explicitly say that people can access the files in our bucket, they won't be able to so, we'll grant read permissions with a bucket policy.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718873792210/512ef923-f0ca-46cb-ac0c-6826b86f2428.png" alt /></p>
<p>On <strong>Permissions tab</strong>, on <strong>Bucket policy</strong> section, click on <code>Edit</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718874130979/6ca29b1a-5305-4dc5-b5d1-cbb5f1d09355.png" alt /></p>
<p>Paste the following bucket policy in the Policy section.</p>
<pre><code class="lang-yaml">{
    <span class="hljs-attr">"Version":</span> <span class="hljs-string">"2012-10-17"</span>,
    <span class="hljs-attr">"Statement":</span> [
        {
            <span class="hljs-attr">"Sid":</span> <span class="hljs-string">"PublicReadGetObject"</span>,
            <span class="hljs-attr">"Effect":</span> <span class="hljs-string">"Allow"</span>,
            <span class="hljs-attr">"Principal":</span> <span class="hljs-string">"*"</span>,
            <span class="hljs-attr">"Action":</span> [
                <span class="hljs-string">"s3:GetObject"</span>
            ],
            <span class="hljs-attr">"Resource":</span> [
                <span class="hljs-string">"arn:aws:s3:::Bucket-Name/*"</span><span class="hljs-comment">#make sure to add your bucket name</span>
            ]
        }
    ]
}
</code></pre>
<p>Make sure to update the Bucket-Name with your own.</p>
<p>Click on <code>Save changes</code>.</p>
<p>Now, it's time to upload our files.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718874242066/1ddc1a7b-5815-430e-9c6f-d2984d97d008.png" alt /></p>
<p>On <strong>Objects</strong> tab, click on <code>Upload</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718874308651/35e4daf3-7b9d-437d-bb54-fa94214cec6a.png" alt /></p>
<p>Click on <code>Add files</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718874425641/8df2440d-70de-499b-b1a5-b048fe9d2171.png" alt /></p>
<p>Select your files and click on <code>Upload</code>. You can create your static files that will make up your static website, or you can use mine.</p>
<p><a target="_blank" href="https://github.com/thapasujan07/s3-static-site-files.git">My files for static website</a></p>
<p>Now it's time to test that our site loads. To do this, we'll need to get the S3 bucket website endpoint.</p>
<p>Head to the <strong>Properties</strong> tab of the bucket &amp; scroll down to the <strong>Static website hosting section</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718874541554/b4b7bc40-9231-4bd5-8fbe-f8a2414554d7.png" alt /></p>
<p>Click on the Bucket website endpoint link.</p>
<p>If everything worked, you should be able to load your static website.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718887011803/374be465-61d0-41df-bb54-12057c656677.png" alt class="image--center mx-auto" /></p>
<p>We have hosted our site in S3 with public access. But as impressive as it is, it would be even more impressive if it were using a custom domain. Currently, it is using the S3 website URL, formatted as <strong>[bucketname].s3website[regionname].amazonaws.com.</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718887070221/709043c6-352c-44dd-95f9-4dfa3dd926ef.png" alt /></p>
<hr />
<h3 id="heading-task-2-creating-a-record-to-point-to-the-s3-website">Task 2: Creating a record to point to the S3 website</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718875384713/59089fb1-710d-470d-adaa-bb871a788922.png" alt class="image--center mx-auto" /></p>
<p>To create a DNS record, we need to be working within our <strong>DNS zone</strong>, which in my case is managed by <strong>Cloudflare</strong>. You might have your zone hosted with other providers like <strong>Amazon Route 53 (R53)</strong> or other DNS management services.</p>
<p>Click on <code>Add record</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718954587924/537474ea-339c-476a-bbbf-9b0c87413ec8.png" alt /></p>
<p>Copy the Bucket website endpoint and remove the protocol from the endpoint, &amp; paste it in the Target field.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718876797292/7d6b921e-3ce0-4bb4-80f3-2108579c96d8.png" alt /></p>
<p>In Amazon Route 53, we have the alias option to point our domain to AWS resources. However, since I'm using Cloudflare, which doesn't have an alias option, I am using a CNAME record type to achieve the similar functionality. Cloudflare automatically enables CNAME flattening for the root domain, allowing it to point to another domain name. This is typically not allowed by DNS standards, but Cloudflare makes it possible.</p>
<p>Click on <code>Save</code>.</p>
<p>Now let's test!  If everything worked, then when you type your domain name into a browser (like sujanmagar.com.np), DNS provider should direct you to the S3 website.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718955808130/08a67f12-22ac-43f3-aa7f-5c97098fed07.png" alt class="image--center mx-auto" /></p>
<p>Alright, the last step is to set up a secure connection (HTTPS with a TLS/SSL certificate) to eliminate the "<strong>Not secure</strong>" message from our browser.</p>
<hr />
<h3 id="heading-task-3-creating-a-public-tlsssl-certificate">Task 3: Creating a Public TLS/SSL Certificate</h3>
<p><a target="_blank" href="https://www.amberisraelsen.com/"><img src="https://www.freecodecamp.org/news/content/images/2023/11/Certificates.png" alt="Certificates" /></a></p>
<details><summary>TLS/SSL Certificate Security</summary><div data-type="detailsContent">We need a public TLS/SSL certificate to secure our website. It encrypts data between users and our server, protecting sensitive information. It also verifies our website's authenticity, removing the <strong>"Not secure"</strong> warning in browsers, building user trust, and improving our site's credibility.</div></details>

<p>In AWS, certificates are handled through AWS Certificate Manager (ACM), where you can create and manage certificates. ACM also allows you to import certificates from another authority if you already have them.</p>
<p>In your AWS console, search for <strong>Certificate Manager</strong> in the search box.</p>
<p>For this section, you need to switch your region to <strong>us-east-1 (N. Virginia)</strong>.</p>
<details><summary>ACM Certificates: Regional vs. Global Usage with CloudFront</summary><div data-type="detailsContent">When you create a certificate in ACM, it is stored in the region where you created it. This means that if you create a certificate in the <code>us-west-2</code> region, that certificate is only available for use within services in the <code>us-west-2</code> region. However, CloudFront's integration with ACM allows it to use certificates from the <code>us-east-1</code> region for distribution globally. This integration is a special case and does not follow the typical region-specific behavior of ACM certificates.</div></details><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719136451207/adcf7b37-48c9-4c71-b7f2-4feaf6f99bdd.png" alt class="image--center mx-auto" />

Click on <code>Request a certificate</code>.

<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718878134611/781fb520-582f-448e-974f-ee0c3a102bfa.png" alt />

Click on <code>Next</code>.

<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718955960325/46a3a969-548c-46f6-b3f4-b8aa1e01efda.png" alt />

Enter your domain name &amp; leave the rest of the options as defaults, then click on <code>Request</code>.

<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718878198583/da98151c-317e-4841-88fa-9d3cab7b7b6c.png" alt />

<details><summary>Validation methods</summary><div data-type="detailsContent">When setting up a new SSL certificate, you must prove ownership of the domain. This is done through two main methods: DNS validation, where you add a specific record to your domain's DNS settings, and Email validation, where a confirmation email is sent to a predefined email address associated with the domain.</div></details>

<p>For now, we choose the DNS validation method.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718956136974/1cd4621b-74bc-4c5d-abe5-57cda3634f60.png" alt /></p>
<p>The request was successful, but it will have a "<strong>Pending validation</strong>" status until we validate DNS.</p>
<p>Click on <code>View certificate</code>.</p>
<p>While DNS validation is straightforward with Route 53, using Cloudflare as my DNS provider requires some manual steps to validate domain ownership when issuing an ACM certificate. With Cloudflare, I need to add a specific DNS record provided by ACM to my DNS settings to complete the validation process.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718956160994/fdde72a6-0f0d-4820-abd4-01d51934f6c0.png" alt class="image--center mx-auto" /></p>
<p>Copy the CNAME name and value, then add a new CNAME record in DNS provider's DNS records.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718956212665/5e53bf13-574f-4bcc-ab13-29b7995f8840.png" alt /></p>
<p>Click on <code>Save</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718956265834/21a8ad5a-60c9-4647-afa2-1f14caabf9a1.png" alt /></p>
<p>We have a TLS/SSL certificate now and our website files are hosted in S3, but we can't use a certificate on an S3 bucket.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718978386108/e0733f5b-7509-4462-a11e-22695ef19ae1.png" alt class="image--center mx-auto" /></p>
<p>What we need instead is a CloudFront distribution that points to the S3 bucket. And then the certificate is applied to the CloudFront distribution.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718978271357/eb1ddf47-ce45-4af4-9103-97e8a4d214b6.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-4-create-a-cloudfront-distribution">Task 4: Create a CloudFront Distribution</h3>
<p>Amazon's content delivery network (CDN), CloudFront, speeds up content delivery by caching it at various <strong>“Edge locations”</strong> globally. This setup is particularly effective for accelerating the load times of videos and images.</p>
<p>For a simple site with few files like ours, the performance boost might not be very noticeable. However, using CloudFront is essential for applying the TLS/SSL certificate that we created in the previous task.</p>
<p>Search for <strong>CloudFront</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718879305561/95e53a86-4c32-4b38-b48c-846a398a9714.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Create a CloudFront distribution</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718879420301/f37c8155-ef41-4bd5-897d-8264cf16dc86.png" alt /></p>
<p>The origin domain is where our website files are stored, which is in S3. If you filter by typing in S3, it will show our bucket.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718879466444/66f25084-a7d5-4e04-ad90-9b1d6e6deece.png" alt class="image--center mx-auto" /></p>
<p>However, we'll get a message about using the website endpoint instead of the bucket endpoint. Click on <code>Use website endpoint</code> and AWS will update the endpoint for us.</p>
<p>Scroll down to the <strong>Default cache behavior section</strong>, then under <strong>Viewer</strong>, select <strong>Redirect HTTP to HTTPS</strong>. This will help ensure that all traffic to our website is encrypted, enhancing security and protecting user data.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718879516915/6efd65d4-798a-4e14-a470-e14bed165f88.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718879616903/1787ab4d-9a2c-4e13-b5fc-b8d5e62624b5.png" alt class="image--center mx-auto" /></p>
<p>Scroll down to <strong>Web Application Firewall (WAF)</strong> and select <strong>Do not enable security protections</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718879788382/11c71b9e-0e4b-484a-b852-60f6b6784e28.png" alt /></p>
<p>In the next section, <strong>Settings</strong>, click on <code>Add item</code>.</p>
<p>Provide your domain name there and select your certificate in <strong>Custom SSL certificate</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718880049302/4a3077c0-b949-467a-b63d-0835d95d3aa8.png" alt /></p>
<p>Scroll to the bottom of the page.</p>
<p>For <strong>Default root object</strong>, enter <strong>index.html</strong> (our default home page) and then click on <code>Create distribution</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718880239577/03f8e865-c2a7-45b5-9a9e-c6b5ae7ffc1c.png" alt /></p>
<p>It will take several minutes for the CloudFront distribution to finish deploying.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718956439867/56b86139-b349-4aaf-b1fe-4327ef6a059d.png" alt class="image--center mx-auto" /></p>
<p>To test that everything is working with CloudFront and the TLS/SSL certificate, copy the <strong>Distribution domain name</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718956587397/f2ed7017-d08a-4927-9434-e05e77a3515c.png" alt class="image--center mx-auto" /></p>
<p>Open a new tab in the browser and navigate to that address.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718956617696/db224321-fd9b-4651-8bd6-5195dea71bff.png" alt class="image--center mx-auto" /></p>
<p>Now, the last thing is to use our custom domain name to load the site instead of this lengthy CloudFront distribution domain name.</p>
<hr />
<h3 id="heading-task-5-updating-dns-record">Task 5: Updating DNS Record</h3>
<p>At the moment, the CNAME Record in Cloudflare is pointing to the S3 bucket.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719134619177/cbba37ee-5162-4766-8561-0d9ec8a2bbe5.png" alt class="image--center mx-auto" /></p>
<p>Instead, we want Cloudflare to point to the CloudFront distribution, which then points to S3.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719134785267/2dda37d4-70e5-49c5-8e2c-445d8f2bcfbe.png" alt class="image--center mx-auto" /></p>
<p>Navigate back to your DNS Records settings.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718956677830/bf86f926-4fce-4e03-8407-e74b39f11284.png" alt class="image--center mx-auto" /></p>
<p>Instead of routing traffic to S3, update the DNS record to point to your CloudFront distribution.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718880915481/b18b9fe6-b97c-48b6-9fed-55589deb6744.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Save</code>.</p>
<hr />
<h3 id="heading-task-6-the-final-show">Task 6: The Final Show</h3>
<p>Alright! Type your custom domain name in the new tab in your browser and hit the <code>ENTER</code> button.</p>
<p>If everything worked, we should be able to load our static website without our own custom domain name on a secure connection.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718956859194/60f1e4a6-219c-4a85-ab64-14c2a308ea1d.png" alt class="image--center mx-auto" /></p>
<p>Aha! It worked.</p>
<p>The static files (coming from S3 via CloudFront) load on the custom domain name (from Cloudflare) over a secure connection using the TLS/SSL certificate (from Certificate Manager).</p>
<hr />
<h3 id="heading-conclusion">Conclusion</h3>
<p>We utilized an S3 bucket for storing our website files &amp; leveraged CloudFront for efficient content distribution. We secured our site with a certificate from AWS ACM, and updated DNS records to enable access through our custom domain, making a scalable, secure, and performant static website on AWS.</p>
<p>Here's what we've built:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719135801936/b5c94026-e9cf-464e-9611-f0e4dfdb1056.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-7-clean-up">Task 7: Clean Up</h3>
<ol>
<li><p><strong>Deleting CloudFront distribution.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718956933595/8197e252-1652-438e-84b0-851500751424.png" alt class="image--center mx-auto" /></p>
<p> Before deleting our Distribution, we have to <code>Disable</code> it.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718956960100/b22c280c-572b-48b9-9bcc-0a1262d8f8c1.png" alt class="image--center mx-auto" /></p>
<p> It'll take a couple of minutes even after being disabled to be able to finally delete.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718957218180/7e0937dc-730d-4c78-acf4-c2ed270f84d8.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Deleting records from DNS Records.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718957110433/c9ad7501-f974-4eb9-ad06-ab789cbe694e.png" alt class="image--center mx-auto" /></p>
<p> Navigate to your DNS Records settings and delete the created records.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718957141866/b43bd93a-9017-4ff3-8306-1784277d2c78.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Delete the certificate from Certificate Manager.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718957186672/fad015be-cbec-4efb-8263-3fb400b68cb9.png" alt class="image--center mx-auto" /></p>
<p> Navigate to <strong>Certificate Manager</strong>. Select your certificate and then click on <code>Delete</code>.</p>
</li>
<li><p><strong>Deleting S3 bucket.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718882210456/b75670ef-cefe-4906-aed8-51bfa4af5044.png" alt class="image--center mx-auto" /></p>
<p> Navigate to your bucket and then empty your bucket, deleting all the files contained.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718957357513/2ef9d533-1942-4210-951b-cda96e8362f0.png" alt /></p>
<p> After you've deleted all the contents, select your bucket and click on <code>Delete</code>.</p>
</li>
</ol>
<p>Now we have deleted all the resources that we used during the lab session.</p>
<hr />
<p>Alright, that was it for this project.</p>
<p>See you in the next one!</p>
]]></content:encoded></item><item><title><![CDATA[VPC Endpoints]]></title><description><![CDATA[Today, we will be learning about VPC Endpoints.
VPC Endpoints
VPC endpoints are a way to privately connect your VPC to supported AWS services and VPC endpoint services without requiring an internet gateway, NAT device, VPN, or Direct Connect connecti...]]></description><link>https://sujanmagar.com.np/vpc-endpoints</link><guid isPermaLink="true">https://sujanmagar.com.np/vpc-endpoints</guid><category><![CDATA[AWS]]></category><category><![CDATA[VPC Endpoints]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Fri, 14 Jun 2024 10:50:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1718361442186/2110cb19-2832-4c44-8a55-7c0d62a3b9f6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today, we will be learning about VPC Endpoints.</p>
<h3 id="heading-vpc-endpoints">VPC Endpoints</h3>
<p>VPC endpoints are <strong>a way to privately connect your VPC to supported AWS services and VPC endpoint services</strong> without requiring an internet gateway, NAT device, VPN, or Direct Connect connection. They allow you to connect to these services using private IP addresses, which keeps your traffic within the AWS network.</p>
<p>There are two types of VPC endpoints:</p>
<ol>
<li><p><strong>Interface Endpoints</strong>: These are powered by AWS PrivateLink and are used for connecting to services like S3, DynamoDB. They provide a private IP address in your VPC. When you create an interface endpoint, an Elastic Network Interface (ENI) is created in your subnet with a private IP address that serves as the entry point for traffic destined to the service.</p>
</li>
<li><p><strong>Gateway Endpoints</strong>: These are used for connecting to S3 and DynamoDB and are simpler to set up than interface endpoints. Gateway endpoints are associated with your route table and use route tables to direct traffic to the endpoint.</p>
</li>
</ol>
<hr />
<h3 id="heading-overview">Overview</h3>
<p>We will set up a VPC with two subnets: one public and one private. Each subnet will have one instance. We will attach a role to the private instance to allow it to list the available S3 buckets. This will be done utilizing the Gateway Endpoint which establishes a private connection within our VPC to access S3, eliminating the need for an internet gateway.</p>
<hr />
<h3 id="heading-task-1-creating-a-vpc">Task 1: Creating a VPC</h3>
<p>Search for <strong>VPC</strong> in the search box.</p>
<p>Click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718275236554/381ff049-59bd-4f76-9c9a-a161a8ff1eba.png" alt /></p>
<p>Provide a name for your VPC and input a CIDR range.</p>
<p>Click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718358456677/9090fb5b-fac5-41ab-8705-1950134aedee.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-2-creating-an-internet-gateway">Task 2: Creating an Internet Gateway</h3>
<p>On <strong>Internet gateways</strong>, click on <code>Create internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718289173594/d0716e80-3fd1-46f8-a588-382d2b770063.png" alt /></p>
<p>Provide a suitable name and click on <code>Create internet gateway</code>.</p>
<p>After creating an Internet gateway, attach it to your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718358529060/2570159d-4a75-4807-af8d-4da48addb0ac.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-3-creating-subnets">Task 3: Creating Subnets</h3>
<p>On <strong>Subnets</strong>, click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718275316282/ed97305e-b8bf-405b-aae0-320c42400d32.png" alt class="image--center mx-auto" /></p>
<p>We are going to create two subnets: one public and one private.</p>
<p>Select your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718286107613/c698c3f8-61d7-4c74-bffc-03956725a15d.png" alt /></p>
<p>Provide a suitable name for your subnet, choose an AZ and input an eligible CIDR range value.</p>
<p>Click on <code>Add new subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718286192712/181df224-a862-4464-980b-b4f5dd34a3d7.png" alt /></p>
<p>Provide a suitable name and CIDR range.</p>
<p>Click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718358687132/8923bdfc-bddf-4416-b417-a0249b7fc553.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-4-creating-route-table">Task 4: Creating Route table</h3>
<p>On <strong>Route tables</strong>, click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718275513777/9105256f-bef2-4322-9ec1-764d0a95338f.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718286258718/863a0a91-5154-48b8-8ded-32b8d974b78b.png" alt /></p>
<p>Provide a suitable name for your route table, select your VPC and click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718286341371/2856efe7-8e98-4940-ba4b-e88507d3482d.png" alt /></p>
<p>On <strong>Subnet associations</strong>, click on <code>Edit subnet associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718286379779/a442ebdc-b93a-4fb6-b630-dbc004200302.png" alt class="image--center mx-auto" /></p>
<p>Tick your public subnet and click on <code>Save associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718289867853/36d1b6a6-ddb8-4915-aabb-89634c81855d.png" alt /></p>
<p>Now on <strong>Routes</strong>, click on <code>Edit routes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718289898816/1666c56d-316c-42c0-98b9-ec92769785ce.png" alt class="image--center mx-auto" /></p>
<p>Configure a route to Internet gateway and click on <code>Save changes</code>.</p>
<p>Now it's time to create another route table &amp; associate private subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718286429558/8290a738-7419-428d-9af1-cd1b3ec9f69d.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718286453378/3f3760c7-0236-4ca7-b2e3-a9e5e129aaa6.png" alt class="image--center mx-auto" /></p>
<p>We should not include an Internet Gateway route in the private route table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718286533113/1cd2b2af-6ec3-4464-a26e-a9f68115489f.png" alt class="image--center mx-auto" /></p>
<p>We have created two route tables.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718358861054/590a0e19-7c1f-4426-96c2-9e427d3aadc9.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-5-creating-a-role">Task 5: Creating a Role</h3>
<p>Search for <code>IAM</code> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718278111705/8e6e0393-d77d-427a-b026-986202182dd5.png" alt /></p>
<p>On <strong>Roles</strong>, click on <code>Create role</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718278151242/3ef55e03-5cc6-4e27-844d-4f4164346743.png" alt /></p>
<p>Select <strong>AWS Service</strong> as the trusted entity type and <strong>EC2</strong> for the use case.</p>
<p>By choosing AWS Service as the trusted entity type, we specify that this role is intended for use by an AWS service, in this case, EC2. This allows EC2 instances to assume this role and inherit the permissions defined in the role's policy.</p>
<p>Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718278482411/d6d06e64-75f0-4845-89b2-9831369cf003.png" alt /></p>
<p>We are attaching S3 read only permission to our instance.</p>
<p>Click on <strong>'+'</strong> sign to expand the policy.</p>
<p>Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718278566812/aa2a9d2e-9c78-4ab9-ae2c-ceda800d1518.png" alt /></p>
<p>Provide a suitable name for your role and review your created role.</p>
<p>Click on <code>Create role</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718278652799/fc5f37d4-ca1f-4e7c-ba5e-3d2e6184dfd4.png" alt class="image--center mx-auto" /></p>
<p>We have created a role.</p>
<hr />
<h3 id="heading-task-6-creating-ec2-instance">Task 6: Creating EC2 instance.</h3>
<p>Search for <strong>EC2</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718278732264/f15264f6-f534-47ed-9d09-59ccc6355cbc.png" alt /></p>
<p>On <strong>Instances</strong>, click on <code>Launch instances</code>.</p>
<p>Provide a name for your instance, select an Amazon Linux AMI (<strong>mandatory</strong>) and a free-tier instance if possible. Either use existing or create a new key pair.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718293117409/13579491-69cc-40cd-90ab-0c6c13a15395.png" alt /></p>
<p>Edit Network settings. Select your VPC and your subnet.</p>
<p>Leaving all other configurations as default, click on <code>Launch instance</code>.</p>
<p>Now, let's create a private instance.</p>
<p>Provide a name for your instance, select an Amazon Linux AMI and a free-tier instance if possible. Either use existing or create a new key pair.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718293230293/4adc91b1-8d73-4cad-98ad-a5446e3b1556.png" alt /></p>
<p>Select your VPC, choose private subnet and keep other as default.</p>
<p>Leaving all other configurations as default, scroll to the bottom <strong>Advanced Details</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718279086946/22f7743a-8979-48d2-9577-87a69a7a634c.png" alt /></p>
<p>On <strong>IAM instance profile</strong>, select your created role.</p>
<p>Now, keeping all other settings as default, click on <code>Launch instance</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718293301560/7f2378fa-9d91-4b3c-9466-0984b1b49b04.png" alt class="image--center mx-auto" /></p>
<p>We have created two EC2 instances.</p>
<p>diagram..</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718359055537/1540dc65-de56-45a3-ac93-f38d77673d1f.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-7-creating-s3-buckets">Task 7: Creating s3 buckets.</h3>
<p>Search for <strong>s3</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718279529504/35c8b250-730c-49d6-9ff6-3efd1993e2dd.png" alt /></p>
<p>On <strong>Buckets</strong>, click on <code>Create bucket</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718279642904/e6d41eca-02fd-420b-b769-ccd1cd055229.png" alt /></p>
<p>Just provide a name for your bucket and leaving all other configurations as it is, click on <code>Create bucket</code>.</p>
<p>Let's create another bucket as well.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718279730961/bf28965b-8762-4e35-affb-d8319996bc34.png" alt /></p>
<p>So, we have created two buckets.</p>
<hr />
<h3 id="heading-task-8-accessing-ec2s">Task 8: Accessing EC2s</h3>
<p>We need to copy the private key required to SSH into the private server from our public server first.</p>
<p>Open your local terminal.</p>
<p>Modify the code below to suit your needs.</p>
<pre><code class="lang-bash">scp -i <span class="hljs-string">"publicServerKey.pem"</span> <span class="hljs-string">"privateServerKey.pem"</span> ec2-user@13.233.225.53:/home/ec2-user
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718293674304/a48822e7-da2f-4702-8991-b258a4deebf1.png" alt class="image--center mx-auto" /></p>
<p>This command copies the file <code>privateServerKey.pem</code> from our local machine to the <code>/home/ec2-user</code> directory on the remote server with IP address <code>13.233.225.53</code> using the SSH key specified by <code>publicServerKey.pem</code>.</p>
<p>Now, let's SSH into our public instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718293771481/11f3e83c-798e-4a29-b9d4-fd6483b4492a.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718293830355/0ef5a992-1b0b-44f8-b9bb-e97b5b791994.png" alt /></p>
<p>We have securely copied the key to our public instance, which will be used to SSH into our private instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718293891290/f2a2ce52-9e7c-4571-a674-474a0e78b767.png" alt /></p>
<p>Copy &amp; paste the command in your public instance's terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718293913040/1dc3498c-2603-47cb-b4b4-74e255607be0.png" alt /></p>
<p>Now, copy the SSH command to establish a connection to the private instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718293995426/c0eab9a8-5e05-4348-b5de-de05bfad0bcb.png" alt class="image--center mx-auto" /></p>
<p>Proceed with yes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718294031609/3e6b64d5-5d6c-4487-80d0-d43bbaa9e100.png" alt class="image--center mx-auto" /></p>
<p>We are now connected to our private instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718294082161/b389e18d-837b-4d3a-b269-32e2538b84b1.png" alt /></p>
<p>Even though we have attached the role that allows an EC2 instance to list S3 buckets, we are unable to do so due to a lack of connection. This is where we set up a VPC endpoint.</p>
<hr />
<h3 id="heading-task-9-creating-a-vpc-endpoint">Task 9: Creating a VPC endpoint.</h3>
<p>Go to the <strong>VPC dashboard</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718294235172/f012327e-55e4-457e-b8bb-4245eb55f848.png" alt /></p>
<p>On <strong>Endpoints</strong>, click on <code>Create endpoint</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718294302505/ee8c2a4a-cb68-46cf-a5ea-7c82f570a46a.png" alt /></p>
<p>Provide a name for your endpoint.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718294689173/c1f54ae7-c6a1-47a8-8099-603b1e64aeee.png" alt /></p>
<p>In the services, look for <strong>S3</strong> and select it. This VPC endpoint will be used to access S3, indicating that the services it will be consuming or using are related to S3.</p>
<p>Choose the service name <code>com.amazonaws.&lt;your-region&gt;.s3</code> to create the VPC endpoint for standard Amazon S3 in the <code>&lt;your-region&gt;</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718294756390/3f8a9f71-8ffb-4712-b4a4-0c32fda55981.png" alt /></p>
<p>Select the Gateway type &amp; select your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718294994801/6b6058c9-0573-47ef-96aa-e46de1c382af.png" alt /></p>
<p>Select only your private route table, as we're allowing EC2 instance in the private subnet to perform actions on S3 buckets using the endpoint.</p>
<p>Click on <code>Create endpoint</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718295192440/d9c5abeb-b29e-434e-ad1c-60ff9d65bed8.png" alt class="image--center mx-auto" /></p>
<p>Now that we've created our VPC Endpoint, let's return to our EC2 terminal and run the same command to see if it's working.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718295266175/957ca9c6-3472-4237-98fc-dfece16d952f.png" alt /></p>
<p>We can now list the S3 buckets, demonstrating that a private instance within our VPC can securely communicate with other AWS services.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718361792287/df1f9afa-9964-4265-a21b-77834e1a0b1b.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-conclusion">Conclusion</h3>
<p>By attaching a role to the private instance and utilizing the Gateway Endpoint, we have enabled it to perform operations on S3 buckets securely. This setup establishes a private connection from our VPC to S3, allowing communication to occur without the need for an internet gateway.</p>
<hr />
<h3 id="heading-task-10-clean-up">Task 10: Clean Up</h3>
<ol>
<li><p><strong>Terminating EC2 instances</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718295557381/d2d812bb-e0f1-4765-9751-e7b87b8cf5b7.png" alt class="image--center mx-auto" /></p>
<p> Select both of your instances and on <strong>Instance state,</strong> click on <code>Terminate instance</code>.</p>
</li>
<li><p><strong>Deleting VPC Endpoint</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718295622016/f541b289-5288-407e-8696-ea801173e529.png" alt /></p>
<p> Select your Endpoint and in the <strong>Actions</strong> panel, click on <code>Delete VPC endpoints</code>.</p>
</li>
<li><p><strong>Deleting subnets.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718295735883/5cc94a7e-8446-4e72-b48c-880ff58572ad.png" alt /></p>
<p> Select both of your subnets and in the <strong>Actions</strong> panel, click on <code>Delete subnet</code>. Refresh the page if you are not able to delete.</p>
</li>
<li><p><strong>Deleting VPC.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718295813365/51dcb3a5-846a-4422-8460-d519906b3fa3.png" alt /></p>
<p> Select your VPC and in the <strong>Actions</strong> panel, click on <code>Delete VPC</code>.</p>
</li>
<li><p><strong>Deleting s3 buckets.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718295892686/c12ed6e0-db7e-409b-9b29-80dd09478a79.png" alt class="image--center mx-auto" /></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718295933358/676fa7a9-5c42-4e11-919e-84ab0ca789b0.png" alt class="image--center mx-auto" /></p>
<p> Select your bucket and click on <code>Delete</code> button.</p>
</li>
</ol>
<p>We have cleaned up our used resources.</p>
<hr />
<p>That was it for today.</p>
<p>I'll see you in the next one!</p>
]]></content:encoded></item><item><title><![CDATA[AWS Command Line Interface (CLI)]]></title><description><![CDATA[AWS Command Line Interface
Today we will be setting up our AWS CLI.
AWS CLI is a tool that lets us manage AWS services from the command line. With AWS CLI, we can control various AWS services and automate tasks through scripts.
To use AWS CLI, we nee...]]></description><link>https://sujanmagar.com.np/aws-command-line-interface-cli</link><guid isPermaLink="true">https://sujanmagar.com.np/aws-command-line-interface-cli</guid><category><![CDATA[AWS]]></category><category><![CDATA[aws cli]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Thu, 13 Jun 2024 08:28:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1718267073002/cd168a4e-a44e-491a-80df-9929c8889383.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-aws-command-line-interface">AWS Command Line Interface</h3>
<p>Today we will be setting up our AWS CLI.</p>
<p>AWS CLI is a tool that lets us manage AWS services from the command line. With AWS CLI, we can control various AWS services and automate tasks through scripts.</p>
<p>To use AWS CLI, we need to configure it with access keys that grant the necessary permissions to perform actions on AWS resources. These access keys are part of AWS Identity and Access Management (IAM).</p>
<hr />
<h3 id="heading-iam-access-keys">IAM Access Keys</h3>
<p>IAM (Identity and Access Management) access keys are a pair of security credentials that AWS uses to authenticate and authorize API calls. These keys are associated with an IAM user and consist of two parts:</p>
<ol>
<li><p><strong>Access Key ID</strong>: A unique identifier for the access key.</p>
</li>
<li><p><strong>Secret Access Key</strong>: A secret key used to sign requests.</p>
</li>
</ol>
<p><strong>Purpose</strong></p>
<p>IAM access keys allow programmatic access to AWS services via the AWS CLI (Command Line Interface), AWS SDKs (Software Development Kits), and other tools that make API requests to AWS services.</p>
<p>When creating access keys, it is essential to use the <code>IAMAdmin</code> role or another appropriate IAM role. Creating <strong>access keys for the root account is not recommended</strong> due to security concerns.</p>
<p>Let's create our Access keys.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718243313322/1128d3b6-4d15-41a6-a938-d3b1df60ae06.png" alt /></p>
<p>Click on your <strong>profile</strong> and select <code>Security credentials</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718243430931/17eb2bbf-121a-42ad-ab2b-a9cb46326601.png" alt /></p>
<p>Scroll a bit and you will find the <strong>Access keys</strong> section.</p>
<p>Click on <code>Create access key</code>.</p>
<p>Choose <strong>CLI</strong> for Use case, tick the confirmation box and click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718245111147/34a27507-274a-4538-87f5-72c808196e4f.png" alt /></p>
<p>Provide a description tag for your Access key.</p>
<p>Click on <code>Create access key</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718245225208/780402ce-caeb-4993-88ad-b05da8004ebf.png" alt /></p>
<p>Our access key has been created.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718245201826/0c4afb26-8200-42f7-8e4e-0052487ab958.png" alt /></p>
<p>We can see that this is the only time we can view or download our secret key. However, if we lose it, we can create a new one.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718245352698/2a9a7dda-9c35-4e7b-ac59-6b201f7548a0.png" alt /></p>
<p>Click on <code>Download .csv file</code> and store it securely in your local machine.</p>
<p>Click on <code>Done</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718245463321/7625a41d-f519-4477-acff-3a81d5633a22.png" alt /></p>
<p>We have created our access keys. We can create <strong>up to two access keys</strong> in total. Access keys can be <strong>created, deleted, activated,</strong> and <strong>deactivated</strong>.</p>
<hr />
<h3 id="heading-downloading-aws-cli">Downloading AWS CLI</h3>
<p>Now that we have created &amp; downloaded our access keys, it's time to download the AWS CLI on our local machine.</p>
<p><a target="_blank" href="https://aws.amazon.com/cli/">AWS CLI</a></p>
<p>Click the link above to download AWS CLI.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718245790494/3f31953e-cd79-40e3-a781-4140d35c80cb.png" alt /></p>
<p>Choose according to your operating system.</p>
<p>Configure all the setup, and after your setup is successful, type the following command.</p>
<pre><code class="lang-python">aws --version
</code></pre>
<p>The command displays the installed version of the AWS CLI on your machine.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718267627061/66bad602-9087-4a73-8955-edc1b8821014.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-configuration">Configuration</h3>
<p>Type the following command to configure your AWS CLI.</p>
<pre><code class="lang-python">aws configure
</code></pre>
<p>The command is used to configure your credentials for the AWS CLI. It will ask for your <strong>access key ID</strong>, <strong>secret access key</strong>, <strong>default region name</strong> (use the closest region code, e.g., us-east-1) &amp; skip the <strong>default output format</strong> field associated with your IAM user.</p>
<p>After you have configured your credentials, input the following command.</p>
<pre><code class="lang-python">aws configure list
</code></pre>
<p>The command displays information about the profiles you have configured for interacting with AWS services.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718262334198/856ea8c8-f2eb-4190-bd5c-49ec1d46b122.png" alt class="image--center mx-auto" /></p>
<p>You must see your configured profile.</p>
<hr />
<h3 id="heading-simple-commands">Simple Commands</h3>
<p>Let's use simple AWS CLI commands.</p>
<pre><code class="lang-python">aws s3 ls <span class="hljs-comment">#to list the S3 buckets.</span>
</code></pre>
<p>The command is used to list the S3 buckets.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718362426500/4faa4a5b-3a80-47c3-be99-b485fb901cbb.png" alt /></p>
<p>As I do not have any buckets created, it is showing empty.</p>
<pre><code class="lang-python">aws iam list-users <span class="hljs-comment">#to list all IAM users</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718266032417/b7320345-5d58-45c5-81df-06adafe4e6cf.png" alt class="image--center mx-auto" /></p>
<p>We used simple AWS CLI commands. Now that our AWS CLI is set up, we can do many AWS operations from the command line but more on that later.</p>
<p>Thank you.</p>
]]></content:encoded></item><item><title><![CDATA[Transit Gateway]]></title><description><![CDATA[Hello Everyone,
Today we will be exploring Transit Gateway.
A Transit Gateway is a network transit hub that enables you to interconnect your VPCs, VPN connections, and Direct Connect gateways through a central point, simplifying your network architec...]]></description><link>https://sujanmagar.com.np/transit-gateway</link><guid isPermaLink="true">https://sujanmagar.com.np/transit-gateway</guid><category><![CDATA[AWS]]></category><category><![CDATA[AWS Transit Gateway]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Thu, 06 Jun 2024 03:29:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1717643857219/fdc5edd7-02a7-4568-b5a6-b2225107cc72.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello Everyone,</p>
<p>Today we will be exploring Transit Gateway.</p>
<p>A Transit Gateway is a network transit hub that enables you to interconnect your VPCs, VPN connections, and Direct Connect gateways through a central point, simplifying your network architecture.</p>
<p>Let's get started.</p>
<hr />
<h3 id="heading-overview">Overview</h3>
<p>We will be creating three VPCs, each with a subnet and an instance within that subnet. We'll set up a Transit Gateway to connect these three VPCs. Once all three VPCs are connected, we will SSH into our EC2 instances and perform some task to verify if they can communicate with instances in the other VPCs.</p>
<hr />
<h3 id="heading-task-1-creating-a-vpc">Task 1: Creating a VPC.</h3>
<p>Search for <strong>VPC</strong> in the search box and on <strong>VPC dashboard</strong>, click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717594159104/2516d407-2c3c-4629-835f-b03f83be99b3.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717594246641/6e4e5eb8-0949-479b-9d6d-aa145d80f048.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable name for your VPC and input a CIDR range value.</p>
<p>Keeping all other configurations as default, click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717594298756/7d1c80ba-5821-4d1c-8590-0ca85e5a9bb0.png" alt class="image--center mx-auto" /></p>
<p>We have created our first VPC.</p>
<p>Now, let's repeat the process two more times. Ensure the CIDR range for your other VPC does not overlap.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717594441473/2e2108f6-4a1d-4993-a3b5-166d5217be74.png" alt /></p>
<p>We have created three VPCs. Let's move on to the next task.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717641471895/ddf4bb4b-a86b-4fb1-bba6-3cbc4e352455.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-2-creating-an-internet-gateway">Task 2: Creating an Internet gateway</h3>
<p>On <strong>Internet gateways</strong>, click on <code>Create Internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717594575864/dc32e172-d10c-4a24-8148-e9e57b229303.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717594630885/bd5f6c1f-b031-43a2-a6e9-8b0ef0146ee4.png" alt /></p>
<p>Provide a suitable name for your Internet Gateway and click on <code>Create Internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717594686895/260e130c-8767-4ac4-b249-bdfb5a532ca1.png" alt /></p>
<p>Now, we should attach the Internet gateway to our VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717594727185/81a9024c-58ee-4d23-8b84-22c8b4517232.png" alt /></p>
<p>Select your first VPC and click on <code>Create internet gateway</code>.</p>
<p>Now, repeat the same process for the remaining two VPCs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717594881441/26d3b7b8-dae7-48bb-8bd8-53c5b9285f5b.png" alt class="image--center mx-auto" /></p>
<p>Alright, we have created three internet gateways and attached them to the VPCs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717641564209/9bae2f63-acf2-4da2-8e0b-86b80183ee57.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-3-creating-subnets">Task 3: Creating Subnets</h3>
<p>On <strong>Subnets</strong>, click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717594949091/671e0008-3504-47e1-8c09-2315626d8963.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595004091/6ed6c266-2603-4495-a064-bb8b1eaaef2b.png" alt /></p>
<p>Select your first VPC, pick an AZ and provide an eligible CIDR range.</p>
<p>Click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595082493/923621f5-8d0b-44dd-8a0d-fb30717b855f.png" alt /></p>
<p>We have created the first subnet. Now, let's repeat the process for the other two subnets.</p>
<p>Ensure that you provide eligible CIDR ranges for your subnets.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595225949/be9054d3-98da-4cce-add4-f52ade439e9a.png" alt class="image--center mx-auto" /></p>
<p>We have created three subnets, each residing in a different VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717641925656/4bf35a88-cf1b-45e8-87b7-6764966e5037.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-4-creating-route-table">Task 4: Creating Route Table</h3>
<p>On <strong>Route table</strong>, click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595291460/e48861f1-32a9-4f7b-bdf4-47474b0a8deb.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595329813/f81fe597-a98b-4714-acd0-efa8681a3670.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable name for your route table, select your VPC and click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595406103/a2c2e805-8fca-406f-b62b-0ee96c7e6c1d.png" alt /></p>
<p>After creating route table, on <strong>Subnet associations</strong>, click on <code>Edit subnet associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595455375/16e37ead-b605-437a-816d-7bc9a61a1a7d.png" alt /></p>
<p>Tick your subnet and click on <code>Save associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595494424/bac002f4-87ea-40ca-b006-598543c7be1e.png" alt /></p>
<p>Now, on <strong>Routes</strong>, click on <code>Edit routes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595555414/d54ed25f-5693-407d-91df-b1d5e85c93c1.png" alt class="image--center mx-auto" /></p>
<p>Click on <strong>Add route</strong>, configure the above configurations, and click on <code>Save changes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595617773/674feea7-a2b3-487e-b9e8-aba1434ac3b5.png" alt class="image--center mx-auto" /></p>
<p>Now, we have associated the subnets and set up the necessary routes for the current VPC. Let's repeat the process for our other VPCs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595776104/99a697f4-e39d-4af3-b4a8-d63c7a6988e5.png" alt /></p>
<p>We have created our route tables.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717642045396/4a5d74e0-cb61-45d3-86d1-e601e49c742f.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-5-creating-ec2-instances">Task 5: Creating EC2 Instances</h3>
<p>Search for <strong>EC2</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595858058/34e1b440-3ddd-4964-b344-63d16fc875e3.png" alt class="image--center mx-auto" /></p>
<p>On <strong>Instances</strong>, click on <code>Launch Instances</code>.</p>
<p>Provide a suitable name for your instance, choose an AMI, either create or use an existing key pair.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717595916064/2280a545-aea0-4567-bf6b-fb996863e0ba.png" alt /></p>
<p>Edit Network settings, select your VPC, and <code>Enable</code> the Auto-assign public IP option.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717596019558/aad20393-d9c9-4f34-a34a-552c098d5c6d.png" alt /></p>
<p>We are provided with default SSH configuration. Now, click on <code>Add security group rule</code> to add a rule for HTTP requests.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717596069447/39e214de-3eae-4e5c-905b-9fb08a467a0b.png" alt /></p>
<p>Configure the above configurations in your new security group rule.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717596133237/5cbc8d51-c834-4828-aa7e-3591d513cd12.png" alt /></p>
<p>Scroll to bottom &amp; click on <strong>Advanced details</strong>.</p>
<p>On <strong>User data</strong>, paste the following command.</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># Update and install apache2</span>
apt-get update
apt-get install -y apache2

<span class="hljs-comment"># Create a simple index.html file with "Hello" text</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"Hello from the FIRST"</span> &gt; /var/www/html/index.html

<span class="hljs-comment"># Restart apache2 service</span>
systemctl restart apache2
</code></pre>
<p>Click on <code>Launch instance</code>.</p>
<p>Now, it's time to set up the other two instances. Repeat the process while making necessary changes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717596516806/36a61a67-22bf-45f4-a300-d6420ae9f0ca.png" alt /></p>
<p>Setting up our second instance.</p>
<p>Configure security rule like we did earlier.</p>
<p>And paste the following in the user data for our second instance.</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># Update and install apache2</span>
apt-get update
apt-get install -y apache2

<span class="hljs-comment"># Create a simple index.html file with "Hello" text</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"Hello from the SECOND"</span> &gt; /var/www/html/index.html

<span class="hljs-comment"># Restart apache2 service</span>
systemctl restart apache2
</code></pre>
<p>Click on <code>Launch instance</code>.</p>
<p>Now, time to set up our third instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717598561537/a547150b-804d-4f39-a6aa-ee1ef68828dc.png" alt /></p>
<p>Setting up our third instance. Make sure you have added the additional security group rule.</p>
<p>On <strong>User data</strong> section, paste the following.</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># Update and install apache2</span>
apt-get update
apt-get install -y apache2

<span class="hljs-comment"># Create a simple index.html file with "Hello" text</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"Hello from the THIRD"</span> &gt; /var/www/html/index.html

<span class="hljs-comment"># Restart apache2 service</span>
systemctl restart apache2
</code></pre>
<p>Click on <code>Launch instance</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717598774314/6fcedb54-91d0-4f98-8d8d-fed78bcd1a88.png" alt class="image--center mx-auto" /></p>
<p>We have launched three instances.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717642332134/5d781a7b-c245-4757-b8ad-7c3bbf679533.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-6-setting-transit-gateway">Task 6: Setting Transit Gateway</h3>
<p>Search for <strong>Transit Gateway</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717598853846/cce53576-0319-434a-a5c5-3487202288d8.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717598917458/52bc9cb5-ab27-4563-b718-a1d4eec118fc.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable name for your transit gateway.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717599144776/4664584a-531f-49a9-9df3-74ed4de30b59.png" alt /></p>
<p>We left these settings as default. The ASN will be provided by AWS. Now, let's discuss these options for a while.</p>
<p><strong>Transit Gateway</strong> is a central hub for connecting and managing different networks. <strong>ASN</strong> is a unique identifier used to help the Transit Gateway route traffic between these networks using Border Gateway Protocol.</p>
<p><strong>DNS Support</strong> means the ability to resolve domain names to IP addresses. When enabled, DNS support allows resources connected through the Transit Gateway to use DNS resolution for communication.</p>
<p><strong>Equal-Cost Multi-Path (ECMP) Support</strong> for VPNs allows the use of multiple paths for data traffic. This improves load balancing and redundancy by distributing traffic across multiple VPN tunnels that have the same cost (or path length).</p>
<p><strong>Default Route Table Association</strong> refers to the automatic association of new VPC attachments to the Transit Gateway's default route table. This means that any new VPCs connected to the Transit Gateway will automatically use the default route table for routing traffic.</p>
<p><strong>Default Route Table Propagation</strong> means that routes learned from new VPC attachments are automatically added to the default route table of the Transit Gateway. This ensures that all connected networks are aware of each other without manual route updates.</p>
<p><strong>Multicast Support</strong> allows the transmission of data from one sender to multiple receivers simultaneously. This is particularly useful for applications like video conferencing, where the same data needs to be sent to multiple users at the same time.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717600796249/11411974-bf0e-4bc4-88f6-7cae21581459.png" alt /></p>
<p>It automatically accepts requests from other AWS accounts to attach their VPCs or VPNs to your Transit Gateway.</p>
<p>With all other configurations left as default, click on <code>Create transit gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717601382097/b551636c-3249-4248-a0d3-697fbe5d5625.png" alt /></p>
<p>We can see the details of our transit gateway.</p>
<p>Now that we have created a transit gateway, it's time to create transit gateway attachments.</p>
<p>A Transit Gateway Attachment is needed to connect your VPCs, VPN connections, or Direct Connect gateways to the Transit Gateway. The attachments essentially establish the pathways through which data can travel between your networks using the Transit Gateway.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717633343172/991383d5-1f8f-4a96-8e7c-c308a8d61a99.png" alt /></p>
<p>On <strong>Transit gateway attachments</strong>, click on <code>Create transit gateway attachment</code>. Since we have three VPC connections, we need to create a transit gateway attachment for each of them.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717633475673/aed2046e-ddcc-4301-aeb3-4d16965947c8.png" alt /></p>
<p>Provide a suitable name and select your Transit Gateway. Since our Attachment type is VPC, we can keep it as the default option.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717633573682/46f193f4-3361-41f2-aa6a-a57a9a40268d.png" alt /></p>
<p>Select your first VPC for the VPC ID. Keep all configurations as default, then click on <code>Create transit gateway attachment</code>.</p>
<p>Now, let's repeat the process to create the other two transit gateway attachments.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717633833728/1da31b5e-e52e-46c0-8d4c-ae0cc8a413ec.png" alt /></p>
<p>We have created three transit gateway attachments and associated them with their respective VPCs.</p>
<p>Now, it's time to update the route tables of all three VPCs. We need to add routes that direct traffic destined for the other VPCs to the Transit Gateway.</p>
<p>Let's start with the route table of the first VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717634886946/b9bf8528-da5a-4452-93c7-1a1629f16283.png" alt class="image--center mx-auto" /></p>
<p>Select your first route table and on <strong>Routes</strong>, click on <code>Edit routes</code>.</p>
<p>Duplicate your current tab and navigate to the CIDR value of your second VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717634984182/de734cdd-9f31-4e72-ba6e-4e5ae3b70701.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717635024310/dd367964-160a-4ea4-9043-75147a1f7fce.png" alt class="image--center mx-auto" /></p>
<p>Now, click on <code>Add route</code>, paste the copied CIDR into the <strong>Destination</strong> field, and select your transit gateway attachment in the <strong>Target</strong> field on Transit Gateway.</p>
<p>Click on <code>Save changes</code>.</p>
<p>Now, click on <code>Add route</code> again.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717635144244/58566d4a-c807-4a89-9cef-1854d9d54c4f.png" alt /></p>
<p>Copy the CIDR range of the third VPC and follow the same steps as before.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717635276738/3fefd4a1-51cb-49b8-88bd-63cb8383898a.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Save changes</code>.</p>
<p>Now, we need to repeat the process for our second and third VPCs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717635402671/23dc2414-c2cc-43ec-b423-d18a50169f69.png" alt class="image--center mx-auto" /></p>
<p>We have completed all the necessary route setup for our second VPC.</p>
<p>Click on <code>Save changes</code>.</p>
<p>Now, let's proceed with our third VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717635533138/5b87d6b6-ed4b-4b41-9040-62f3c356f760.png" alt class="image--center mx-auto" /></p>
<p>Okay, the necessary routes for the third VPC have been configured.</p>
<p>Click on <code>Save changes</code>.</p>
<p>Now that all setups are complete, it's time to test the connectivity between the VPCs to ensure everything is working as expected.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717643279876/df3ca6fc-9b01-4d60-8ccf-8042aaf8ec0a.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-7-ssh-into-ec2-instances">Task 7: SSH into EC2 instances.</h3>
<p>Go to <strong>EC2 dashboard</strong> by searching for <strong>EC2</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717635748096/be8888f5-6758-48c6-b4c3-8a6a7a975557.png" alt class="image--center mx-auto" /></p>
<p>Select your first instance and click on <code>Connect</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717635779520/da3bb19d-76e1-4c00-bdff-e6d51a0b3529.png" alt /></p>
<p>Now on SSH client, we have to follow given procedures.</p>
<p>Open terminal in your local machine.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717635891821/0eb7fc46-b14a-45f7-94e1-9a0749013036.png" alt /></p>
<p>Paste the copied command into your terminal to change the key permissions.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717635927358/73a55409-6215-4d19-bfe6-2640edbb3c3d.png" alt /></p>
<p>Now copy the command and paste it into your terminal to SSH to your instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717635977551/096a32d4-96cf-4cb2-b281-c484b18f3717.png" alt /></p>
<p>Click on <code>Enter</code>, proceed with <strong>yes</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717636025449/cdad64a9-21a2-4404-b097-b4b641ae5930.png" alt class="image--center mx-auto" /></p>
<p>We're now in our first instance. Let's check if we can communicate with the other two instances that are in different VPCs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717636118838/ad4d1462-5efe-4828-b797-d1ad30ef7bb8.png" alt class="image--center mx-auto" /></p>
<p>Select your second instance &amp; copy the <strong>Private IPv4 address</strong>.</p>
<pre><code class="lang-bash">curl &lt;Private IPv4 address&gt;
</code></pre>
<p>Paste the command into your terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717636260785/993f55a0-d89f-4c01-929f-e528007b8bf6.png" alt /></p>
<p>Alright, we've received a response from our second instance.</p>
<p>Let's check for a response from our third instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717636342182/718c939b-bdf0-4db0-91e1-044f552768e0.png" alt /></p>
<p>We've received a response from our third instance as well.</p>
<p>This confirmation was from our first instance in our first VPC. To check the connectivity from our other two instances in different VPCs, we need to SSH into them and follow the same process we used for the first instance.</p>
<p>Let's now check from our second instance in our second VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717636565049/c57f3e26-0f85-4dd5-a22b-8fd2db15062b.png" alt /></p>
<p>Now it's time from our third instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717636692787/b421051b-e23f-4fa9-85d0-e69f25aec567.png" alt /></p>
<p>Alright, we have tested connectivity from all of our instances, and they all have a connection.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717644517436/fb78511d-7cd4-4c6b-b6cd-9f8cd9e0d2be.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-conclusion">Conclusion</h3>
<p>We have successfully set up a transit gateway and connected three VPCs to it. We tested the communication between instances in these VPCs using a simple <code>curl</code> command, confirming that they can communicate with each other.</p>
<hr />
<h3 id="heading-task-8-clean-up">Task 8: Clean Up</h3>
<ol>
<li><p><strong>Terminating Instances.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717637116659/1c009bb6-b5e5-46e4-9743-4c913927a262.png" alt class="image--center mx-auto" /></p>
<p> Select all your instances and in the <strong>Instance state</strong> panel, click on <code>Terminate instance</code>.</p>
</li>
<li><p><strong>Deleting Transit Gateway attachments.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717637667541/a782708c-54a8-4cd5-86a0-2f95d9d7a246.png" alt class="image--center mx-auto" /></p>
<p> Go to <strong>VPC dashboard</strong>, scroll down to <strong>Transit gateways</strong>, in the <strong>Actions</strong> panel, click on <code>Delete transit gateway attachment</code>. Repeat this process for the remaining two attachments. Note that it will take some time for the deletion to complete.</p>
</li>
<li><p><strong>Deleting Transit Gateway.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717637752080/32af7ee4-542d-40c0-afd7-923c66fc7ccd.png" alt class="image--center mx-auto" /></p>
<p> Select your transit gateway and in the <strong>Actions</strong> panel, click on <code>Delete transit gateway</code>.</p>
</li>
<li><p><strong>Deleting Subnets.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717637211064/d42b1aab-4d18-4e18-99bd-60737d5e5f05.png" alt class="image--center mx-auto" /></p>
<p> On <strong>Subnets</strong>, select all your 3 subnets and in the <strong>Actions</strong> panel, click on <code>Delete subnet</code>.</p>
</li>
<li><p><strong>Deleting VPCs.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717637970382/bb6abc2f-0c10-44b2-a0b3-87457d38a6b6.png" alt /></p>
<p> Select your first VPC and in the <strong>Actions</strong> panel, click on <code>Delete VPC</code>.</p>
<p> Deleting a VPC will also remove all associated route tables and internet gateways. Repeat the process for the other two VPCs.</p>
</li>
</ol>
<p>We have removed all the used resources now.</p>
<hr />
<p>Alright, see you in the next one!</p>
]]></content:encoded></item><item><title><![CDATA[VPC Peering]]></title><description><![CDATA[Hello everyone,
Today, we'll be exploring VPC peering in AWS. In Amazon Web Services (AWS), a Virtual Private Cloud (VPC) is a logically isolated network segment you create within the cloud. You can launch resources like EC2 instances into your VPC.
...]]></description><link>https://sujanmagar.com.np/vpc-peering</link><guid isPermaLink="true">https://sujanmagar.com.np/vpc-peering</guid><category><![CDATA[AWS]]></category><category><![CDATA[vpc]]></category><category><![CDATA[vpc peering]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Wed, 05 Jun 2024 01:14:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1717548657665/daea270c-8f39-4577-88eb-c70eb7920f07.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello everyone,</p>
<p>Today, we'll be exploring VPC peering in AWS. In Amazon Web Services (AWS), a Virtual Private Cloud (VPC) is a logically isolated network segment you create within the cloud. You can launch resources like EC2 instances into your VPC.</p>
<p>VPC peering is a networking connection established between two VPCs that enables you to route traffic between them using private IP addresses.</p>
<p><strong>Why do we need VPC peering?</strong></p>
<p>VPC peering is essential for enabling private communication between VPCs without relying on public IPs or the internet. It facilitates secure and efficient sharing of resources across different VPCs, whether they reside within the same account, different accounts, or even different regions.</p>
<p>Alright, time to put our knowledge to work!</p>
<hr />
<h3 id="heading-overview">Overview</h3>
<p>We will set up two VPCs, each containing instances. We will SSH into our instances and initiate communication with instances in the other VPC to test if our VPC peering connection is working.</p>
<hr />
<h3 id="heading-task-1-creating-vpcs">Task 1: Creating VPCs</h3>
<p>Search for <strong>VPC</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717414735194/ed0402c3-65c6-4838-add1-eedd76c495a7.png" alt /></p>
<p>On <strong>VPC dashboard</strong>, click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717414921324/1d6079c7-f626-49ea-bf9a-4d3514adba41.png" alt /></p>
<p>Provide a name for your VPC and input a CIDR range value for your VPC.</p>
<p>Click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717414969048/fcc99705-3c65-420c-935a-0d4b3a013307.png" alt class="image--center mx-auto" /></p>
<p>Let's create another VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415128290/8d2fc224-6aaa-4cae-adbc-e82d91e0a6a3.png" alt /></p>
<p>Provide a suitable name and input a CIDR range value for your second VPC.</p>
<p>Click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415190194/c51bc16a-8813-43c0-b8f1-abe449e0ec0d.png" alt class="image--center mx-auto" /></p>
<p>We have created two VPCs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717546208267/f6b8b86c-e076-4c25-a902-d0c4f85de3f4.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-2-creating-internet-gateway">Task 2: Creating Internet gateway</h3>
<p>On <strong>Internet gateways</strong>, click on <code>Create internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717420054888/9ad3e5ca-a76c-41f3-82d0-47f018d7e3b6.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717420131229/fd63d27c-cca8-435c-826c-7eace325c57f.png" alt /></p>
<p>Provide a name for your Internet gateway and click on <code>Create internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717420187006/c6299c96-0ce3-48cd-8eea-d1ad363ae1fd.png" alt /></p>
<p>After creating internet gateway, attach to your first VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717420257481/adfae176-1325-437c-b1fe-45f8c51d195b.png" alt /></p>
<p>Similarly, create another internet gateway and attach to the second VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717546320555/64ae8e82-d683-4fa9-9248-7e74ecd07e68.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-3-creating-subnets">Task 3: Creating Subnets</h3>
<p>On <strong>Subnets</strong>, click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415259081/6c8f9e54-db62-4a69-88d3-65003f88993c.png" alt class="image--center mx-auto" /></p>
<p>Select your first VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415310404/fc606926-bb58-4bdd-9cb3-fbdea5ced159.png" alt /></p>
<p>Provide a suitable name for your VPC, choose AZ and input a valid CIDR range for your subnet.</p>
<p>Click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415377903/2714c600-7a5f-4126-8eb1-55a041f379a5.png" alt /></p>
<p>Let's create another subnet in our second VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415442808/0cfec5ef-3965-46e5-9e6a-871c06233a40.png" alt /></p>
<p>Provide the name for your subnet, select AZ, and input an eligible CIDR range.</p>
<p>Click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415596385/3dc4c9e6-9b79-4a68-a0fe-1340091eb623.png" alt class="image--center mx-auto" /></p>
<p>We have created two subnets in different VPCs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717546635266/ac011215-450d-4005-bf14-df634219fdb5.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-4-creating-route-tables">Task 4: Creating Route tables</h3>
<p>On <strong>Route tables</strong>, click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415635263/e4e1003e-cd82-44b2-99d8-2116cb454ec1.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415714941/cc2a05e5-5482-47d5-ade3-dbde678e6241.png" alt /></p>
<p>Provide the name for your route table and select your first VPC.</p>
<p>Click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415778458/28797bee-3ed6-48bf-8594-4050220da708.png" alt class="image--center mx-auto" /></p>
<p>On <strong>Subnet associations</strong>, click on <code>Edit subnet associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415835891/5ccc4d15-079f-43e3-a1a5-fb16a121618f.png" alt /></p>
<p>Select your subnet and click on <code>Save associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717420341559/48252201-0efd-4989-9b4f-8f828e240ac5.png" alt /></p>
<p>On <strong>Routes</strong>, click on <code>Edit routes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717420380294/ac2d78b8-3a24-492c-ba13-6d0edae452c4.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Add route</code> to add the above configurations.</p>
<p>Click on <code>Save changes</code>.</p>
<p>Now, let's create another route table, associate the corresponding subnet to it &amp; add the necessary route.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415927199/34c0f658-f966-4708-ad6a-5a25c3fa85f6.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717415961944/5c8c1a26-e3c1-4917-9a1e-6a805ba09e99.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717420529073/3d1a8b0b-208b-45e5-aa28-91f60d58bf23.png" alt class="image--center mx-auto" /></p>
<p>And now we have set up our second route table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717416002151/2912a722-7ee8-43bc-91ce-c0e4fcd8344f.png" alt /></p>
<p>We have created two route tables for two VPCs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717546782769/66836a21-7d63-4bbd-a71a-26095c1f361d.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-5-creating-ec2-instances">Task 5: Creating EC2 instances</h3>
<p>Go to <strong>EC2 dashboard</strong>, on Instances, click on <code>Launch instances</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717416107676/1653b4b8-3f6d-44a1-ad05-2e4fb40bc36b.png" alt /></p>
<p>Provide name for your EC2, select an AMI. Create or use an existing key pair.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717420822887/d9acb0fd-4e70-4695-a227-4e1f81d6806d.png" alt /></p>
<p><code>Edit</code> Network settings. Select your first VPC, subnet and <strong>Enable</strong> the Auto-assign public IP.</p>
<p>We are provided with default SSH configuration.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717470974788/0e86a098-8458-4c67-95d8-b58796773ba4.png" alt /></p>
<p>Click on <code>Add security group rule</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717471017237/f6e4e786-79cc-4c27-81f0-26439d44c1e3.png" alt /></p>
<p>Configure the above configurations in your Security group rule.</p>
<p>On <strong>Advanced Details</strong>, scroll to <strong>User data</strong> and paste the following command.</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># Update and install apache2</span>
apt-get update
apt-get install -y apache2

<span class="hljs-comment"># Create a simple index.html file with "Hello" text</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"Hello FIRST"</span> &gt; /var/www/html/index.html

<span class="hljs-comment"># Restart apache2 service</span>
systemctl restart apache2
</code></pre>
<p>Leave all other configurations as default and click on <code>Launch instance</code>.</p>
<p>Now, let's create another instance.</p>
<p>Provide name for your instance, choose an AMI, either create or use an existing key pair.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717420979354/0cf9c421-bba6-4095-92d3-52ee4ff1d830.png" alt /></p>
<p><code>Edit</code> Network settings, select your second VPC, subnet and <strong>Enable</strong> the Auto-assign public IP.</p>
<p>Repeat the necessary instructions (security group rule) as earlier.</p>
<p>Here is the user data for the second instance.</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># Update and install apache2</span>
apt-get update
apt-get install -y apache2

<span class="hljs-comment"># Create a simple index.html file with "Hello" text</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"Hello SECOND"</span> &gt; /var/www/html/index.html

<span class="hljs-comment"># Restart apache2 service</span>
systemctl restart apache2
</code></pre>
<p>Leaving all other configurations as default, click on <code>Launch instance</code>.</p>
<p>We have created two EC2 instances in different subnets residing in different VPCs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717471636548/07d7fd32-157b-4eed-a172-9752b3fc7a40.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717546920974/dcf653be-035f-4d22-9444-0b8048c6ec54.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-6-establishing-a-vpc-peering-connection">Task 6: Establishing a VPC Peering Connection</h3>
<p>A peering connection is a networking connection between two Virtual Private Clouds that allows them to communicate as if they are on the same network.</p>
<p>Go to <strong>VPC dashboard</strong>, scroll down to <strong>Peering connections</strong>, click on <code>Create peering connection</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717424812073/cdd204c0-ef03-4c4f-9b65-46e73322bada.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717424876496/dac8323a-2dfe-455d-9c86-5a9c0a4985f5.png" alt /></p>
<p>Provide a suitable name and select your first VPC as Requester.</p>
<p>One VPC initiates a peering connection request to another VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717425056053/2b1034f0-2186-4954-bd25-df1f7a06b966.png" alt /></p>
<p>We can establish a peering connection to a VPC in our own account as well as to a VPC in another account.</p>
<p>The owner of the target VPC accepts the peering request.</p>
<p>Click on <code>Create peering connection</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717425246247/dd7106e8-dc47-40be-a3cb-7ce9be4c45ca.png" alt /></p>
<p>Since both VPCs reside within the same account, this acceptance request message appears. In the Actions panel, click <code>Accept request</code> to proceed.</p>
<p>Now, both VPCs must update their route tables to direct traffic destined for the other VPC through the peering connection.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717425384614/670ceecf-4cb7-4fba-9cb2-95a535a338d4.png" alt /></p>
<p>On <strong>Route tables</strong>, click on one of your Route table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717425433415/6af3b16f-bed1-4af1-8de4-f1fbc1c2fb19.png" alt /></p>
<p>Click on <code>Edit routes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717425478295/d9adc8bf-607f-43b5-8d5a-5635b0d3f00f.png" alt /></p>
<p>Click on <code>Add route</code>.</p>
<p>Duplicate your current tab and copy the IPv4 CIDR of your second VPC.</p>
<p><strong>Note</strong> that for the first router, IPv4 CIDR of second VPC must be configured while for second router, IPv4 CIDR of the first VPC is considered.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717462408145/b3f52e95-ee88-4fa0-8c14-6d5f72886ccc.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717462653828/37c40dc8-401b-42ac-9c13-3c703126ab93.png" alt class="image--center mx-auto" /></p>
<p>Paste into the <strong>Destination</strong> field and select your Peering connection in <strong>Target</strong> field.</p>
<p>Click on <code>Save changes</code>.</p>
<p>Now, let's set up the necessary route for the second VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717463007394/db8ef4c2-5cea-438a-b330-36aada78468f.png" alt /></p>
<p>Copy the IPv4 CIDR of your first VPC and paste it into the destination field in your second route table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717463040245/abef465a-674f-4026-b077-c4caadf01575.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717463154409/193b0f86-5f05-494d-b6fb-70c9b45fd9dd.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Save changes</code>.</p>
<p>Now, we have set up the necessary peering routes in the respective route tables.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717547745588/94b9e958-4236-45ed-82e5-a450983a0a72.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-7-ssh-into-ec2s">Task 7: SSH into EC2s</h3>
<p>On <strong>Instances</strong>, select one of your instance and click on <code>Connect</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717472394133/e41238c7-4676-43e5-b818-eb9771529d77.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717472415517/1fe18188-ea08-4a4c-b27f-ee7d1bed4fb4.png" alt /></p>
<p>On SSH client, we are going to follow some instructions.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717472441286/ab7b0851-e243-4534-8643-ef3f4d57db72.png" alt /></p>
<p>Copy the command and paste it into your terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717468717857/9ed8fee2-64d2-4660-857f-e1a62a6fdabe.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717472468733/15fe48aa-d476-4a00-b48c-0d92f5a0ed97.png" alt /></p>
<p>Copy the command and paste it into your terminal.</p>
<p>Proceed with yes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717472507374/9446758d-c219-4262-bedb-4ea9bafe0a74.png" alt class="image--center mx-auto" /></p>
<p>We are into our first instance now.</p>
<p>Now, it's time to SSH into our second instance.</p>
<p>Follow all the instructions as before.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717471919869/a7b77135-f454-4a15-b506-50ac00371a05.png" alt class="image--center mx-auto" /></p>
<p>We are now connected to the second instance via SSH.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717548293280/564c0b7e-0ab9-477a-8432-02a999886994.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717469366820/4f3fb9da-ddd6-4323-b9dd-5b247518735e.png" alt /></p>
<p>Copy the private IPv4 address of the second instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717472740783/770f57b2-ecd7-42ad-afbe-e5013f3e780b.png" alt /></p>
<p>Type the command <code>curl</code> and paste the copied private IPv4 address of the second instance.</p>
<p>The <code>curl</code> command is being used to retrieve content from a web server at IP address <code>12.0.1.98</code>.</p>
<p>We can see the second instance is responding to our request.</p>
<p>Let's see it the other way around.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717472576578/5b703526-4fea-4f47-b8d3-205581485d3c.png" alt /></p>
<p>We can see the connection is happening between two instances.</p>
<p>Now, let's remove the connection and see if the connection still happens.</p>
<hr />
<h3 id="heading-task-8-removing-peering-connection">Task 8: Removing Peering Connection</h3>
<p>On <strong>VPC dashboard</strong>, on <strong>Route tables</strong>, click on your first route table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717473262610/c082ca4f-5e31-42fd-bf17-25511b31569d.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717473339539/a43d1246-f2f1-4c68-8fe1-dca91c4b62e7.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Edit routes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717473372417/a11fff67-e281-42d4-897b-cfdd480c8bf2.png" alt class="image--center mx-auto" /></p>
<p>Remove the peering route.</p>
<p>Click on <code>Save changes</code>.</p>
<p>Now, repeat the same process for your second route table.</p>
<p>Okay, now that we have updated our route tables, let's try to make the same request from both of our instances.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717473494091/38f26388-b6e2-4825-9cf5-d00f4181b5d5.png" alt /></p>
<p>There is no response to the request at this time.</p>
<p>Let's try from another instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717473551233/74774dcc-b20d-490f-b811-c1c6f5fee620.png" alt /></p>
<p>Following the removal of the VPC peering connection, the VPCs can no longer communicate directly as if they were on the same network.</p>
<hr />
<h3 id="heading-conclusion">Conclusion</h3>
<p>In this session, we explored the concept of VPC peering by establishing connections between two VPCs. We successfully initiated communication between instances in these peered VPCs.</p>
<hr />
<h3 id="heading-task-9-clean-up">Task 9: Clean Up</h3>
<ol>
<li><p><strong>Terminating Instances.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717473718526/1e3b91d8-a7bb-4bce-a38c-3e877e42b27a.png" alt class="image--center mx-auto" /></p>
<p> Select both of your instances and in the <strong>Instance state</strong> panel, click on <code>Terminate instance</code>.</p>
</li>
<li><p><strong>Deleting Subnets.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717473810652/1b9edc99-cf70-4ba1-91ab-0d40591d5c28.png" alt class="image--center mx-auto" /></p>
<p> Go to <strong>VPC dashboard</strong>, on <strong>Subnets</strong>, select both of your subnets and in the <strong>Actions</strong> panel, click on <code>Delete subnet</code>.</p>
</li>
<li><p><strong>Deleting Route table.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717473966050/f14d3b33-48e1-48e8-b7af-0bc819dd549e.png" alt class="image--center mx-auto" /></p>
<p> On <strong>Route tables</strong>, select both of your route tables and in the <strong>Actions</strong> panel, click on <code>Delete route table</code>.</p>
</li>
<li><p><strong>Deleting peering connection.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717474014106/8af2be27-286e-4eca-a0e5-cb4c10f378fd.png" alt class="image--center mx-auto" /></p>
<p> Select your created peering connection and in the <strong>Actions</strong> panel, click on <code>Delete peering connection</code>.</p>
</li>
<li><p><strong>Deleting VPCs.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717474163022/25112eda-c505-4ce7-8782-9ad4b5d90e4e.png" alt /></p>
<p> Select one of your VPC and in the <strong>Actions</strong> panel, click on <code>Delete VPC</code>. Repeat the same to delete the other VPC.</p>
</li>
</ol>
<p>Now, we have cleaned up our used resources.</p>
<hr />
<p>Alright people, see you in the next one!</p>
]]></content:encoded></item><item><title><![CDATA[AWS WAF (Web Application Firewall)]]></title><description><![CDATA[Hello people, today we will be learning about AWS Web Application Firewall (WAF) and doing a simple demo on it.
AWS WAF defends web apps from online threats with customizable rules to filter and block malicious traffic. Integrated with CloudFront and...]]></description><link>https://sujanmagar.com.np/aws-waf-web-application-firewall</link><guid isPermaLink="true">https://sujanmagar.com.np/aws-waf-web-application-firewall</guid><category><![CDATA[AWS]]></category><category><![CDATA[Web Application Firewall]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Mon, 03 Jun 2024 06:04:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1717394497137/651159b2-7f09-45b2-b116-cc50ffb90fdc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello people, today we will be learning about AWS Web Application Firewall (WAF) and doing a simple demo on it.</p>
<p>AWS WAF defends web apps from online threats with customizable rules to filter and block malicious traffic. Integrated with CloudFront and ALB, it offers real-time monitoring through CloudWatch.</p>
<p>Let's get started.</p>
<hr />
<h3 id="heading-overview">Overview</h3>
<p>In this setup, we will create two subnets, each containing an EC2 instance. These instances will be fronted by an Application Load Balancer (ALB). Then we will configure AWS WAF with a simple IP set rule to restrict connection requests from our IP address.</p>
<hr />
<h3 id="heading-task-1-creating-a-vpc">Task 1 : Creating a VPC</h3>
<p>Search for <strong>VPC</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717340363489/0bbcf1be-18dd-4d27-ac02-872a9fe7d54c.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717340485209/58c50da4-5f0f-4e30-bd75-6462f5908cb4.png" alt /></p>
<p>Provide a suitable name for your VPC and input a IPv4 CIDR value.</p>
<p>Click on <code>Create VPC</code> with all other configurations left as default.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717392621763/856014f1-dcbf-4e34-9166-ec541ecdfc84.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-2-creating-internet-gateway">Task 2: Creating Internet Gateway</h3>
<p>On <strong>Internet gateways</strong>, click on <code>Create internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717340592306/5e74fcbd-44eb-42bf-b041-6563ca4ac128.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717340660531/e7259ec9-9bd8-431b-9f7c-04019bad7ac6.png" alt class="image--center mx-auto" /></p>
<p>Provide name for your Internet gateway &amp; click on <code>Create internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717340721300/cfe2fc71-3bfd-4cc7-a0df-2a15555e2c80.png" alt class="image--center mx-auto" /></p>
<p>Click on Attach to a VPC and select your VPC and click on <code>Attach internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717392689235/a5088e1f-fcff-4a0d-b7f4-78edfd458fc3.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-3-creating-subnets">Task 3: Creating Subnets</h3>
<p>On <strong>Subnets</strong>, click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717340831765/3972b1dc-75cc-4d18-81d7-71472e1dccc1.png" alt class="image--center mx-auto" /></p>
<p>Select your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717340911828/a54c40c1-2cb3-4b1d-aa60-99c90526d27a.png" alt /></p>
<p>Provide a suitable name for your subnet and an eligible CIDR range.</p>
<p>Click on <code>Add new subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717340989913/551a1734-3394-440c-b6e6-c2f9e0af4e31.png" alt /></p>
<p>Provide name for your second subnet and provide an eligible CIDR range value.</p>
<p>Click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717392864202/a6793ab5-2a14-4664-8df3-4dc1e62bcda6.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-4-creating-route-tables">Task 4: Creating Route tables</h3>
<p>On <strong>Route tables</strong>, click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717341095122/21db1d29-3af1-472b-b7ee-c334574569b2.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717341154142/d7ccdb8b-8cbb-4150-9ac2-373811cfff70.png" alt class="image--center mx-auto" /></p>
<p>Provide the name for your Route table and select your VPC.</p>
<p>Click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717341204614/e2a195a2-3111-4ccd-8e3a-fd4ea4491991.png" alt class="image--center mx-auto" /></p>
<p>Now, in <strong>Subnet associations</strong>, click on <code>Edit subnet associations</code> to associate subnets with this route table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717341260434/cb130098-40bf-4524-8c80-8a403e896cd5.png" alt class="image--center mx-auto" /></p>
<p>Select both of your subnets and click on <code>Save associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717341291526/27b34238-03d4-4aa9-9a74-0a125b46d4f7.png" alt class="image--center mx-auto" /></p>
<p>Now, on <strong>Routes</strong>, click on <code>Edit routes</code> to add route in our route table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717341351554/5488c845-93b0-4182-b00a-c84610578f96.png" alt class="image--center mx-auto" /></p>
<p>Configure the above configurations and select your internet gateway.</p>
<p>Click on <code>Save changes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717392931358/0870f262-6ad1-43ef-a418-c5142861822a.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-5-creating-ec2-instances">Task 5: Creating EC2 instances</h3>
<p>Search for <strong>EC2</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717341484588/be7181a7-8b72-4be6-81cd-eefb921b40fc.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Launch instances</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717341534038/43bee6ab-1292-4a65-abe3-97a33e1a451b.png" alt class="image--center mx-auto" /></p>
<p>Provide name for your instance. Choose an AMI. I have picked Ubuntu as my AMI.</p>
<p>Select free-tier instance if possible and create either a new or use an existing key pair.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717341722337/244080b4-ad7d-4a51-8833-a6147662fb00.png" alt /></p>
<p>Edit Network settings.</p>
<p>Select your VPC, select one of your subnets and <code>Enable</code> the Auto-assign public IP.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717341807199/bd3c3dea-a3cf-45dc-b265-43bae0f5dcd6.png" alt /></p>
<p>We have a default security group configured with SSH access.</p>
<p>Click on <code>Add security group rule</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717341886160/5bf74a2f-fdc0-4492-a363-8008efbe3ec0.png" alt /></p>
<p>Configure the above configurations.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717341953244/67c205a7-9b7c-46e6-b78a-bf4e6eb9c1ac.png" alt /></p>
<p>Click on <code>Advanced details</code>.</p>
<p>Scroll down to <strong>User data</strong> section and paste the following code.</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>
yes | sudo apt update
yes | sudo apt install apache2
<span class="hljs-built_in">echo</span> <span class="hljs-string">"&lt;h1&gt;Hello from the first server&lt;/h1&gt;"</span> &gt; /var/www/html/index.html
sudo systemctl restart apache2
</code></pre>
<details><summary>Code Explained</summary><div data-type="detailsContent">This script sets up the Apache web server and serves a simple HTML page with the message "Hello from the first server".</div></details>

<p>Click on <code>Launch instance</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717342187328/ad50e3e0-cc25-4646-90ea-309f1025a3ac.png" alt /></p>
<p>Copy the <strong>Public IPv4 address</strong> of your instance and paste into your browser.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717342314658/ac484930-df55-48dd-9adb-b1f6702bbaae.png" alt /></p>
<p>Set up another instance in a different subnet. Follow the same steps as before, but this time, make a slight change in the user data. Everything else can remain the same.</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>
yes | sudo apt update
yes | sudo apt install apache2
<span class="hljs-built_in">echo</span> <span class="hljs-string">"&lt;h1&gt;Hello from the second server&lt;/h1&gt;"</span> &gt; /var/www/html/index.html
sudo systemctl restart apache2
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717342634337/a6dbbb4f-8b97-4d10-9e98-ec76dff2df67.png" alt /></p>
<p>We have set up our second instance as well.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717393053959/bee8d363-7097-4c05-a13d-1c62b911a671.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-6-creating-target-groups">Task 6: Creating Target groups</h3>
<p>On <strong>Target groups</strong>, click on <code>Create target group</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717342687838/5ac21df0-5b49-4faa-a51f-bbb35f5fdf43.png" alt class="image--center mx-auto" /></p>
<p>Provide name for your target group, select your VPC while keeping all other settings as default.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717342837266/4838c5d7-5128-43fb-bde8-cc12ef9f6137.png" alt /></p>
<p>Select both of your instances and click on <code>Include as pending below</code>.</p>
<p>Click on <code>Create target group</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717393318974/7cc62faa-5c29-43c9-bd17-1ecfe8014554.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-7-creating-load-balancer">Task 7: Creating Load Balancer</h3>
<p>On <strong>Load Balancers</strong>, click on <code>Create load balancer</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717342940466/ca22a47b-c13b-4a0c-9c70-516a8669cafa.png" alt /></p>
<p>Choose <strong>ALB</strong> as load balancer.</p>
<p>Provide a suitable name for your load balancer.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717343144617/6a3ba7be-90dd-4be6-a982-f2afd91b4cb4.png" alt class="image--center mx-auto" /></p>
<p>Select your VPC and also tick all of your subnets.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717343176263/bbe8bd6f-68bc-4028-8425-122fd98d1eeb.png" alt class="image--center mx-auto" /></p>
<p>On Security groups, click on <strong>create a new security group</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717343238588/8e1fba18-ce1a-47d6-814f-5c4cbd0514cd.png" alt /></p>
<p>Provide a suitable name for your security group and select your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717343373042/55236187-5f73-4d3d-9a68-6dc8daf82b14.png" alt class="image--center mx-auto" /></p>
<p>In <strong>Inbound rules</strong>, configure the above configurations.</p>
<p>Click on <code>Create security group</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717343493501/5b2ccd30-0ba8-4490-8ccb-0d7788dc2cc9.png" alt class="image--center mx-auto" /></p>
<p>Return to your ALB setup page and refresh the Security groups.</p>
<p>Select your security group.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717343573526/052b5e29-d7cd-433e-87fc-8b49a0078ca6.png" alt /></p>
<p>Select your target group &amp; click on <code>Create load balancer</code>.</p>
<p>It takes a while to provision.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717343886399/388c3a5d-b833-44a3-8eaf-f9eef72ee5ed.png" alt class="image--center mx-auto" /></p>
<p>When the load balancer is ready, copy the DNS name and paste into your browser.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717343938147/57f16f1e-fab1-488b-b8de-ce8d270a204e.png" alt class="image--center mx-auto" /></p>
<p>You can refresh the page to see the load balancer distributing traffic to another server.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717393499838/62de59e0-2cb9-4313-bfb0-7192276dc6c3.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-8-setting-up-aws-waf">Task 8: Setting up AWS WAF</h3>
<p>Search for <strong>waf</strong> on the search box and select <code>WAF &amp; Shield</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717374088679/56218a74-6e9a-439c-85f4-b3611581ec5d.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717376071693/07d67ba4-1400-469b-bff4-c86f56ac85a2.png" alt class="image--center mx-auto" /></p>
<p>On the WAF &amp; Shield Dashboard, on <strong>IP sets</strong>, click on <code>Create IP set</code>.</p>
<p>IP sets in AWS WAF are collections of IP addresses or IP address ranges that you can use to specify which IPs should be allowed or blocked. By creating an IP set, you can easily manage a list of trusted or suspicious IP addresses and reference this list in your Web ACL rules.</p>
<p>Let's restrict access to our instances by blocking our IP address.</p>
<p>To get your IP address: <a target="_blank" href="https://whatismyipaddress.com/">find your ip address here</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717376343352/14ab8743-78ae-4288-8970-c830885b4be8.png" alt /></p>
<p>Make sure to provide <code>/32</code> at the end of your IP address to restrict access to only that specific address on the Internet.</p>
<p>Click on <code>Create IP set</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717377189414/57230bd8-13ab-4a7b-acab-10386bc7c966.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717377244704/8eb735dc-70d8-48be-836b-73ce28273565.png" alt /></p>
<p>Now on <strong>Web ACLs</strong>, click on <code>Create web ACL</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717374360032/145ce558-1da0-44f3-a5b4-8e332ab5b984.png" alt /></p>
<p>When setting up a Web ACL, you need to choose the resource type it will protect. There are two main categories:</p>
<ol>
<li><p><strong>Amazon CloudFront distributions</strong>: These are globally distributed networks that deliver content with low latency.</p>
</li>
<li><p><strong>Regional resources</strong>: These include services which operate within specific AWS regions.</p>
</li>
</ol>
<p>Selecting the resource type determines how the Web ACL rules will be applied to manage and control access.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717374540411/74f51f87-56c4-4670-b2e4-3c1c72dc8329.png" alt /></p>
<p>Provide name for your WAF.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717374565393/ef48c189-411e-4441-ae67-75b3a64d3a9e.png" alt /></p>
<p>Click on <code>Add AWS resources</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717374652611/cb1eb4c8-a76e-4eb6-b0dc-4ba4a9d47d2c.png" alt /></p>
<p>Select your Application Load Balancer and click on <code>Add</code>.</p>
<p>Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717377342192/525b9e30-60f1-4382-9d53-3e4705c07d73.png" alt class="image--center mx-auto" /></p>
<p>In Add rules panel, there are two modes:</p>
<ol>
<li><p><strong>Managed Rule Groups</strong>: These are pre-configured sets of rules created by AWS or AWS Marketplace sellers.</p>
</li>
<li><p><strong>Add My Own Rules &amp; Groups</strong>: This option allows you to create custom rules based on your specific needs.</p>
</li>
</ol>
<p>Click on <code>Add my own rules and rule groups</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717377683010/b8929c19-49f4-47cd-a43e-db0b7d85cf7f.png" alt /></p>
<p>There are different <strong>Rule type</strong> to choose from. As have already talked about IP set, let's explore the remaining.</p>
<ul>
<li><p><strong>Rule builder:</strong> A tool to create custom rules that specify conditions for allowing or blocking web requests.</p>
</li>
<li><p><strong>Rule group:</strong> A collection of rules managed together, which can be custom-made or provided by AWS/third parties, simplifying rule management for web applications.</p>
</li>
</ul>
<p>For now, we are sticking to IP set.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717378072963/5a1e160d-0189-4f09-b735-ffbc1abca23a.png" alt /></p>
<p>Name your Rule and select your IP set.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717378299873/a4398730-6498-48f4-bf6f-5c9576c20ece.png" alt /></p>
<p>When requests come through a CDN or proxy, the source IP is the proxy's, and the original IP is in a header. Using "<strong>IP address in header"</strong> can be risky because headers can be altered or handled inconsistently by proxies. Choose between using the source IP or the IP in the header to identify the original address.</p>
<p>The purpose is to accurately identify the original source IP address of a request that passes through a CDN or proxy. This helps in applying correct security rules and logging the true origin of the traffic, rather than just the intermediary proxy's IP address. However, caution is needed as headers can be manipulated.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717379180632/7dbd2beb-7739-496d-a7af-eaca251fa694.png" alt /></p>
<p>We can specify the action to take when a request originates from an IP address in a defined IP set. For now, let's stick to Block.</p>
<p>Click on <code>Add rule</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717380002541/6565fd55-4a42-4c96-8995-701f5ad39c25.png" alt class="image--center mx-auto" /></p>
<p>AWS WAF evaluates the rules and rule groups in the order shown, starting from the top. We can move rules up or down to change the evaluation order.</p>
<p>The <strong>order of evaluation affects the behavior of the web ACL</strong>. For example, suppose a web request matches a rule that allows requests and matches another rule that counts requests. If you list the rule that allows requests before the rule that counts requests, AWS WAF will allow the request and won’t count it.</p>
<p>As we do not have multiple rules for now, click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717379949846/23647b35-e024-4a62-8c94-404baee464b1.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717380298607/7e266c4b-4633-4a91-be09-9d4c0f1677a6.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Next</code>.</p>
<p>Review your Web ACL and click on <code>Create web ACL</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717380434468/ed1c8b50-f78f-4df9-b34d-701ce27df771.png" alt class="image--center mx-auto" /></p>
<p>We have created our Web ACL.</p>
<p>Now search for <strong>load balancer</strong> in the Search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717381203713/f1614128-bab6-4eeb-9373-4f320498006c.png" alt class="image--center mx-auto" /></p>
<p>Select your load balancer &amp; copy the DNS name. Paste it into your browser.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717381259728/b311b95b-e9dd-4d28-8082-2a9eb0cd9296.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717394156643/00b39f10-3e04-4137-8581-3a7f15089830.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-9-exploring-waf">Task 9: Exploring WAF</h3>
<p>We are currently unable to process the request because the WAF is configured to block it. Try reloading the page a few times to see the effect later.</p>
<p>Search for <strong>WAF</strong> in the search box and select WAF &amp; Shield.</p>
<p>On <strong>Web ACLs</strong>, select your Web ACLs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717381427009/94d286be-65ae-44db-861a-37f24c5f8276.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717382011384/e00a123c-6471-4d1e-86b0-bfefdf884d1a.png" alt class="image--center mx-auto" /></p>
<p>We can explore different aspects here. Let's look at the Traffic Overview.</p>
<p>This section provides insights on various details.</p>
<p>Next, head over to the Sampled Requests section.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717382306436/84e69940-1e30-4b93-be70-9f969b3da139.png" alt class="image--center mx-auto" /></p>
<p>We can see the sampled requests here.</p>
<p>Alright, let's delete the rule that we had set up.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717382392974/a7906e29-f4b8-41d2-b33f-03d4f020ee26.png" alt class="image--center mx-auto" /></p>
<p>On <strong>Associated AWS resources</strong> section, select your associated resources and click on <code>Disassociate</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717382456803/7bd13af1-6da4-4e3a-8681-3ba78180bbad.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717382482459/8f98cef5-5f65-4c99-8bfd-a5f4c3fe87f6.png" alt class="image--center mx-auto" /></p>
<p>On <strong>Web ACLs</strong>, select your Web ACL and click on <code>Delete</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717382967825/0bee544e-b7d6-4f54-828e-63449b89807d.png" alt class="image--center mx-auto" /></p>
<p>On <strong>IP sets</strong>, select your IP set and click on <code>Delete</code>.</p>
<p>Now, let's head up to our load balancer, copy the DNS name, and paste it into our browser to check if the restriction is still in place.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717382604862/2587d12e-0d21-4c74-ab66-263865bc86ec.png" alt class="image--center mx-auto" /></p>
<p>We can see that our request is no longer blocked.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717394220616/d91abb4b-bd23-4a13-94b3-a6664039e101.png" alt class="image--center mx-auto" /></p>
<p>Try refreshing the page to see if the load balancer distributes the traffic to different servers.</p>
<hr />
<h3 id="heading-conclusion">Conclusion</h3>
<p>Today, we used a technique to protect our resources using AWS WAF by blocking our own IP address using an IP set. This was a simple demonstration. There are many more powerful techniques available with AWS WAF to block web exploits, but that's for another project.</p>
<hr />
<h3 id="heading-task-10-clean-up">Task 10: Clean Up</h3>
<ol>
<li><p><strong>Deleting load balancer.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717383107967/979f5ef1-529c-46cc-89f0-fe3bd3fd3893.png" alt class="image--center mx-auto" /></p>
<p> Select your load balancer and in the <strong>Actions panel</strong>, click on <code>Delete load balancer</code>.</p>
</li>
<li><p><strong>Deleting Target Group.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717383185328/4eccfb4e-98ae-466f-9123-6e732f7fc0da.png" alt class="image--center mx-auto" /></p>
<p> Select your target group and in the <strong>Actions</strong> panel, click on <code>Delete</code>.</p>
</li>
<li><p><strong>Terminating EC2 instance.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717383428940/6edbea8c-502c-444c-9249-6e0829721220.png" alt class="image--center mx-auto" /></p>
<p> Select both of your instances, In <strong>Instance state</strong> panel, click on <code>Terminate instance</code>.</p>
</li>
<li><p><strong>Deleting Subnets.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717383267137/02b7f656-b576-4cd4-8a29-b43f38fe9eb3.png" alt class="image--center mx-auto" /></p>
<p> Search for <strong>VPC</strong> in the search box. On <strong>Subnets</strong>, select both of your subnets and in the <strong>Actions</strong>, panel, click on <code>Delete subnet</code>. If you can't delete, wait for some time, refresh the box and try again.</p>
</li>
<li><p><strong>Deleting Route table.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717384476298/0f25d876-4cfd-4d88-a959-6ba5b92beaa0.png" alt /></p>
<p> Select your Route table and in the <strong>Actions</strong> panel, click on <code>Delete route table</code>.</p>
</li>
<li><p><strong>Deleting VPC.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717384541026/ac96afb8-c802-430e-ac49-d522080829cf.png" alt class="image--center mx-auto" /></p>
<p> Select your VPC and in the <strong>Actions</strong> panel, click on <code>Delete VPC</code>.</p>
</li>
</ol>
<p>We've cleaned up our used resources.</p>
<hr />
<p>Alright, see you guys in the next one!</p>
]]></content:encoded></item><item><title><![CDATA[Auto Scaling Groups]]></title><description><![CDATA[Today we will learn about Auto Scaling Group.
Auto Scaling Groups (ASGs), as the name suggests, automatically adjust the number of EC2 instances in response to demand. They help ensure your application is both responsive and cost-effective by scaling...]]></description><link>https://sujanmagar.com.np/auto-scaling-groups</link><guid isPermaLink="true">https://sujanmagar.com.np/auto-scaling-groups</guid><category><![CDATA[AWS]]></category><category><![CDATA[autoscaling]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Sun, 02 Jun 2024 04:25:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1717302264727/5f5db6f2-f89d-4b1e-a370-9869f5b72f1d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today we will learn about Auto Scaling Group.</p>
<p>Auto Scaling Groups (ASGs), as the name suggests, automatically adjust the number of EC2 instances in response to demand. They help ensure your application is both responsive and cost-effective by scaling up during high traffic and scaling down during low traffic.</p>
<p>Let's get started.</p>
<hr />
<h3 id="heading-overview">Overview</h3>
<p>In this setup, we will create an Auto Scaling Group (ASG) to manage the provisioning and scaling of EC2 instances based on changing demand. The ASG will automatically adjust the number of instances in response to load fluctuations, ensuring optimal performance and cost-efficiency.</p>
<hr />
<h3 id="heading-task-1-creating-a-vpc">Task 1: Creating a VPC</h3>
<p>Search for <strong>VPC</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717208882238/3700954c-b274-4058-9843-33d924b5b6ff.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717208954537/8ec256a2-c375-4b7d-b04d-06caba404e68.png" alt class="image--center mx-auto" /></p>
<p>Provide a name for your VPC and input a CIDR range.</p>
<p>Keeping all other configurations default, click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717209052298/5ca7df13-2ce5-4520-9821-4f635147196f.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717299369291/09b6f635-0ce5-45c4-867d-2731ba2c2b70.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-2-creating-internet-gateway">Task 2: Creating Internet Gateway</h3>
<p>On <strong>Internet gateways</strong>, click on <code>Create internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717209124156/646ff0be-a47f-4895-8bed-50208f0df7d0.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717209171030/e59da978-52b4-46b7-9c2b-4ec2e766a5a4.png" alt class="image--center mx-auto" /></p>
<p>Provide a name for your Internet Gateway and click on <code>Create internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717209215189/05a492a2-0430-4488-90f8-256f630d1f87.png" alt class="image--center mx-auto" /></p>
<p>Attach the Internet Gateway to your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717210030148/a1a24053-7957-4e2c-9eea-0d7fa547c839.png" alt /></p>
<p>Now, we have attached an internet gateway to our VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717299469434/eaa3ec5e-e0f5-4290-b92e-61108385ba57.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-3-creating-subnets">Task 3: Creating Subnets</h3>
<p>On <strong>Subnets</strong>, click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717210167646/ab1ee8f4-61bc-4600-ab80-d2bfb26d446a.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717210202941/db8219be-c71f-43a7-b986-1caa2904b668.png" alt /></p>
<p>Select your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717210249053/0071dd31-ac69-4a8f-94b9-7e4c96312cce.png" alt /></p>
<p>Click on <code>Add new subnet</code> to create another subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717210308782/e447fea6-6ccb-4f58-a404-d32cc6050d8a.png" alt /></p>
<p>Click on <code>Create subnet</code>.</p>
<p>We have created two subnets in different AZs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717300036436/2416ce6d-7b18-4117-96fd-60f4b120a7b1.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-4-creating-route-table">Task 4: Creating Route table</h3>
<p>On <strong>Route tables</strong>, click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717256048988/7f72e6ef-2d15-4153-9441-5f9721732b28.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717256116882/bef1ce22-a123-4c42-940b-54266a76f16e.png" alt class="image--center mx-auto" /></p>
<p>Provide name for your route table, select your VPC and click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717256196411/c066c170-da8b-49a1-9ac4-9211c239f77b.png" alt class="image--center mx-auto" /></p>
<p>On <strong>Subnet associations,</strong> click on <code>Edit subnet associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717256229837/15af3322-984d-46ac-b82d-6e16136a6395.png" alt class="image--center mx-auto" /></p>
<p>Tick both of your subnets and click on <code>Save associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717256295615/821f7fc4-9968-4c6e-a6a5-8f49f3c2a350.png" alt class="image--center mx-auto" /></p>
<p>On <strong>Routes,</strong> click on <code>Edit routes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717256352593/2606ef93-96a9-4b6e-875c-ff82bfe729a5.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Add route</code> and configure above configurations.</p>
<p>Click on <code>Save changes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717301582449/0c272f74-92ec-4fac-b8e3-db2bc4d4cab5.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-5-creating-launch-template">Task 5: Creating Launch template</h3>
<p>Previously, launching EC2 instances involved manually configuring every detail for each launch. Launch templates simplify this process by offering a reusable definition - essentially a blueprint - that stores settings such as AMI, instance type, security groups, and more. This streamlines instance creation, enables straightforward configuration versioning, and maintains consistency across your deployments.</p>
<p>On <strong>EC2 dashboard</strong>, <strong>on Launch Templates</strong>, click on <code>Create launch template</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717207899386/bf3b48b2-cd03-42d3-bc00-5d03fac9b071.png" alt /></p>
<p>Provide a suitable name for your template.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717208621175/7e2d09d4-295d-4cdb-88d1-9660e8729b0c.png" alt class="image--center mx-auto" /></p>
<p>On <strong>Quick Start</strong>, choose Ubuntu as an AMI.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717208734807/3e843fbe-64ff-4d29-ae57-1d0e23c4dc71.png" alt class="image--center mx-auto" /></p>
<p>Choose instance type and either create or select your existing key pair.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717286778901/6148c882-81ea-46e8-91a6-a45cdd6cc394.png" alt /></p>
<p>In the <strong>Network settings</strong>, subnets are not selected. Instead, a Security Group is created for the instances. Select your VPC and add the inbound rules to your Security Group.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717257887623/df3b1943-b757-43f1-9634-d207c1333e5b.png" alt class="image--center mx-auto" /></p>
<p>In the <strong>Advanced network configuration</strong>, click on <code>Add network interface</code> and <code>Enable</code> the Auto-assign public IP option.</p>
<p>With all other configurations left as default, click on <code>Create launch template</code>.</p>
<hr />
<h3 id="heading-task-6-creating-auto-scaling-group">Task 6: Creating Auto Scaling Group</h3>
<p>On <strong>EC2 dashboard</strong>, scroll to bottom on Auto Scaling Groups.</p>
<p>Click on <code>Create Auto Scaling group</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717210908448/6f81e755-9d6e-4efc-bc56-41df763d1db1.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717210990649/2ccf7021-f8a2-426c-bf65-3b9fd0c8f50c.png" alt class="image--center mx-auto" /></p>
<p>Name your Auto Scaling Group and select the Launch template you created.</p>
<p>Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717211089128/23005314-e3de-4c4e-8ff9-90e2f8fc19e5.png" alt /></p>
<p>Select your VPC and choose your subnets.</p>
<p>Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717211154956/aa03b683-9cc6-413c-bd3a-74ed9dab07c1.png" alt class="image--center mx-auto" /></p>
<p>For this project, we are not going to associate a load balancer.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717211265566/67b282d2-515d-45ef-8a4e-1dc7fd71aa06.png" alt class="image--center mx-auto" /></p>
<p>The Health Check Grace Period gives new instances time to start up and become healthy before health checks start. This prevents instances from being incorrectly marked as unhealthy and terminated during startup. Setting a grace period allows instances to boot up, configure themselves, and start applications, leading to more stable scaling.</p>
<p><em>Determines how long to wait before starting health checks on a new instance.</em></p>
<p>With all other configurations set to default, click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717211856620/e4c74fd7-c681-4dea-95ac-d5160c6143d6.png" alt /></p>
<p>In normal operations, the Auto Scaling group keeps 2 instances running (<strong>Desired capacity</strong>). It can scale up to 3 instances in high traffic (<strong>Max desired capacity</strong>) but never goes below 1 instance in low traffic (<strong>Min desired capacity</strong>).</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717212328854/6efeb4e8-2e48-4fd5-9664-c1689d273f63.png" alt /></p>
<p>Scaling policies determine how the group responds to changes in demand. These policies are based on metrics like CPU utilization, network traffic, or custom CloudWatch alarms.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717213305239/2029ebf7-5c94-4b6d-9289-9b9824d9efbd.png" alt class="image--center mx-auto" /></p>
<p>By setting up these policies, we can ensure our application always has enough resources to handle traffic spikes, while also optimizing costs during quieter periods.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717258904315/eed34c51-433b-4396-ba40-9309be7fe1d1.png" alt /></p>
<p>The Target Tracking Scaling Policy in AWS Auto Scaling automatically adjusts the number of instances in a group <strong>to maintain a specific metric at a target value</strong>.</p>
<p>Instance warm-up refers to time before a new instance is included in scaling activities. It ensures the instance is fully operational before being counted.</p>
<p><em>Determines how long to wait before including a new instance in scaling decisions.</em></p>
<p>Our scaling policy adjusts the number of instances to maintain a 50% average CPU utilization. During high traffic, it adds instances to handle the load and maintains performance. During low traffic, it reduces instances to the minimum required, prioritizing cost optimization over meeting the 50% target.</p>
<p>Click on <code>Next</code>, keeping all other configurations default until you reach the option to <code>Create Auto Scaling group</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717242978275/f83377d7-bd40-40f7-8b65-808ef23ce97c.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717301496352/a264ea05-2fe4-4f7b-9fb0-3838a7831c09.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-7-exploring-auto-scaling-groups">Task 7: Exploring Auto Scaling groups</h3>
<p>Let's perform various actions on our Auto Scaling Groups.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717245499403/69d94995-24bf-4d53-841c-90891f200308.png" alt class="image--center mx-auto" /></p>
<p>Select your Auto Scaling group and click on the <strong>Activity</strong> section.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717287960416/0143ff1f-9071-4a3d-8ef8-54a214e12249.png" alt class="image--center mx-auto" /></p>
<p>Our Auto Scaling Group is currently launching instances.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717288032514/e8e7ca10-8787-4c57-8a99-5112a95f68d6.png" alt class="image--center mx-auto" /></p>
<p>The instances for our desired capacity have been launched.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717288079606/48e97823-2937-4a44-ae2d-3e798de38484.png" alt class="image--center mx-auto" /></p>
<p>We can see the instances in the Instances console.</p>
<p>Now, let's terminate one of the EC2 instances.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717288141187/b16c5dd0-eb3e-4a4d-a2ec-dd89ee054941.png" alt class="image--center mx-auto" /></p>
<p>Let's head up to the Auto Scaling Group's Activity section to see what happens next.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717288326785/bef15163-7774-4132-a854-47e3d76c2c06.png" alt class="image--center mx-auto" /></p>
<p>We can see our terminating instance while the Auto Scaling Group (ASG) is launching a new instance to reach our desired capacity.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717288422672/c28ebed3-194f-46af-a966-7abbadb27ec2.png" alt class="image--center mx-auto" /></p>
<p>In the meantime, an Auto Scaling Group terminated one EC2 instance. As there is currently no traffic, the ASG is operating efficiently by keeping only the minimum required resources running.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717288608075/3574f38c-9a2a-402c-b857-21f630fafb4c.png" alt class="image--center mx-auto" /></p>
<p>Now, click on the ID of your running instance, then navigate to the <strong>Monitoring section</strong>.</p>
<p>Enlarge the CPU utilization metric.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717260954272/8222954e-4465-4ce0-86eb-e284da802d2d.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717290038574/56268c3b-a063-4f47-bb73-95fe12b61e98.png" alt class="image--center mx-auto" /></p>
<p>Let's increase the CPU utilization.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717261040080/a79f2ff7-df15-4fb8-b10d-76c4f75d3196.png" alt class="image--center mx-auto" /></p>
<p>On your instance details, click on <code>Connect</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717290168642/e67e3f03-f2ef-4098-a7de-39b466c58b0a.png" alt /></p>
<p>On <strong>EC2 Instance Connect</strong>, click on <code>Connect</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717290266657/d00d3d38-ef4a-4f83-9b96-4e192d8ec887.png" alt class="image--center mx-auto" /></p>
<p>We're now connected to our instance.</p>
<p>Copy the command and paste into your terminal.</p>
<pre><code class="lang-bash">sudo apt-get update <span class="hljs-comment"># updating package lists</span>
sudo apt-get install stress -y <span class="hljs-comment"># installing stress</span>
</code></pre>
<ul>
<li>stress utility is used to simulate high CPU usage scenarios for testing and benchmarking purposes.</li>
</ul>
<p>And now it's time to spike the CPU utilization.</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Stress the CPU cores for 5 minutes</span>
stress --cpu $(nproc) --timeout 300
</code></pre>
<p>This command stresses all available CPU cores for 5 minutes using the <code>stress</code> tool. <code>$(nproc)</code> dynamically determines the number of CPU cores.</p>
<p>Let's check the CPU utilization metric of our instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717292729808/6aaea258-5320-41ce-89b7-2a9398f5249d.png" alt /></p>
<p>We can observe that the CPU utilization is increasing.</p>
<p>Now, let's check the Auto Scaling Group's Activity section to see if there are any changes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717292750255/0123e4a7-b23c-4bef-8640-062ef3d8f709.png" alt /></p>
<p>We can see that the Auto Scaling Group (ASG) has launched an instance in response to the increasing load.</p>
<p>As the CPU utilization continues to rise, as we have configured it to spike for 5 minutes, another instance is being launched by the Auto Scaling Group (ASG), and now we've reached our maximum EC2 limit as set by us.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717292764746/1ac88f68-94cd-4bb9-87e9-3bc22b461b2e.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717292942116/1ebdd45a-1a96-43b5-99d0-2856dcd08b24.png" alt class="image--center mx-auto" /></p>
<p>Let's go to the Instances list.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717292855956/225eaccb-4041-4930-8f73-f7605db26734.png" alt class="image--center mx-auto" /></p>
<p>We can see that 2 additional instances have been launched by ASG as the CPU utilization metric crossed the threshold that we had set.</p>
<p>And when the CPU utilization is low, a scale-in event will occur.</p>
<p>That's the beauty of Auto Scaling.</p>
<hr />
<h3 id="heading-conclusion">Conclusion</h3>
<p>We created an Auto Scaling Group with a minimum capacity of one instance, a desired capacity of two instances, and a maximum capacity of three instances. We observed both scale-in and scale-out events during the testing process. To stimulate CPU utilization, we used a stress utility tool.</p>
<hr />
<h3 id="heading-tasks-8-clean-up">Tasks 8: Clean Up</h3>
<ol>
<li><p><strong>Deleting Auto Scaling Group</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717293818975/8a0a1b3d-728e-4a72-b1d4-7f3c0e24b5f2.png" alt class="image--center mx-auto" /></p>
<p> Select your Auto Scaling Group, and in the <strong>Actions panel</strong>, click on <code>Delete</code>.</p>
</li>
<li><p><strong>Deleting Launch Template</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717293889155/a4c020b8-028b-4956-a51d-a8e757c96a3b.png" alt class="image--center mx-auto" /></p>
<p> Select your Launch Template and in <strong>Actions panel</strong>, click on <code>Delete template</code>.</p>
</li>
<li><p><strong>Deleting Subnet</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717294027713/86b72cd4-e382-467f-ab65-8dd84b83ef50.png" alt class="image--center mx-auto" /></p>
<p> Go to the VPC Dashboard. In the <strong>Subnets</strong> section, select both of your subnets, and in the <strong>Actions panel</strong>, click on <code>Delete subnet</code>.</p>
</li>
<li><p><strong>Deleting Route Table</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717294114664/b802109f-f6a8-4cab-974f-766ba0667613.png" alt class="image--center mx-auto" /></p>
<p> Select your route table, and in the <strong>Actions panel</strong>, click on <code>Delete route table</code>. If you're unable to do so, try refreshing the box.</p>
</li>
<li><p><strong>Deleting Internet Gateway &amp; VPC</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717294236374/2a6becb4-33db-437c-85ba-916d01e1ba64.png" alt class="image--center mx-auto" /></p>
<p> Select your VPC and in the <strong>Actions</strong> panel, click on <code>Delete VPC</code>.</p>
<p> Deleting the VPC will also delete the internet gateway associated with it.</p>
</li>
</ol>
<p>We have now cleaned up our used resources.</p>
<hr />
<p>Alright! See you next time!</p>
]]></content:encoded></item><item><title><![CDATA[Application Load Balancer]]></title><description><![CDATA[Today, we will learn about the Application Load Balancer (ALB).

An Application Load Balancer distributes incoming application traffic across multiple targets, such as EC2 instances, containers, and IP addresses. Operating at the application layer (O...]]></description><link>https://sujanmagar.com.np/application-load-balancer</link><guid isPermaLink="true">https://sujanmagar.com.np/application-load-balancer</guid><category><![CDATA[AWS]]></category><category><![CDATA[Load Balancer]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Fri, 31 May 2024 03:22:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1717125735148/180d67cb-5547-46ac-bc26-cd49d469d393.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today, we will learn about the Application Load Balancer (ALB).</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717121944694/3807ab5f-eb94-42c1-89b9-a7662d4bb1eb.png" alt class="image--center mx-auto" /></p>
<p>An Application Load Balancer distributes incoming application traffic across multiple targets, such as EC2 instances, containers, and IP addresses. Operating at the application layer (OSI layer 7), ALB is ideal for HTTP and HTTPS traffic. It offers advanced routing, integrates with AWS services, and includes features like user authentication and WebSocket support, ensuring high availability and reliability for modern applications.</p>
<hr />
<h3 id="heading-overview">Overview</h3>
<p>In this setup, we will create two EC2 instances in different subnets within a VPC. We will then configure an Application Load Balancer (ALB) to distribute incoming traffic across these instances. The ALB will serve as the entry point for all traffic and will route requests to the targets.</p>
<hr />
<h3 id="heading-task-1-creating-a-vpc">Task 1: Creating a VPC</h3>
<p>Search for <strong>VPC</strong> and click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717035749546/1d94401a-af19-47a4-96a3-29b8c96c047b.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717035814350/6b2be349-13cb-4b34-b9ae-0edac0eec5ca.png" alt class="image--center mx-auto" /></p>
<p>Provide a name for your VPC and input a CIDR value for your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717035901248/fab65679-46e1-41cd-8d0f-6ed00ee36f9c.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717122104962/509c1e80-4b75-425d-a242-07eedfdad1a2.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-2-creating-internet-gateway">Task 2: Creating Internet Gateway</h3>
<p>On <strong>Internet gateways</strong>, click on <code>Create internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717035949718/c33e1f86-3505-497f-9aa9-f8417c563b6f.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717035990856/e05384a5-5b3b-4900-89f4-d328f4c35b21.png" alt class="image--center mx-auto" /></p>
<p>After creating an internet gateway, it's time to attach it to our VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717036044484/48d68c01-3bbf-40f0-b888-acc872351f56.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717036073296/a5ba9dad-1a73-49cf-936e-7bfaee9b2c9f.png" alt class="image--center mx-auto" /></p>
<p>Select your VPC and click on <code>Attach internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717122191893/116d9679-5706-4d57-b70f-3ec41c698a5a.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-3-creating-subnets">Task 3: Creating Subnets</h3>
<p>On <strong>Subnets</strong>, click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717036775406/5e37f320-6def-4040-8ab5-fa02d478cbb4.png" alt class="image--center mx-auto" /></p>
<p>Select your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717036864362/a18d3658-704d-4719-b3bf-7f63d05ea0eb.png" alt class="image--center mx-auto" /></p>
<p>Provide a name for your subnet, choose AZ and input an eligible CIDR range.</p>
<p>For this project, we are picking different AZs.</p>
<p>Create another subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717036961524/7cc561c1-85f7-4b4f-b5af-41823403af50.png" alt class="image--center mx-auto" /></p>
<p>Once you are done, click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717037023151/561fae64-6561-4627-9bbd-9edd049cac54.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717123658973/6009bc84-9a41-44a1-83f6-ef5cba7add39.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-4-creating-route-tables">Task 4: Creating Route tables</h3>
<p>On <strong>Route tables</strong>, click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717037086241/f2d0d568-8cd0-4a17-9617-1ce716c15e35.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717040222703/0ab0738b-8252-43c6-b658-13a146f1e913.png" alt class="image--center mx-auto" /></p>
<p>Provide name for your route table, select your VPC &amp; click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717040313776/018652ed-13f6-413d-9e59-a2d51667e4d8.png" alt class="image--center mx-auto" /></p>
<p>After creating route table, On <strong>Subnet associations</strong>, click on <code>Edit subnet associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717040375495/11a43d21-9ec8-4751-b629-be9f7ddd1367.png" alt class="image--center mx-auto" /></p>
<p>Tick both of your subnets and click on <code>Save associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717040457171/1a1d0da1-2aa6-4b90-80ef-844cde43308a.png" alt class="image--center mx-auto" /></p>
<p>Now on <strong>Routes</strong>, click on <code>Edit routes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717040488180/a6b7af67-f5d2-47a8-a773-228ab798504f.png" alt class="image--center mx-auto" /></p>
<p>Add route, select your internet gateway and click on <code>Save changes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717040569336/3f26ca20-2136-40db-8368-7080c30cee4c.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717123727966/ee847218-dc72-480b-aef4-8621913fd784.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-5-creating-ec2-instances">Task 5: Creating EC2 Instances</h3>
<p>Search for <strong>EC2</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717041285495/8667a9af-ad62-43b5-85e4-b1da944f64ba.png" alt class="image--center mx-auto" /></p>
<p>On EC2 dashboard, click on <code>Launch instance</code>.</p>
<p>Provide a name for your EC2, select an AMI, create or use an existing key pair.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717041624118/40beae85-0ce0-4d7c-b487-a3c0b2c34d5a.png" alt class="image--center mx-auto" /></p>
<p>Edit Network settings. Select your VPC, select your subnet and <code>Enable</code> Auto-assign public IP.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717041699521/d7a11f4d-1545-4896-be8d-d4ff8531ea4f.png" alt class="image--center mx-auto" /></p>
<p>We are provided with a default security group that has SSH configuration.</p>
<p>Now, let's add another security group rule to allow HTTP traffic to our instance.</p>
<p>Click on <code>Add security group rule</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717041814491/5edbf381-06cc-45ea-921c-93ec3b14b6ee.png" alt class="image--center mx-auto" /></p>
<p>Configure the above settings in your new security group rule.</p>
<p>Now, at the bottom, click <strong>Advanced Details</strong> to see more options.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717041932511/167505f5-ae75-4b10-91db-02e8e4b7ad18.png" alt /></p>
<p>On <strong>User data</strong> section, provide the following code:</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>
yes | sudo apt update
yes | sudo apt install apache2
<span class="hljs-built_in">echo</span> <span class="hljs-string">"&lt;h1&gt;Hello from the first server&lt;/h1&gt;"</span> &gt; /var/www/html/index.html
sudo systemctl restart apache2
</code></pre>
<details><summary>Code Explained</summary><div data-type="detailsContent">This script sets up the Apache web server and serves a simple HTML page with the message "Hello from the first server".</div></details>

<p>User data in EC2 instances refers to a script or set of commands you can provide when launching an instance. This script runs automatically when the instance starts for the first time. This process is known as <strong>bootstrapping</strong>.</p>
<p>User data automates the setup of EC2 instances, saving time and ensuring consistency by automatically installing software and configuring settings when the instance starts, eliminating manual tasks.</p>
<p>But for now, we are just displaying <strong>Hello</strong> message.</p>
<p>Click on <code>Launch instance</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717061093900/a0fc032b-b436-426c-bebd-fdb6ce22c2ac.png" alt class="image--center mx-auto" /></p>
<p>After your instance is up and running, go to the instance details, copy the Public IPv4 address, open a new tab, and paste the address there.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717061207481/3a2028c3-0387-4dae-a773-98b25d5992de.png" alt class="image--center mx-auto" /></p>
<p>You may see something like this.</p>
<p>Now, let's create another instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717061327937/27fd86d0-83fc-4d35-8428-a250ff669371.png" alt class="image--center mx-auto" /></p>
<p>On <strong>Network settings</strong>, for subnet, choose another subnet than you chose earlier.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717061402390/e2b14f27-f166-4a43-867b-8c2ad90fe35f.png" alt class="image--center mx-auto" /></p>
<p>Now add additional inbound rules like we did earlier.</p>
<p>For <strong>User data</strong>, add the following script:</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>
yes | sudo apt update
yes | sudo apt install apache2
<span class="hljs-built_in">echo</span> <span class="hljs-string">"&lt;h1&gt;Hello from the second server&lt;/h1&gt;"</span> &gt; /var/www/html/index.html
sudo systemctl restart apache2
</code></pre>
<p>And all the procedures are the same, and we get this.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717062993815/aebdfc07-8212-4a11-a675-1b980d85d26c.png" alt class="image--center mx-auto" /></p>
<p>We have created two instances.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717063145387/775f3c53-b086-4485-a330-28653384deb1.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717124529476/fd24958e-b6e7-4535-afac-fdc1b518e713.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-6-create-a-target-group">Task 6: Create a Target Group</h3>
<p>A target group is a set of resources that a load balancer routes traffic to. It ensures efficient traffic distribution and high availability by routing only to healthy targets. Target groups also support configuring rules to direct traffic based on specific conditions, helping manage and scale applications effectively.</p>
<p>On EC2 dashboard, scroll down to <strong>Target Groups</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717063403032/4cfa77c2-b374-4a4b-9163-1b4d943260fc.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Create target group</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717064226339/8781a6bd-b135-402e-ade2-85bf218531aa.png" alt class="image--center mx-auto" /></p>
<p>Provide a name for your target group and select your VPC, keeping all other configurations as default.</p>
<p>Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717064331564/6bbcc0ac-01bb-4660-a78a-aa40e5b7e21f.png" alt class="image--center mx-auto" /></p>
<p>Select both of your instances and click on <code>Include as pending below</code>.</p>
<p>This option allows you to add targets to a target group in a <strong>non-active state</strong> initially. These targets won't receive traffic from the ALB until they pass the configured health checks.</p>
<p>Click on <code>Create target group</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717079708458/97443a11-e884-4fdf-ba88-cad9aa24801d.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717122959084/79a22960-7c8d-4439-9e03-77c9a2057bec.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717125010247/fc2f6cda-9cd7-4023-8316-3c09caa236f2.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-7-creating-security-group">Task 7: Creating Security Group</h3>
<p>Security Groups (SGs) act as virtual firewalls for your instances to control inbound and outbound traffic. You can define rules to allow or deny specific traffic based on IP addresses, ports, and protocols. Security Groups are stateful, meaning if you allow an inbound request, the response is automatically allowed.</p>
<p>Let's create security group for our Load Balancer.</p>
<p>On EC2 dashboard, on <strong>Security Groups</strong>, click on <code>Create security group</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717079922216/e5c1dc17-0c17-48c8-85db-aa457c1cff7a.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717080006391/e1772bcb-1910-483d-8778-302208abe42f.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable name, description is optional &amp; select your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717080206600/cf712e30-e2c3-4765-873e-62575bcedc63.png" alt class="image--center mx-auto" /></p>
<p>On Inbound rules, click on <code>Add rule</code> to configure above configurations.</p>
<p>We're allowing HTTP traffic from anywhere on the internet.</p>
<p>Click on <code>Create security group</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717080265718/b44b896a-dc0c-424a-93e1-69006a57636d.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-8-creating-load-balancer">Task 8: Creating Load Balancer</h3>
<p>A Load Balancer (LB) distributes incoming traffic across multiple targets, such as EC2 instances, to ensure high availability and reliability. It helps balance the load, improving application performance and fault tolerance. There are different types of load balancers, including Application Load Balancer (ALB) for HTTP/HTTPS traffic and Network Load Balancer (NLB) for TCP/UDP traffic.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717080417541/0cc96121-eff8-46bd-9ec6-10f5e947fea7.png" alt class="image--center mx-auto" /></p>
<p>On EC2 dashboard, On <strong>Load Balancer</strong>, click on <code>Create load balancer</code>.</p>
<p>Choose ALB as the load balancer and click on <code>Create</code>.</p>
<p>Provide a name for your ALB.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717080732544/e4f21089-daa4-4d99-9cb1-44b5980c9808.png" alt class="image--center mx-auto" /></p>
<p>When you create a load balancer, you must decide whether to make it an internal load balancer or an internet-facing load balancer.</p>
<p>The nodes of an internet-facing load balancer have public IP addresses.</p>
<p>The nodes of an internal load balancer have only private IP addresses.</p>
<p>Both internet-facing and internal load balancers route requests to your targets using private IP addresses.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717080892075/28c24814-0b3d-4a7c-9b08-5dd1bab89922.png" alt class="image--center mx-auto" /></p>
<p>Select your VPC and tick on your AZs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717080985619/c020842b-c20f-4e1a-a56b-e9f6355946d3.png" alt class="image--center mx-auto" /></p>
<p>In addition to the default security group, select the security group that we created earlier for this load balancer.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717081087646/134e85a9-f746-421f-8a79-788b4032de95.png" alt class="image--center mx-auto" /></p>
<p>A listener is responsible for checking or listening for incoming connection requests on a specified protocol and port, such as HTTP on port 80 or HTTPS on port 443. Once a listener accepts a connection, it uses routing rules to determine how to direct the traffic.</p>
<p>These rules can route traffic based on hostnames, URL paths, HTTP headers, or query string parameters. The traffic is then forwarded to the appropriate target group.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717081146101/9f13e4ed-2aba-4ac6-8049-36f8393624b1.png" alt class="image--center mx-auto" /></p>
<p>You can read a summary about your Application Load Balancer.</p>
<p>Click on <code>Create load balancer</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717081219679/afee87ab-3a01-4a66-adf1-b7fc3b039118.png" alt class="image--center mx-auto" /></p>
<p>Let's wait for a while. It may take 3 to 4 minutes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717081378748/426dc27d-fbf2-4595-85a5-9ab4c60104f4.png" alt class="image--center mx-auto" /></p>
<p>After a few minutes, our ALB is active. Copy the DNS name of your ALB and paste it into your browser.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717081440457/727174bf-ec9a-4122-affb-25203821a7c0.png" alt class="image--center mx-auto" /></p>
<p>Try refreshing the browser.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717081466094/97d85aae-a6ff-47fa-8996-e554ab736031.png" alt class="image--center mx-auto" /></p>
<p>Our ALB is actively distributing traffic to the targets we set up.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717125308673/24d0abde-2458-4347-b339-2689bbd7bd3e.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-conclusion">Conclusion</h3>
<p>We have successfully set up an Application Load Balancer (ALB) to distribute traffic, improving our application's availability and reliability. We added two EC2 instances as targets and configured the ALB to direct traffic to them.</p>
<hr />
<h3 id="heading-task-9-clean-up">Task 9: Clean Up</h3>
<ol>
<li><p><strong>Deleting Load Balancer</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717084402990/351d1c7c-d0f3-47ce-8730-d283db266249.png" alt class="image--center mx-auto" /></p>
<p> Select your load balancer and on <strong>Actions panel</strong>, click on <code>Delete load balancer</code>.</p>
</li>
<li><p><strong>Deleting Target Group</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717084505833/2f9a8b37-6cf8-4428-8104-dfead5315c9d.png" alt class="image--center mx-auto" /></p>
<p> Select your target groups and click on <code>Delete</code>.</p>
</li>
<li><p><strong>Terminating instances</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717084604420/9b49ce83-df23-49f4-ade2-6331b492745f.png" alt class="image--center mx-auto" /></p>
<p> Select both of your instances and click on <code>Terminate instance</code>.</p>
</li>
<li><p><strong>Deleting Subnets</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717084698271/dab9c734-5a5a-4b3c-afb4-ee9d7af147ee.png" alt class="image--center mx-auto" /></p>
<p> Search for <code>VPC</code> in the search box and click on VPC.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717084784982/8c0f3116-76cb-4fb5-9edb-1ab69840ded7.png" alt class="image--center mx-auto" /></p>
<p> After navigating to the VPC dashboard, select both of your subnets under <strong>Subnets</strong> and click on <code>Delete subnet</code>.</p>
</li>
<li><p><strong>Deleting Route tables</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717084875009/5b39406e-69e6-49bb-9138-cc50db538894.png" alt class="image--center mx-auto" /></p>
<p> Select your Route table and in <strong>Actions panel</strong>, click on <code>Delete route table</code>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717084950667/2f0dc5eb-395a-4e40-aa63-eac9d2ba814e.png" alt class="image--center mx-auto" /></p>
<p> If an error occurs, try refreshing the box and then click on <code>Delete</code>.</p>
</li>
<li><p><strong>Deleting VPC</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717085061970/4752dd09-51d3-42d2-b7fa-92085bea5c8b.png" alt class="image--center mx-auto" /></p>
<p> Select your VPC and click on <code>Delete VPC</code>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717085117263/41e8b645-13c7-4f7f-81d0-0069bb214dd6.png" alt class="image--center mx-auto" /></p>
<p> This action will also delete our Internet Gateway. Alternatively, we could perform these actions individually.</p>
</li>
</ol>
<p>We have successfully cleaned up the resources that were in use.</p>
<hr />
<p>Hope you enjoyed the project!</p>
<p>I'll see you in the next one!</p>
]]></content:encoded></item><item><title><![CDATA[Bastion Host]]></title><description><![CDATA[Today, we'll create a Bastion Host, a secure gateway, in our Virtual Private Cloud (VPC). This host will act as a bridge, allowing us to securely access our private instances located in the VPC's private subnet.
Let's dive in right away.

Analogy
A b...]]></description><link>https://sujanmagar.com.np/bastion-host</link><guid isPermaLink="true">https://sujanmagar.com.np/bastion-host</guid><category><![CDATA[AWS]]></category><category><![CDATA[Bastion Hosts]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Thu, 30 May 2024 00:15:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1716990663805/a23da314-bd2b-4705-a7be-99ca0e9bd5b0.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today, we'll create a Bastion Host, a secure gateway, in our Virtual Private Cloud (VPC). This host will act as a bridge, allowing us to securely access our private instances located in the VPC's private subnet.</p>
<p>Let's dive in right away.</p>
<hr />
<h3 id="heading-analogy">Analogy</h3>
<p>A bastion host is like a secure gatekeeper for your network, ensuring no one can bypass it to get inside. It checks everyone's identity and keeps a record of all entries, allowing only authorized users. With minimal features to reduce risks, it is well-protected against attacks, acting like a vigilant gatekeeper monitoring and controlling access to the castle.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716987047248/252564ec-e7b1-41e4-af32-9ecb15cfd41c.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-1-create-a-vpc">Task 1: Create a VPC</h3>
<p>Search for <strong>VPC</strong> in the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716950280998/1252a27b-0427-4ba2-8bc5-91f40f8bf8c6.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716950395854/b0b3e8ae-9af6-4e94-ac09-a68754a68577.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable name for your VPC and provide CIDR range.</p>
<p>Leaving all other configurations as default, Click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716950486711/784e53fb-b982-4707-9f84-baf6a338da8b.png" alt class="image--center mx-auto" /></p>
<p>Our VPC is created.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716987449164/c8e6857b-4cf5-47d1-8c53-61791c05c92b.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-2-creating-an-internet-gateway">Task 2: Creating an Internet Gateway</h3>
<p>Internet Gateway to provide our VPC internet access.</p>
<p>On the VPC dashboard, <strong>On Internet gateways</strong>, click on <code>Create Internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716950564132/0feeea5f-8cdd-4243-acc0-ebaec5047535.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716950705596/b9083f60-4fbb-4596-aa5f-5f73a0187bc2.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable name for your IG and click on <code>Create internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716950752148/8fda38c1-22d7-4ce6-9062-11e55cf48144.png" alt class="image--center mx-auto" /></p>
<p>Now, we have to attach it to our VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716950787079/2bd22309-db1c-4de7-8981-f7d4b19c1bfe.png" alt class="image--center mx-auto" /></p>
<p>Select your VPC and click on <code>Attach internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716987556567/82e0586e-9fbb-487e-81da-726ec408d4e5.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-3-creating-subnets">Task 3: Creating Subnets</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716950960041/43bcefa7-5fa2-4bc6-b2ed-f34540e3b267.png" alt class="image--center mx-auto" /></p>
<p>On the VPC dashboard, On <strong>Subnets</strong>, click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716950995399/c65abfb8-af36-4aa1-b13f-eaf449fd01ed.png" alt class="image--center mx-auto" /></p>
<p>Select your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716951039344/56094164-ecdc-4a54-a991-af5609762415.png" alt class="image--center mx-auto" /></p>
<p>First, we are going to create Public subnet. Provide a suitable name for your subnet and an eligible CIDR range.</p>
<p>For this project, we're only using single Availability Zone.</p>
<p>Click on <code>Add new subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716951215930/ef673ec3-57ec-495c-89a9-922903edeb7b.png" alt class="image--center mx-auto" /></p>
<p>Now, we'll set up our Private subnet. Provide a suitable name, choose the AZ and an eligible CIDR range.</p>
<p>Click on <code>Create subnet</code>.</p>
<p>We've successfully created two subnets.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716951346417/891b9f56-ad1b-479b-a1b0-89d552be6df7.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716989530514/b3ad263c-bdff-4b9b-9ab2-2c346d12c398.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-4-creating-route-tables">Task 4: Creating Route Tables</h3>
<p>On VPC dashboard, On <strong>Route tables</strong>, click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716951412917/f9678549-f5f0-4497-9808-f4e77fbba248.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716951761665/51dd2ce4-e3ad-4b7a-9048-66c7d28f3acb.png" alt class="image--center mx-auto" /></p>
<p>Provide name for your route table, select your VPC and click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716951825409/303c7b17-fde7-4a9b-a60b-12915764e9d4.png" alt class="image--center mx-auto" /></p>
<p>After creating route table, on <strong>Subnet associations</strong>, click on <code>Edit subnet associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716951887618/5ed2d60c-0076-47d6-8179-ba79d92bd9b4.png" alt class="image--center mx-auto" /></p>
<p>Tick your Public subnet and click on <code>Save associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716951930171/65b25406-59f7-460c-a1d1-b7f3789dc13f.png" alt class="image--center mx-auto" /></p>
<p>Now, Click on <code>Edit routes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716951963429/5acb8853-0461-418e-a09f-4fd1402a629c.png" alt class="image--center mx-auto" /></p>
<p>Add route and configure the above configurations. Select your Internet Gateway and click on <code>Save changes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716952051474/7479f0c8-9e59-4fc7-8974-32edaabed52f.png" alt class="image--center mx-auto" /></p>
<p>The Public subnet can access the Internet now.</p>
<p>Now, it's time to set up our Private subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716952179179/01616b83-f65a-4016-87e7-9acd3ab77718.png" alt class="image--center mx-auto" /></p>
<p>Provide name for your Private route table and select your VPC and click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716952237272/862f0380-9ecf-4e00-a2c2-1c038ebf3159.png" alt class="image--center mx-auto" /></p>
<p>On <strong>Subnet associations</strong>, click on <code>Edit subnet associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716952283253/b66cf4d4-5b3f-4764-a66d-04c9f0995732.png" alt class="image--center mx-auto" /></p>
<p>Tick your Private subnet and click on <code>Save associations</code>.</p>
<p>For this Private route table, we do not have to configure any additional routes.</p>
<p>The route table entry <code>10.0.0.0/16</code> with the target <code>local</code> indicates that traffic within this IP range is allowed to communicate within the VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716989755109/40f0c621-7413-4d5f-8141-a594c57e11fb.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-5-creating-ec2-instances">Task 5: Creating EC2 instances</h3>
<p>Search for <strong>EC2</strong> on the search box.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716952457857/ec9d4371-8e6d-4ca8-ad24-6396ec4d4978.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716952501367/f0faf5ea-915b-4a86-8a56-65d9e4ca30b3.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Launch instance</code>.</p>
<p>We'll create our Bastion Host first.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716952588957/b9b20f69-1093-4820-b529-d7d79b719f7f.png" alt class="image--center mx-auto" /></p>
<p>Provide name for your Bastion Host, select <strong>Ubuntu</strong> as an AMI, choose free tier instance if available.</p>
<p>Create a new key pair.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716952674272/dddd1f3e-d52b-4398-8060-75b5dded632c.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716952719376/26ab633f-889b-4ebd-ac47-e9a3f8d1b086.png" alt class="image--center mx-auto" /></p>
<p>Edit Network settings. Select your VPC, choose your Public subnet and Enable Auto-assign public IP.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716952782976/bf824f1b-a310-41b7-bb8b-25ed11d26915.png" alt class="image--center mx-auto" /></p>
<p>By default, we're provided with an Inbound Security Group Rules.</p>
<p>We can SSH into this instance from anywhere on the internet.</p>
<p>Leaving all other configurations as default, click on <code>Launch instance</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716952953211/2f29b627-3ae8-4044-9658-966727d25aa6.png" alt class="image--center mx-auto" /></p>
<p>Now, let's create Private instance. Click on <code>Launch instances</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716953024855/bd4fd9f7-c526-4d21-a02f-3cd8c4e8df90.png" alt class="image--center mx-auto" /></p>
<p>Provide a name for your instance, select your AMI, select the instance type, and create a new key pair. You can also use an existing key pair that was created earlier.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716953134878/9f3089d2-7499-48f2-89d3-0ae2d573a561.png" alt class="image--center mx-auto" /></p>
<p>I'm creating separate keys for different instances.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716953186667/85a6ad58-1367-4834-87d3-5d694fc4d6dd.png" alt class="image--center mx-auto" /></p>
<p>Edit Network Settings. Select your VPC, choose your Private subnet and leave Auto-assign public IP as default.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716953253200/53583eb4-a4b6-4f77-8440-f4d080578ba7.png" alt class="image--center mx-auto" /></p>
<p>In the Inbound Security Group Rules, the Source type should not be set to "Anywhere." We must configure it to allow SSH access only from the resources that resides in our Public subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716953381935/130de17a-6a22-49b7-800f-3f1b6c0e817d.png" alt class="image--center mx-auto" /></p>
<p>This ensures that only instances within the Public subnet can SSH into the instance.</p>
<p>Leave all other configurations as default and Click on <code>Launch instance</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716953545112/92a990ed-9175-406c-a02b-3bebc23239cb.png" alt class="image--center mx-auto" /></p>
<p>We've created two instances.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716989865490/6b907e39-0cd1-49f3-be84-ab0fae522d81.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-6-ssh-into-our-bastion-host">Task 6: SSH into our Bastion Host</h3>
<p>Select your Bastion Host and now click on <code>Connect</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716953647542/2b362202-5db7-4a64-a3fa-da117f8afb3d.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716953727510/4f289b53-5986-4d8f-a457-d40dd400320d.png" alt class="image--center mx-auto" /></p>
<p>On SSH client, we have to follow some steps shown there.</p>
<p>I'm in my SSH client, i.e., terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716953804573/ea9c33eb-4f21-4b41-9de3-fce1bde811a3.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716953845938/485a2519-1391-4fdb-b7d9-8a0951d00763.png" alt class="image--center mx-auto" /></p>
<p>Copy the command and paste into your terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716988013063/639ca9a0-9bac-4296-9ab0-a2352fd5de89.png" alt class="image--center mx-auto" /></p>
<p>You can view your permissions using the following command:</p>
<pre><code class="lang-bash">ls -l
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716961708419/fcc444ef-9fea-4145-8db7-eb43b425673d.png" alt class="image--center mx-auto" /></p>
<p>We have changed the file permissions to make it readable by the owner only.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716954002059/225521a7-83bd-4ee6-9e3f-1bef6e906e57.png" alt class="image--center mx-auto" /></p>
<p>Copy the command &amp; paste into your terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716954044575/9a8fa7e2-5ad5-49aa-8276-8a66a3c97fb8.png" alt class="image--center mx-auto" /></p>
<p>Make sure your key file is present in your working directory; otherwise, provide the full path to the key file.</p>
<p>Proceed with <code>yes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716954170848/36c19d31-636e-4372-b3e9-736e44545fdc.png" alt class="image--center mx-auto" /></p>
<p>Now, we have logged into our instance using SSH.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716989964466/fe9670dc-2bf7-4c73-aa94-2096a242a471.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-7-copying-the-key-file">Task 7: Copying the Key File</h3>
<p>Open new terminal in your <strong>local computer</strong>.</p>
<p>We're copying the private key file that is in our local computer to our Bastion Host.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716958263649/060442cd-d166-479b-ad86-7914abc74290.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716960314059/dd0153c1-2e4c-43f2-a25c-3706bac3761a.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-bash">ssh -i <span class="hljs-string">"myKey.pem"</span> ubuntu@3.83.154.159
</code></pre>
<p>For ease, copy the command that we use to SSH into our instance. It's so to modify it a bit.</p>
<p>Paste the command in your <strong>Desktop's</strong> terminal.</p>
<pre><code class="lang-bash">scp -i <span class="hljs-string">"myKey.pem"</span> privateKey.pem ubuntu@3.83.154.159:/path/to/destination/
</code></pre>
<p>Replace and add commands/configurations as required.</p>
<p>Here's a breakdown of the command:</p>
<ul>
<li><p><code>scp</code> stands for Secure Copy. It is a command-line utility that allows you to securely copy files and directories between two locations.</p>
</li>
<li><p><code>-i my-key.pem</code>: Specifies the identity file (private key) to use for <strong>authentication</strong>.</p>
</li>
<li><p><code>privateKey.pem</code>: Specifies the source file on your local machine that you want to copy.</p>
</li>
<li><p><code>ubuntu@3.83.154.159:/path/to/destination/</code>: Specifies the destination on the remote</p>
</li>
</ul>
<p>Alright.</p>
<p>To see your present working directory, In your <strong>Bastion terminal</strong>, type command:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">pwd</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716961158200/3c0d62be-6880-41dd-8689-0e605ba47cc6.png" alt /></p>
<p>Now, replace the <code>/path/to/destination/</code> with your pwd location in your <strong>Desktop's</strong> terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716960733542/43f78eba-afaa-40e3-a7dc-457394c05835.png" alt class="image--center mx-auto" /></p>
<p>Now see if the key has been successfully copied into our Bastion Host by listing files/folders in our <strong>Bastion's</strong> terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716961422760/fc7616f6-a0cc-4b11-9d56-6fb0b1279c9c.png" alt /></p>
<p>We can see that the private key has been copied from our local computer to the remote instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716990122325/38234f5a-5b42-400f-a2e2-d0bf81f77c05.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-8-ssh-login-to-private-instance">Task 8: SSH Login to Private Instance</h3>
<p>It's time to SSH log in into our Private instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716962077383/8280fe9a-99a9-4a50-bc52-1b5d4d167034.png" alt class="image--center mx-auto" /></p>
<p>Select your Private instance and click on <code>Connect</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716962113686/ea483a52-c68c-404c-a596-000d93252ba6.png" alt class="image--center mx-auto" /></p>
<p>Copy the command.</p>
<p>But before that, let's see what permissions are set initially,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716962201158/989a1b71-b9c5-4146-ae7e-3080c4252cc0.png" alt class="image--center mx-auto" /></p>
<p>We can see there are <code>read/write</code> for <strong>Owner</strong>, <code>read/write</code> for <strong>Group</strong> &amp; <code>read</code> permissions for <strong>Others</strong>.</p>
<p>It is recommended to set the permissions of the file or directory to the minimum necessary for the required operations.</p>
<p>So, let's do that.</p>
<p>Paste the command that you had copied into the <strong>Bastion's</strong> terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716962446213/a95ee1ac-ae50-4cf4-b0f0-1d77a55ebef3.png" alt class="image--center mx-auto" /></p>
<p>We can see the file permissions have been changed now.</p>
<p>Now, copy the SSH command.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716962495845/34577337-9deb-4fab-9413-0a7af036b814.png" alt class="image--center mx-auto" /></p>
<p>Paste into your terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716962570893/735438d0-919c-4f40-bcd7-9951cf34d7a4.png" alt class="image--center mx-auto" /></p>
<p>Proceed with <code>yes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716962623157/3ea136a7-aea0-4461-9fb2-637c8d127473.png" alt class="image--center mx-auto" /></p>
<p>Now we are into our Private instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716962674769/d8dd29a5-4374-487d-ab94-7adf168c3afb.png" alt class="image--center mx-auto" /></p>
<p>You can verify this by examining the details in the instance configurations.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716990233847/bb1b8f3f-6619-4e7a-9ede-0b17d50d040f.png" alt class="image--center mx-auto" /></p>
<p>Alright, that's our work done.</p>
<hr />
<h3 id="heading-conclusion">Conclusion</h3>
<p>This configuration helps keep our Private instance secure by limiting direct access from the internet. Instead, we can access it securely through the Bastion host. This setup is a common practice for enhancing security in cloud environments.</p>
<hr />
<h3 id="heading-task-8-clean-up">Task 8: Clean Up</h3>
<ol>
<li><p><strong>Terminating instances.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716962908793/9b29e8a3-4aed-47c4-9c9b-101b3b30460f.png" alt class="image--center mx-auto" /></p>
<p> Select both of your instances, on <strong>Instance state</strong>, click on <code>Terminate instance</code>.</p>
</li>
<li><p><strong>Deleting Route tables.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716962908793/9b29e8a3-4aed-47c4-9c9b-101b3b30460f.png" alt /></p>
<p> Search for <strong>VPC</strong> in the search box.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716963093734/568e641a-8fc8-4b6d-b92a-b18803c12fef.png" alt class="image--center mx-auto" /></p>
<p> On Route tables <strong>Subnet associations</strong>, click on <code>Edit subnet associations</code>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716963152693/b426aeae-266c-4df6-8e6b-6d309ad20063.png" alt class="image--center mx-auto" /></p>
<p> Uncheck the box and click on <code>Save associations</code>. Do the same for Private Route tables.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716963249528/fc2e47d4-3d2c-47e4-957f-38607f8654f7.png" alt class="image--center mx-auto" /></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716963262944/17452ff2-ea48-477a-86d1-a5fd11fcb17b.png" alt class="image--center mx-auto" /></p>
<p> Now, as we do not have any associations, we can delete the route tables.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716963362225/077d8de6-537d-4847-b3c7-8b5c4e45673e.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Deleting Subnets</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716963439585/298496fb-86cc-4761-9efd-f8667bf04384.png" alt class="image--center mx-auto" /></p>
<p> Tick both of your subnets and on <strong>Actions panel</strong>, click <code>Delete subnet</code>.</p>
</li>
<li><p><strong>Deleting Internet Gateway.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716963527716/18e2dca6-2f59-4351-8c6c-c30086bab8f2.png" alt class="image--center mx-auto" /></p>
<p> Before we are able to delete the IG, we've to detach it from our VPC.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716963594766/e3fee0ff-669f-4de2-b428-17f9527d1656.png" alt class="image--center mx-auto" /></p>
<p> After detaching from our VPC, we can delete our Internet gateway.</p>
</li>
<li><p><strong>Deleting VPC.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716963702825/caef33e0-d5b5-4ce7-af6d-fbf22e658053.png" alt class="image--center mx-auto" /></p>
<p> Now, we have cleaned up our resources that we had used in our lab session.</p>
</li>
</ol>
<hr />
<p>Alright folks, See you in the next one!</p>
]]></content:encoded></item><item><title><![CDATA[Setting Up Virtual Private Cloud]]></title><description><![CDATA[Hello folks.
Today, we'll be setting up our Virtual Private Cloud, a.k.a. VPC.
Let's get started right away.

Overview
In this setup, we will create a VPC with an Internet Gateway for internet access. We'll configure route tables for traffic manageme...]]></description><link>https://sujanmagar.com.np/setting-up-virtual-private-cloud</link><guid isPermaLink="true">https://sujanmagar.com.np/setting-up-virtual-private-cloud</guid><category><![CDATA[AWS]]></category><category><![CDATA[vpc]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Wed, 29 May 2024 00:15:29 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1716896898496/27f3727b-8a3e-4cbc-bb4a-af727172802c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello folks.</p>
<p>Today, we'll be setting up our Virtual Private Cloud, a.k.a. VPC.</p>
<p>Let's get started right away.</p>
<hr />
<h3 id="heading-overview">Overview</h3>
<p>In this setup, we will create a VPC with an Internet Gateway for internet access. We'll configure route tables for traffic management. Inside the VPC, we'll have public subnets for instances directly accessible from the internet and private subnets for instances needing internet access but not directly reachable. To enable internet access for private instances, we'll deploy a NAT Gateway in the public subnet.</p>
<hr />
<h3 id="heading-task-1-creating-a-vpc">Task 1: Creating a VPC</h3>
<p>On Services, search for VPC and select <strong>VPC</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716861722916/e75707d8-386e-4825-8d45-f04a2b880a22.png" alt class="image--center mx-auto" /></p>
<p>A Virtual Private Cloud (VPC) in AWS is a customizable network environment that allows you to isolate and securely manage your AWS resources.</p>
<p>Click on <code>Create VPC</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716862095136/3adcae33-7f6e-4ed0-9b67-4ea7091fdf3c.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable name for your VPC.</p>
<p>Input the given CIDR in the IPv4 CIDR block.</p>
<p>For the <code>10.0.0.0/16</code> network, the first two octets are reserved for the network portion, while the remaining two octets are for host addresses. This allows for 2^16 = 65,536 total IP addresses.</p>
<p>Click on <code>Create VPC</code>.</p>
<p>We've created our VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716862897458/1c02f114-098d-4964-b188-48f980a8b701.png" alt class="image--center mx-auto" /></p>
<p>The other one is default, created by AWS.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716892751236/00deaad5-d42d-48fb-9e75-a196640aa416.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-2-creating-an-internet-gateway">Task 2: Creating an Internet Gateway</h3>
<p>An Internet Gateway (IGW) allows your VPC to connect to the internet, enabling resources within the VPC, to send and receive internet traffic.</p>
<p>On the VPC dashboard, select <strong>Internet gateways</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716889809637/dd3694a8-ea01-4609-9611-f7714fdfe06f.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Create internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716864949431/aeb7f523-b0b0-49ec-a3f1-180c45b7255c.png" alt class="image--center mx-auto" /></p>
<p>Provide a name for your internet gateway and <code>Create internet gateway</code>.</p>
<p>Now, it's time to attach the Internet Gateway (IG) to the VPC.</p>
<p>We can do this using either of the options.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716865049090/bd1964a6-fb1d-493b-8645-6d4d4e0fce52.png" alt class="image--center mx-auto" /></p>
<p>Select your VPC and <code>Attach internet gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716865294193/c360321f-f492-4634-b03c-f268d254f554.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716892890637/d3fe941d-8600-4af2-a65f-4bc97010adbb.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-3-creating-subnets">Task 3: Creating subnets</h3>
<p>A subnet is a segment of a VPC's IP address range where you can place resources such as EC2 instances. Subnets allow you to <strong>group resources based on security and operational needs</strong>, and can be either public (with internet access) or private (without direct internet access).</p>
<p>On VPC dashboard, on <strong>Subnets</strong>, click on <code>Create subnet</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716866572282/74b01a66-8e82-41de-9aa7-bceb1414940f.png" alt class="image--center mx-auto" /></p>
<p>Select your VPC.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716866638308/ca334cc8-3569-421a-8d32-3ca87122d244.png" alt class="image--center mx-auto" /></p>
<p>Provide suitable name for your subnets.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716867057395/8e7634b8-7def-4ed8-87e5-7d44ec2bcc96.png" alt class="image--center mx-auto" /></p>
<p>Our first subnet, <code>publicSubnet</code>, has a CIDR value of 10.0.1.0/24.</p>
<p>It will have a total of 2^8 = 256 addresses.</p>
<p>Also, for this project, we're only choosing a single availability zone.</p>
<p>Click on <code>Add new subnet</code> and create a private subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716867507021/55eced24-2b31-479e-9db5-0832b8965451.png" alt class="image--center mx-auto" /></p>
<p>Our second subnet, <code>privateSubnet</code>, has a CIDR value of 10.0.2.0/24.</p>
<p>It will have a total of 2^8 = 256 addresses.</p>
<p>Click on <code>Create subnet</code>.</p>
<p>We've successfully created 2 subnets.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716867300365/3794c106-9733-40ba-be93-a1bcbe6290e8.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716893460595/744b89a6-3c61-426e-be15-20fe08b5375d.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-4-creating-a-nat-gateway">Task 4: Creating a NAT Gateway</h3>
<p>A NAT Gateway allows instances in a private subnet to initiate outbound traffic to the internet, while preventing inbound traffic from reaching those instances directly. It provides a way for these instances to access the internet while remaining private.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716871983671/82199b81-6ff3-4f9a-99dc-b0479ea2f268.png" alt class="image--center mx-auto" /></p>
<p>On VPC dashboard, search for <strong>Nat gateways</strong> and click on <code>Create NAT gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716872847702/2fadee99-d3f5-464f-9274-a0ede500335c.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable name and select your private subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716872793523/3c905ed6-5652-4681-9f5e-c19bdccc66b1.png" alt class="image--center mx-auto" /></p>
<p>For public connectivity, instances in private subnets can connect to the internet through a public NAT gateway, but they cannot receive unsolicited inbound connections from the internet. You create a public NAT gateway in a public subnet and associate an elastic IP address with it.</p>
<p>On the other hand, the Private connectivity type allows instances in private subnets to connect to other VPCs or your on-premises network. Unlike the Public NAT gateway, a Private NAT gateway does not use an Elastic IP address.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716881924407/deac57d6-5143-4e04-b357-c31662130f1c.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Allocate Elastic IP</code>.</p>
<p>An Elastic IP (EIP) is a static IPv4 address associated with your AWS account, not a specific resource. It's ideal for scenarios requiring a persistent public IP that can be easily reassigned to another instance during failures, updates, or scaling.</p>
<p>Click on <code>Create NAT gateway</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716882849030/01fde8de-eccf-41ef-a8bb-3acf4c7d76d5.png" alt class="image--center mx-auto" /></p>
<p>It takes some time to configure.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716882907986/6eb73bdf-1c79-40ff-9c60-15963ed3989a.png" alt class="image--center mx-auto" /></p>
<p>Alright, let's move on.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716894949626/0ab5173b-2bf1-4ae1-99dd-746f96a35359.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-5-creating-route-tables">Task 5: Creating route tables</h3>
<p>Route tables direct network traffic within your VPC. They contain a set of rules (routes) that determine where network traffic from your subnet or gateway is directed.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716866062121/f1dea02b-e0d1-46e2-b229-6da00d233e4f.png" alt class="image--center mx-auto" /></p>
<p>On VPC dashboard, select <strong>Route tables</strong> and click on <code>Create route table</code>.</p>
<p>Since we have two subnets, one private and one public, for different purposes, we need to create two route tables.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716867758203/17c4a10b-b0a5-49a3-a94f-064143be5d6e.png" alt class="image--center mx-auto" /></p>
<p>Provide name for your Route table and select your VPC.</p>
<p>Click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716868264251/885220f1-6221-484e-a707-41dfd8da7977.png" alt class="image--center mx-auto" /></p>
<p>After creating route table, on <strong>Subnet associations</strong>, click on <code>Edit subnet associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716868835746/f4437a40-75d4-427b-9130-97c830230224.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716867958627/0649fce3-2023-4b77-9307-11d1f9fc7e1d.png" alt class="image--center mx-auto" /></p>
<p>Select your Public Subnet and click on <code>Save associations</code>.</p>
<p>Now we need to add routes so that our public subnet can access the Internet.</p>
<p>Click on <code>Edit routes</code> and add the following configurations on <code>Add route</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716868757129/f54d1984-b967-440f-ac3e-db84dab0757e.png" alt class="image--center mx-auto" /></p>
<p>So, we have added a rule to access the destination <code>0.0.0.0/0</code> using the Internet Gateway. In routing tables, a destination of 0.0.0.0/0 means all IP addresses, effectively representing the entire internet.</p>
<p>Click on <code>Save changes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716883774342/83220b66-7b7d-44c8-8c96-e081b8476195.png" alt class="image--center mx-auto" /></p>
<p>Now, for private subnets, let's create a route table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716883040564/87ac0e8b-4835-4c76-b9b9-7c49438eb9c2.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable name and assign your VPC.</p>
<p>Click on <code>Create route table</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716883359455/2deb2345-403b-4872-a4a0-220603579c0b.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Edit subnet associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716883392821/22acf2df-221f-44ea-8c92-447fdc8db57e.png" alt class="image--center mx-auto" /></p>
<p>Tick your Private Subnet and click on <code>Save associations</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716883444488/eb2eec70-e083-4313-8c61-5f1a19b154c7.png" alt class="image--center mx-auto" /></p>
<p>Now, time to add route. Click on <code>Edit routes</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716883498988/cf8974db-e2a7-4412-a024-7bfeb43481e8.png" alt class="image--center mx-auto" /></p>
<p>Select your NAT Gateway and click on <code>Save changes</code>.</p>
<p>This configuration allows instances in the private subnet to access the internet through the NAT Gateway.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716883588733/11613900-b88f-4e75-b43a-18310d4a21e0.png" alt class="image--center mx-auto" /></p>
<p>Alright, we have now associated an Internet Gateway with the public subnet and a NAT Gateway with the private subnet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716895050992/55755288-882d-413f-b19b-f2b223c4b1c8.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-6-creating-ec2-instances">Task 6: Creating EC2 Instances</h3>
<p>Now, it's time to create EC2.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716884051210/d90ec9ec-ab9c-4a77-87cf-3ef4240b3b5f.png" alt class="image--center mx-auto" /></p>
<p>Search for <strong>EC2</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716884132822/df24ec02-dc24-4acd-a991-7d8eca38c050.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Launch instance</code>.</p>
<p>Let's create Public instance first.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716884974153/38c363d7-f01a-496c-82dc-cc1ec8e642b4.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable name. I chose Ubuntu as AMI.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716885024760/4f65f98e-b941-447b-822c-8d37c8611a31.png" alt class="image--center mx-auto" /></p>
<p>Select a free tier instance if available and create a new key pair or use your existing one.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716885180035/fb93ba59-077c-4862-a906-92713dab4d7f.png" alt class="image--center mx-auto" /></p>
<p>Edit Network settings. Select your VPC, select the public subnet, and enable Auto-assign public IP.</p>
<p>Assigning a public IP allows an instance to communicate directly over the internet.</p>
<p>Leave all other configurations as they are and click <code>Launch instance</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716885452385/15a2e0c4-7a05-41f5-bbf4-65806663ebc8.png" alt class="image--center mx-auto" /></p>
<p>Alright, let's go for Private instance now. Click on <code>Launch instances</code>.</p>
<p>Provide name, select an AMI, select the free-tire instance.</p>
<p>We can use our previously created key pair or create a new one.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716885713217/16d9df0f-edfc-432d-974e-5db5c928ad7a.png" alt class="image--center mx-auto" /></p>
<p>Edit Network settings. Select your VPC, select Private subnet and leave the Auto-assign public IP as default, i.e., <code>Disable</code> mode.</p>
<p>A private instance does not require a public IP address, as it is not intended to communicate directly over the internet.</p>
<p>Leave all other configurations as they are and click <code>Launch instance</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716886127195/df780adf-0f79-4b0c-a060-54127a7b1986.png" alt class="image--center mx-auto" /></p>
<p>Alright, we've created two instances: one public and one private, each residing in different subnets, and that sums up our project.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716895420598/df2b25f7-8096-4426-a121-732fdba5ed76.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-conclusion">Conclusion</h3>
<p>To sum up, we created a Virtual Private Cloud (VPC) with two subnets in one Availability Zone. The public subnet is for resources needing direct internet access, like public EC2 instances, connected to an Internet Gateway (IG). The private subnet, for more secure resources like private EC2 instances, is connected to a Network Address Translation (NAT) Gateway. We also configured route tables to manage traffic flow.</p>
<hr />
<h3 id="heading-task-7-clean-up">Task 7: Clean up</h3>
<p>Now, it's time to clean up the resources.</p>
<ol>
<li><p><strong>Terminating EC2 instances.</strong></p>
<p> Select your instances and, on <strong>Instance state</strong>, click Terminate instance.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716886357755/746ada4d-c948-422d-9325-3e9445f4a9c3.png" alt class="image--center mx-auto" /></p>
<p> Click on <code>Terminate</code>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716886444879/29f5d99c-63cb-4172-a05b-d827bee57fd3.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Deleting route tables.</strong></p>
<p> Head up to VPC Dashboard by searching <strong>VPC</strong> on the Search box.</p>
<ol>
<li><p>On Route tables, select your one route table and click on <code>Edit subnet associations</code>. We've to disassociate subnets first to delete the route table.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716886848116/3f22d37f-9f5a-4bac-9c43-f71f62cefdb7.png" alt class="image--center mx-auto" /></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716886943673/a7557c26-a697-4bda-b819-74511149b128.png" alt class="image--center mx-auto" /></p>
<p> Uncheck the box and click on <code>Save associations</code>. And the same for another route table. Select route table, on <strong>Subnet associations</strong>, click on <code>Edit subnet associations</code>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716887058044/008e212c-4070-436b-9b33-b65d6000ff15.png" alt class="image--center mx-auto" /></p>
<p> Uncheck the box and click on <code>Save associations</code>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716886738248/a6b8f20e-67a7-4e57-aa9c-42e8eb645f23.png" alt class="image--center mx-auto" /></p>
<p> Now, select both of your route tables and on Actions menu, click on <code>Delete route table</code>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716887259327/a6660d1f-9857-4bdc-81f6-97309aae69ac.png" alt class="image--center mx-auto" /></p>
<p> Type <em>delete</em> and click on <code>Delete</code>.</p>
</li>
</ol>
</li>
<li><p><strong>Release Elastic IP.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716887990159/44b195b1-230a-4487-b380-dc8fd3783dae.png" alt class="image--center mx-auto" /></p>
<p> On <strong>Elastic IPs</strong>, select your elastic IP and click on <code>Release Elastic IP addresses</code>.</p>
</li>
<li><p><strong>Deleting NAT Gateway.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716887776802/d86b8be7-bea5-4996-b732-6f0770b4130f.png" alt class="image--center mx-auto" /></p>
<p> Select your NAT Gateway and on <strong>Actions panel</strong>, click on <strong>Delete NAT gateway</strong>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716887853850/bde5d7fd-0c20-48e0-9390-637da84bbfed.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Detaching Internet Gateway.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716887659752/942a62d0-114f-479c-a767-c569677cd182.png" alt class="image--center mx-auto" /></p>
<p> Select your Internet Gateway and, on <strong>Actions panel</strong>, click <code>Detach from VPC</code>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716888258312/c101f9c4-0773-4897-8285-836211047622.png" alt class="image--center mx-auto" /></p>
<p> After detaching, we have to delete the internet gateway.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716888321913/00d92bf9-6d96-407b-adcd-631b649c5a4e.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Deleting subnets.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716887362727/52bc5dfb-9ad5-40e8-9265-8634ff588f38.png" alt class="image--center mx-auto" /></p>
<p> Select both of your subnets and on Actions menu, click on <code>Delete subnet</code>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716888421839/6f2b0c29-42c1-4c46-8465-b3e1c7d4c3f4.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Deleting VPC.</strong></p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716888483887/aa3d56aa-da4d-4387-a2f6-7fc8529f1cb6.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716888513901/469f0eb8-b653-42aa-bd8b-fe31389021cc.png" alt class="image--center mx-auto" /></p>
<p>Alright, now, we've cleaned up our used resources.</p>
<hr />
<p>See you in the next one!</p>
]]></content:encoded></item><item><title><![CDATA[Launching and Accessing an EC2 Instance with SSH]]></title><description><![CDATA[In this blog, we'll walk through the process of launching an Amazon Elastic Compute Cloud (EC2) instance and securely connecting to it using SSH.
Let's get started.

Overview
In this setup, we will launch an EC2 instance on AWS. Then, using our local...]]></description><link>https://sujanmagar.com.np/launching-and-accessing-an-ec2-instance-with-ssh</link><guid isPermaLink="true">https://sujanmagar.com.np/launching-and-accessing-an-ec2-instance-with-ssh</guid><category><![CDATA[AWS]]></category><category><![CDATA[ec2]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Tue, 28 May 2024 00:15:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1716781244642/09406758-0b5e-4dd8-a897-dc05efaf7149.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this blog, we'll walk through the process of launching an Amazon Elastic Compute Cloud (EC2) instance and securely connecting to it using SSH.</p>
<p>Let's get started.</p>
<hr />
<h3 id="heading-overview">Overview</h3>
<p>In this setup, we will launch an EC2 instance on AWS. Then, using our local terminal, we will establish an SSH connection to that EC2 instance.</p>
<hr />
<h3 id="heading-task-1-launching-an-ec2-instance">Task 1: Launching an EC2 instance</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716771399472/f345d9f7-c239-436b-9bc1-9209862ab6d0.png" alt class="image--center mx-auto" /></p>
<p>On services, search for EC2 and click on it.</p>
<p>Now, click on the yellow button <code>Launch instance</code> below.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716771508539/f2f07d55-2544-47ea-9480-f18cb0e2a1a0.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable name for your EC2 and choose Ubuntu as AMI.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716771636931/df7031f4-fa7d-4bfc-81dc-6ae226a311b7.png" alt class="image--center mx-auto" /></p>
<p><strong>AMI:</strong> An AMI (Amazon Machine Image) is a template for launching virtual servers in the cloud, containing the operating system, software, and settings.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716771765438/c1b908e8-1a07-4240-8598-604ed018f2da.png" alt class="image--center mx-auto" /></p>
<p>We're utilizing the free tier instance provided by AWS.</p>
<p>Now, time to create a key pair.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716771869801/d1313a0f-b02d-4fe7-b6ec-5f7517a2de97.png" alt /></p>
<p>Key pairs are a fundamental security element for accessing EC2 instances in AWS. They utilize public-key cryptography to ensure secure logins.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716779280099/fc9accd2-f675-46c5-b054-b3cb821c5c06.png" alt class="image--center mx-auto" /></p>
<p>When we launch an EC2 instance, we can select an existing key pair or create a new one. The public key is stored on the instance, while we securely store the private key on our local machine.</p>
<p>To connect to the instance, we use an SSH client and the private key to authenticate ourselves.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716771893935/130157d4-ad87-4d3d-88e9-3b17d4f2e4ee.png" alt class="image--center mx-auto" /></p>
<p>I've downloaded the private key file in my device.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716772849226/c1739c6b-8323-434f-a5f7-3c84c08759eb.png" alt /></p>
<p>Our current configuration allows SSH access to our instance from any location on the internet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716773048637/fe565e85-1827-4844-a88c-fcd991147fee.png" alt class="image--center mx-auto" /></p>
<p>Leave all other configurations as default. On the right panel, we can see the Summary section on our EC2 specifications.</p>
<p>Click on <code>Launch instance</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716773357400/7cd97c83-9496-4288-bc6c-be64982a18ba.png" alt class="image--center mx-auto" /></p>
<p>Click on the instance ID.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716773396784/17c4acc0-e2c4-430f-8c48-b5ca5ca50033.png" alt class="image--center mx-auto" /></p>
<p>We can see we have successfully launched our EC2 instance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716773461347/ab2f712b-034b-42b6-88b2-af36d7ce7e6d.png" alt class="image--center mx-auto" /></p>
<p>Click on the instance ID to see various details of our EC2 instance.</p>
<hr />
<h3 id="heading-task-2-accessing-ec2-with-ssh">Task 2: Accessing EC2 with SSH</h3>
<p>SSH (Secure Shell) is the secure way to connect to and manage our EC2 instances. It provides encrypted communication between our local machine and the instance, protecting our login credentials and commands.</p>
<p><strong>Prerequisites:</strong></p>
<ul>
<li><p><strong>Running EC2 Instance:</strong> A launched EC2 instance with SSH enabled.</p>
</li>
<li><p><strong>SSH Client:</strong> An SSH client installed on our local machine. Common options include terminal (Linux/macOS) or tools like PuTTY (Windows).</p>
</li>
<li><p><strong>Key Pair:</strong> Ensure you have a key pair created and downloaded securely. The public key should be associated with your instance.</p>
</li>
</ul>
<p>As we have done all the prerequisites, it's time to get the work done.</p>
<p>Head up to your instance details and click on <code>Connect</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716774068362/e263c628-4bd0-4f59-b4f3-85ed07883561.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716774195094/49adb9cc-64b0-4d5d-82a5-d558092eceb9.png" alt class="image--center mx-auto" /></p>
<p>Alright, now we have to follow the given instructions.</p>
<p>But before we continue, let's learn about the file permissions first.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Octal Representation</td><td>Decimal Representation</td><td>Permission</td><td>Representation</td></tr>
</thead>
<tbody>
<tr>
<td>000</td><td>0</td><td>No Permission</td><td>---</td></tr>
<tr>
<td>001</td><td>1</td><td>Execute</td><td>--x</td></tr>
<tr>
<td>010</td><td>2</td><td>Write</td><td>-w-</td></tr>
<tr>
<td>011</td><td>3</td><td>Write + Execute</td><td>-wx</td></tr>
<tr>
<td>100</td><td>4</td><td>Read</td><td>r--</td></tr>
<tr>
<td>101</td><td>5</td><td>Read + Execute</td><td>r-x</td></tr>
<tr>
<td>110</td><td>6</td><td>Read + Write</td><td>rw-</td></tr>
<tr>
<td>111</td><td>7</td><td>Read + Write + Execute</td><td>rwx</td></tr>
</tbody>
</table>
</div><p>The table shows uses octal numbers (base-8) to define three permission levels: owner, group, and others. Each permission level can be granted read, write, and execute access. For example, a chmod value of 7 (111 in octal) grants read, write, and execute permission to all three levels (owner, group, and others).</p>
<p>Say, there is a file with the value 777, it represents full access. This translates to all three user levels (owner, group, and others) having permission to read, write, and execute the file.</p>
<p>Alright, back to our demo.</p>
<p>I'm in my desktop terminal, and we can see the permissions of our key file here.</p>
<pre><code class="lang-bash">ls -l
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716775329500/90f7d901-f675-43c2-9404-0d5082dbc9ce.png" alt /></p>
<p>Owner: read/write permission</p>
<p>Group: read/write permission</p>
<p>Others: read permission</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716774384028/c9f6720b-83ff-4529-9560-a48635118a6e.png" alt class="image--center mx-auto" /></p>
<p>chmod is a command used in Unix-based operating systems to change the permissions of files and directories.</p>
<p>Copy the command and paste it into your terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716775788066/dae6bb7c-80ee-4b1a-98d1-79ee2cd506e1.png" alt class="image--center mx-auto" /></p>
<p>Now, we see the permissions have been changed.</p>
<p>Only the owner has the read permissions now.</p>
<p>Let's continue.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716776188027/6cbb8386-6300-444c-a5f7-695481a318e4.png" alt /></p>
<p>Copy the command and paste it into your terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716776285889/a0e3fb38-9a74-4677-958c-96bf4c9fb631.png" alt class="image--center mx-auto" /></p>
<p>Let's break down the command.</p>
<ul>
<li><p><strong>ssh:</strong> This is the command itself, which stands for Secure Shell. It's used to initiate a secure connection to a remote server.</p>
</li>
<li><p><strong>-i "myKey.pem"</strong>: This option specifies the identity file to be used for authentication. In this case, it's "myKey.pem" which is my private key file. The quotes around the filename are necessary if there are spaces in the path. Also, if you have your private key file in a different directory than your current working directory, you have to specify the full path.</p>
</li>
<li><p><strong>ubuntu</strong>: This specifies the username required to log in to the remote server. Here, the username is "ubuntu" (default).</p>
</li>
<li><p><a target="_blank" href="http://ec2-13-238-254-242.ap-southeast-2.compute.amazonaws.com">ec2-13-238-254-242.ap-southeast-2.compute.amazonaws.com</a>: This is the hostname or IP address of the remote server we're trying to connect to.</p>
</li>
</ul>
<p>Alright, now hit the Enter.</p>
<p>Proceed with yes when prompt.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716776929557/b655410f-0100-435a-872d-2edb1a655dbe.png" alt class="image--center mx-auto" /></p>
<p>And finally, we have logged in into our EC2 instance.</p>
<hr />
<h3 id="heading-task-3-clean-up">Task 3: Clean Up</h3>
<p>Select your instance and Select Terminate instance on <code>Instance state</code> panel.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716777066866/5793db29-345b-4a1c-bfb3-99ddfe3d9880.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716777121687/2133b249-4cf6-40a3-a937-04e249ccd90e.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Terminate</code>.</p>
<p>This concludes our lab.</p>
<hr />
<h3 id="heading-conclusion">Conclusion</h3>
<p>In this lab, we created an EC2 instance and then connected securely via SSH.</p>
<p>See you in the next one.</p>
]]></content:encoded></item><item><title><![CDATA[AWS Assume IAM Role]]></title><description><![CDATA[Today, we will learn about IAM Roles and their importance. We will cover key concepts and follow up with a practical demonstration. Let's get started!

Overview
In this blog, we will explore AWS IAM roles by creating a user with no S3 permissions. Th...]]></description><link>https://sujanmagar.com.np/aws-assume-iam-role</link><guid isPermaLink="true">https://sujanmagar.com.np/aws-assume-iam-role</guid><category><![CDATA[AWS]]></category><category><![CDATA[iam role in aws]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Mon, 27 May 2024 00:52:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1716720545576/3c8f9c39-4f9c-4b64-b05b-54f9cfdacaf1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today, we will learn about IAM Roles and their importance. We will cover key concepts and follow up with a practical demonstration. Let's get started!</p>
<hr />
<h3 id="heading-overview">Overview</h3>
<p>In this blog, we will explore AWS IAM roles by creating a user with no S3 permissions. Then, we will create a role with full S3 permissions. Finally, we will log in as the user with no permissions and switch to the role with full S3 access, demonstrating how roles can be used to manage access control in AWS.</p>
<hr />
<h3 id="heading-iam-role">IAM Role</h3>
<p>An IAM (Identity and Access Management) role in AWS is an identity that you can create in your AWS account. It has specific permissions and is designed to be assumed by trusted entities such as users, applications, or services.</p>
<p>Unlike an IAM user, a role does not have long-term credentials (password or access keys) associated with it. Instead, it provides temporary security credentials for the purpose of accessing AWS resources.</p>
<h3 id="heading-why-iam-roles">Why IAM Roles?</h3>
<ol>
<li><p><strong>Security:</strong> Roles use <strong>temporary credentials</strong>, reducing the risk if credentials are compromised.</p>
</li>
<li><p><strong>Cross-Account Access:</strong> Allow users or services from one AWS account to access resources in another account.</p>
</li>
<li><p><strong>Least Privilege Principle:</strong> Grant only the necessary permissions for a specific task or session.</p>
</li>
</ol>
<hr />
<h3 id="heading-attaching-role-directly-to-a-user">Attaching Role directly to a user?</h3>
<p>We cannot attach role directly to a user.</p>
<p>Here's why directly attaching roles to users wouldn't be ideal:</p>
<ul>
<li><p>If roles were directly attached to users, it would mean the user would always have those permissions. This could be a security risk, as it wouldn't allow for fine-grained control over access.</p>
</li>
<li><p>Without role assumption, users would be stuck with the permissions assigned to their attached role. This wouldn't be flexible for scenarios where a user might need different permissions for different tasks.</p>
</li>
</ul>
<p>Instead, IAM uses a concept called "assuming a role". This means a user (or another trusted entity like an application) can temporarily take on the identity of a role, along with the permissions that role provides. This grants them access to AWS resources for a specific session.</p>
<hr />
<h3 id="heading-stsassumerole">sts:AssumeRole</h3>
<p><code>sts:AssumeRole</code> is an AWS Security Token Service (STS) operation that allows a user or service to obtain temporary security credentials for assuming a different role.</p>
<p><strong>Key Points</strong></p>
<ol>
<li><p><strong>Purpose</strong>: To grant temporary access to AWS resources based on the permissions of a specified role.</p>
</li>
<li><p><strong>How it Works</strong>:</p>
<ul>
<li><p><strong>Request</strong>: A user or service calls <code>sts:AssumeRole</code> and specifies the ARN (Amazon Resource Name) of the role they want to assume.</p>
</li>
<li><p><strong>Verification</strong>: AWS STS checks if the caller is allowed to assume the role based on the role's trust policy.</p>
</li>
<li><p><strong>Temporary Credentials</strong>: If allowed, STS issues temporary security credentials (Access Key ID, Secret Access Key, and Security Token).</p>
</li>
</ul>
</li>
<li><p><strong>Temporary Credentials</strong>:</p>
<ul>
<li><p><strong>Access Key ID</strong>: Like a username for programmatic access.</p>
</li>
<li><p><strong>Secret Access Key</strong>: Like a password, used together with the Access Key ID.</p>
</li>
<li><p><strong>Security Token</strong>: Adds an additional layer of security and has a short expiration time (usually up to 1 hour).</p>
</li>
</ul>
</li>
<li><p><strong>Session with Assumed Role</strong>:</p>
<ul>
<li><strong>Use Temporary Credentials</strong>: With these credentials, the user can access AWS resources as allowed by the role, for a limited time.</li>
</ul>
</li>
</ol>
<hr />
<h3 id="heading-trust-policy-vs-role-policy">Trust Policy vs. Role Policy</h3>
<p><strong>Trust Policy</strong>:</p>
<ul>
<li><p>Determines <strong>who</strong> can assume the role.</p>
</li>
<li><p>Attached to the role and uses <code>sts:AssumeRole</code>.</p>
</li>
</ul>
<p><strong>Role Policy</strong>:</p>
<ul>
<li><p>Determines <strong>what actions</strong> can be performed when the role is assumed.</p>
</li>
<li><p>Attached to the role and specifies allowed actions and resources.</p>
</li>
</ul>
<hr />
<h3 id="heading-dirty-hands">Dirty Hands</h3>
<p>Alright, let's get our hands dirty.</p>
<p>To begin with, let's create a new user.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716708671707/4cb22b96-fa97-41b4-856f-9389d5421f64.png" alt class="image--center mx-auto" /></p>
<p>Go to IAM section, and on Users, click on <code>Create user</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716708756114/eff8044b-6348-4809-8d4b-0b8ff7ef3f30.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716708787084/98f903ed-18fd-489f-a086-1652fa9f4aa2.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Next</code> until you create a user.</p>
<p>I've created a User named testuser.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716708897505/0282fcd4-f3f5-4ea7-9f9f-c043524504a6.png" alt class="image--center mx-auto" /></p>
<p>Now, let's create a Role.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716708999174/1eecb5c2-5a40-4dd8-ad91-822dce595df8.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716709099752/2a2975b8-4877-49d2-9232-599016957b0a.png" alt class="image--center mx-auto" /></p>
<p>We are granting permission to users, applications, or services from different AWS accounts (including accounts we own and accounts owned by others) to access and perform specific operations in our AWS account</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716709203856/eb58e074-87e0-4eb7-82f1-5419c72b4b48.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716709272886/3d0409bf-4881-4ff5-a095-df7732eee9bc.png" alt class="image--center mx-auto" /></p>
<p>Search for s3 and select the policy where we're granting full s3 access for this role.</p>
<p>Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716709365412/fa6f0ad4-73cd-4e2e-bd93-7b7071fac9c1.png" alt class="image--center mx-auto" /></p>
<p>Provide a suitable role name.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716709909249/07a374a4-bbb4-4b57-812e-abdac5f1e217.png" alt class="image--center mx-auto" /></p>
<p>This trust policy allows any user or entity belonging to the AWS account with ID <code>767398070747</code> to assume the role.</p>
<p>When someone from that account tries to assume the role (using the <code>sts:AssumeRole</code> API operation), as long as the account ID matches the one specified in the trust policy, they will be granted temporary security credentials to act with the role's permissions for a limited time.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716709992018/95afe707-5e8a-4f2a-8173-04e9bfa1447c.png" alt class="image--center mx-auto" /></p>
<p>While, it is the permissions policy we'd given earlier.</p>
<p>Click on Next and Create a role.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716710401487/5e1fe424-f6a2-4067-b0f3-fd54d26988fc.png" alt class="image--center mx-auto" /></p>
<p>Our role has been created.</p>
<p>Now, let's log in as recently created testuser. For that, go to Dashboard, and copy the Sign-in URL.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716710525698/033e2435-15b1-430e-95c7-1b074778bfc0.png" alt class="image--center mx-auto" /></p>
<p>Open private window, paste the link and login as recently created New User.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716710622896/8654c3cd-6629-4edd-8dc9-affddb8a0c91.png" alt class="image--center mx-auto" /></p>
<p>You either provide Account ID or alias. I had created alias for ease.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716710719215/0ad15f84-c331-42d9-b544-23dca64edebc.png" alt class="image--center mx-auto" /></p>
<p>I've logged in as testuser.</p>
<p>Now, let's try to see the list of buckets if there's any.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716710799169/d2f08d1b-2e65-4bd5-bb6b-1676c3510120.png" alt class="image--center mx-auto" /></p>
<p>We do not have the permissions to list buckets.</p>
<p>Now, let's assume the s3Access role for this testuser.</p>
<p>For this, we've to go back to the iamadmin console and proceed.</p>
<p>After you're in your iamadmin console, Click on Role, select the role that you'd created and copy the ARN.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716711381038/8ae6c777-5754-4352-9047-447a6921b8c9.png" alt class="image--center mx-auto" /></p>
<p>Save it to somewhere for now.</p>
<p>Now, click on Users and select the testuser.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716711064822/3c20a7f8-7d38-4579-8f29-395481794218.png" alt class="image--center mx-auto" /></p>
<p>Scroll a bit and click on <code>Add permissions</code>.</p>
<p>Click on <code>Create inline policy</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716711126382/a72711e9-119c-4bff-8486-0d9441b4208b.png" alt class="image--center mx-auto" /></p>
<p>On Action, type <code>sts:AssumeRole</code></p>
<p>Also, paste the copied ARN in Resource field.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716711472281/beab2e08-d657-4c2d-a1f3-4960aeed9f49.png" alt class="image--center mx-auto" /></p>
<p>This policy allows users from the account ID <code>767398070747</code> to assume the "s3Access" role. Once they assume the role, they can temporarily act with the permissions assigned to that role.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716711573535/dcf218fe-5048-4a8a-8254-8acc49011cd6.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Next</code> and provide relevant policy name and <code>Create Policy</code>.</p>
<p>Ok, now our testuser can assume that role that grants the user full access to s3 services.</p>
<p>Head up to testuser console.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716711838963/34cdd04a-6c31-4338-bfe5-bfec5b4a41dd.png" alt class="image--center mx-auto" /></p>
<p>As we discussed earlier, role can't be assigned directly to the user. So, we've to switch role.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716711914372/bc5f1586-05b9-430d-b537-92223bec33e9.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Switch role</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716711951810/49e44e1e-330e-4c42-a6ef-83c4c00ed988.png" alt class="image--center mx-auto" /></p>
<p>Provide the details and click on <code>Switch Role</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716712012635/d93c19ca-b0c1-4821-bec7-4b8b6f6250fa.png" alt class="image--center mx-auto" /></p>
<p>Now we can see We've switched our role, and we can see no restrictions as before. We've assumed a role that has full access to s3 services. We can perform different operations on s3 for a limited time.</p>
<p>And, to go back to our own profile, simply click on <code>Switch back</code>.</p>
<p>Now, as we've switched back, and we have no longer permissions to perform operations on s3.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716712182046/387605bf-236a-4bdd-abb0-7e3a2b28c6de.png" alt class="image--center mx-auto" /></p>
<p>In this way, by carefully crafting trust policies, we can grant controlled access to our AWS account's resources. We can specify exactly who (or what) can assume a role and what actions they can perform while acting under that role's permissions. This allows for secure and granular access management within your AWS environment.</p>
<p>Now, time to clean up.</p>
<p>Head back to your iamadmin console.</p>
<p>Click on roles and delete the created role.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716712416174/83dafd2e-5ac7-4942-b957-8341f225963a.png" alt class="image--center mx-auto" /></p>
<p>Similarly, delete the created user.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716712452445/bceea06c-9ae9-41e7-826d-a33ea0372904.png" alt class="image--center mx-auto" /></p>
<p>Alright, that was it for this demo.</p>
<p>See you in the next one.</p>
<p>Thank you.</p>
]]></content:encoded></item><item><title><![CDATA[System Design Architectures]]></title><description><![CDATA[Here, we'll be exploring different system designs.
Let's dive in.

Content Based Message Routing System
Let's explore different architectures.

Say, we have an insurance system. If anyone purchase an insurance, System A get's data and sends message t...]]></description><link>https://sujanmagar.com.np/system-design-architectures</link><guid isPermaLink="true">https://sujanmagar.com.np/system-design-architectures</guid><category><![CDATA[AWS]]></category><category><![CDATA[System Design]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Sun, 26 May 2024 10:14:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1716718452328/b81a05f0-82b1-424d-96a5-ff7edd46229d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Here, we'll be exploring different system designs.</p>
<p>Let's dive in.</p>
<hr />
<h3 id="heading-content-based-message-routing-system">Content Based Message Routing System</h3>
<p>Let's explore different architectures.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716177814937/ce1e5e54-c077-41b0-8bf7-572c2d8390e5.png" alt class="image--center mx-auto" /></p>
<p>Say, we have an insurance system. If anyone purchase an insurance, System A get's data and sends message to the respective backend processing.</p>
<p><strong>How would you design the architecture where System A can send message to different backend servers effectively?</strong></p>
<p><strong>First method: Just calling API's to different system.</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716178437490/b9efa314-c4f7-48d3-b23f-78a298d6ab43.png" alt class="image--center mx-auto" /></p>
<p>System A will be having some conditioning logic like if insurance type is CAR, call CAR API, if it's house, call HOUSE API and so on. It's not considered a good practice.</p>
<p>As traffic grows, all the system need to scale up at the same time. And say, CAR system breaks down, the system A need to resend the message as it is synchronous architecture (API-based).</p>
<p>When there is need of message, routing, message based/event-based processing, always think of queue.</p>
<p>You can insert the message in queue. Even if there are lots of messages in the queue, the backend servers will eventually process them. Also, retries are built-in in queue.</p>
<p><strong>Second method: Using SQS, Lambda</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716179399654/a049d329-a72e-4131-8c26-6b9985112ffa.png" alt class="image--center mx-auto" /></p>
<p>We've SQS that aces as a queue where System A stores messages &amp; lambda/EC2. Based on the type of message, it calls 3 different systems. But here the lambda becomes the bottleneck. It's easier to scale SQS on a message based system than to scale lambda.</p>
<p>Also, as a single lambda is processing all 3 different types of servers, so even if the volume increases, say CAR insurance, it might impact the HOUSE &amp; MOTORCYCLE processing. The CAR insurance's traffic volume might take over the concurrency limit of lambda.</p>
<p><strong>Third method: Using SNS Topic</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716252858640/3f8ad67b-d934-4f59-9c78-d64bdd5e0f44.png" alt class="image--center mx-auto" /></p>
<p>Here, System A publishes the message in SNS topic while doing that, it also attaches meta-data to the message. SNS can do filtering based on the metadata.</p>
<p>Metadata is not included inside the message body. Metadata (message attributes) provides additional context about the message, but is not part of the message content itself.</p>
<p>Say, message looks like this</p>
<pre><code class="lang-xml">#Message
{
    "INS_type": "CAR",
    "NAME": "RAM",
    "PRICE": 50
}
</code></pre>
<p>The metadata is not included in the message, but SNS can accept a message with metadata. Metadata could have field like insurance type, then have CAR, BIKE as a value.</p>
<pre><code class="lang-xml">#Meta-data
"ins_type": "CAR"
</code></pre>
<p>Note that the metadata insurance type is different from the insurance type within the JSON message.</p>
<p>So, when System A sends a message to SNS topic, it can attach metadata &amp; based on the metadata, SNS topic can send to the respective queue, and it can be processed using lambda/EC2.</p>
<p>Each of the queue &amp; backend can be scaled independently, which is considered a good approach.</p>
<p>When you want to use the actual message instead of attaching metadata, we can use Amazon Event Bus.</p>
<p><strong>Fourth method: Using Amazon Event Bus</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716257822241/d9cb8155-e789-497a-88bb-2c0dbf50de5f.png" alt class="image--center mx-auto" /></p>
<p>In this architecture, System A will simply publish the message into Amazon Event Bus &amp; the message could have the field and the event bus can do filtering based on the value of the field. So, it can inspect the field insurance type and send it to the respective SQS.</p>
<p>It can also handle advanced conditions, pattern matching, and more.</p>
<p><strong>Event Bus vs. SNS</strong></p>
<ul>
<li><p>Event Bus can do simple to advanced conditioning, pattern matching, however it is more expensive. SNS on the other hand is cost-effective.</p>
</li>
<li><p>SNS and SQS can scale almost infinitely, while Event Bus has limits on scaling.</p>
</li>
</ul>
<hr />
<h3 id="heading-image-storage-amp-retrieval-architecture">Image Storage &amp; Retrieval Architecture</h3>
<p>When considering how to save or store images, there are generally two options:</p>
<ol>
<li><p>Saving in a database.</p>
</li>
<li><p>Saving in object storage, such as Amazon S3.</p>
</li>
</ol>
<p><strong>When we save an image, and someone retrieves the image, it's not always the same image.</strong></p>
<p>For example, on Facebook, we can upload a super high-resolution image, such as one with 20 megapixels. However, when we view this image in our Facebook feed on a device and try to zoom in, the image appears pixelated. While the original image remains the same, it gets downsampled based on the device being used.</p>
<p>When we talk about saving &amp; retrieving images, it's not just about saving and retrieving, it's also the processing that's involved which is downsampling the images for different resolutions based on the device type. Downsampling images not only saves bandwidth but also enhances user experience, reduces storage costs, optimizes performance, improves network efficiency, and ensures consistency across devices.</p>
<p>If we store images in a database, which can be disk-based or memory-based, it is generally more expensive than using regular object-based storage. Databases provide faster IOPS (Input/Output Operations Per Second), enabling quicker image retrieval. However, in many architectures that handle images, such as those used by Amazon or Tinder, it is acceptable for images to take slightly longer to load, such as an additional second. In these systems, it is not critical for images to be retrieved in microseconds.</p>
<p>Therefore, almost all architectures that manage a high volume of images use object-based storage solutions like Amazon S3.</p>
<p><strong>Simplified System Without Downsampling/Upscaling</strong></p>
<p>If downsampling and upscaling are not required, the system can be simplified. Users can directly upload images to a predetermined folder in S3 using API Gateway. For retrieval, since there’s only one copy of the image, the API Gateway uses a fixed path to fetch the image from S3 and return it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716285229085/3a4cc0d7-fcce-47dd-a052-3e6f6f38e44b.png" alt class="image--center mx-auto" /></p>
<p>Let's consider a user named Smith. He uploads an image called <code>cat.jpg</code>. Smith invokes an API hosted on API Gateway and points to the image saved in his local folder. This API will call a backend Lambda function, which will save the image in an S3 bucket named <code>Images</code>. Within this S3 bucket, the image <code>cat.jpg</code> will be saved in a folder called <code>Images/Cats</code>.</p>
<p>API Gateway can save the image directly into S3. If you don't need any business processing.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716285760719/5764b4c9-c9ea-4852-9c61-770bb138c4e1.png" alt class="image--center mx-auto" /></p>
<p>But generally what happens is, the lambda does some processing for example, to check if the image contains explicit contents, it'll call Amazon Recognition.</p>
<p>If we consider scenarios with multiple S3 buckets and different folder structures, we want to avoid hardcoding these details into the retrieval code. For instance, hardcoding conditions like 'if the region is X, go to this bucket and this folder structure' becomes impractical when new folder structures are added, as it requires constant code changes.</p>
<p>Instead, the Lambda function will save the image location into a database. While it saves an image to an S3 bucket, it will also record the location in a database table, such as 'cat.jpg is saved in Images/Cats'. Additionally, we assume that the list of eligible S3 buckets is also stored in a database table. The Lambda function will fetch the appropriate bucket name from the database and save the image accordingly.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716286271487/bd59dba6-bd0c-49e8-afaa-8663a28cf563.png" alt class="image--center mx-auto" /></p>
<p>Now, regarding the upsampling and downsampling of images after they are uploaded, to enhance retrieval efficiency and storage optimization, we follow the following approach.</p>
<p>Once an image is uploaded to S3, it triggers a Lambda function. This Lambda function uses an image processing library to downsample/upsample the image into different resolutions such as 10 MP, 7 MP, and 5 MP. The processed images are saved into different S3 buckets. The Lambda function also records the locations of these images in a DynamoDB table, storing entries for each resolution.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716288102601/a662c42d-4409-4e62-bcc6-9988d7dc8650.png" alt class="image--center mx-auto" /></p>
<p>If further processing is required beyond saving metadata, a backend_lambda function can be used. Alternatively, if no additional processing is needed, API Gateway can upload images directly to S3. The S3-triggered Lambda function then handles resizing and saving metadata into DynamoDB. This way, both the original and downsampled images are saved in S3 buckets, with their pointers stored in a DynamoDB table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716288267418/94d580dd-370a-44a3-82c8-afecd2e0b96e.png" alt class="image--center mx-auto" /></p>
<p><strong>Image Retrieval</strong></p>
<p>To retrieve an image, such as 'cat.jpg', the process involves invoking an API with the image name. A backend Lambda function queries DynamoDB to find the image location. The application can detect the user's device type (e.g., cellphone, computer, big-screen monitor) and set the appropriate header on the API Gateway. The Lambda function then retrieves the image location from DynamoDB based on the device type. With different entries for each resolution in the database, the Lambda function fetches the corresponding image from the appropriate S3 bucket and returns it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716289068050/ae488a32-f683-48e4-bd17-54e389e30d1f.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-high-priority-queuing-messaging-system">High Priority Queuing Messaging System</h3>
<p>Let's consider an insurance company where System A receives messages for different types of insurance: car, house, and bike. System B should process car insurance messages with higher priority.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716335855619/ef634d7a-7782-4396-9ea2-0ea124d669dd.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--- Application logic for system A ---&gt;</span>
{
    instype: CAR,
    accountno. = 12345678,
    amount = 500
}
</code></pre>
<p>Let's explore several design options.</p>
<p><strong>Option 1: RabbitMQ</strong></p>
<p>One potential solution involves using RabbitMQ or another message queue (MQ) service. RabbitMQ supports priority queues, allowing you to set a priority value in the message header.</p>
<p>System A sends messages to RabbitMQ. System A checks the insurance type. If it's car insurance, it sets a higher priority in the message header. RabbitMQ processes higher priority messages first.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716335806350/7be4b156-a1ef-43ab-8349-89a16966f3c3.png" alt class="image--center mx-auto" /></p>
<p><strong>Option 2: Amazon SQS</strong></p>
<p>A more common and robust solution leverages Amazon SQS. Although it does not support message priority natively, we can create separate queues for different priorities.</p>
<p>We create two SQS queues: one for car insurance messages and one for other insurance types. System A checks the insurance type. If the message is for car insurance, it goes to the high-priority SQS queue other messages go to the standard SQS queue.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716336301815/8f02a58b-1237-42ea-8078-756a5879ca69.png" alt class="image--center mx-auto" /></p>
<p>We use EC2 instances or AWS Lambda to process messages. For car insurance (high-priority queue), we use an auto-scaling EC2 group to handle varying loads efficiently. We deploy more powerful EC2 instances to ensure quick processing. For other insurances (standard queue), we use a smaller EC2 instance or a limited auto-scaling group to save costs ( can also use ASGs if required ). For Lambda, we adjust memory and concurrency settings to manage processing speed.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716336448600/b9722115-903d-4520-8ffc-34b0e90afe7d.png" alt class="image--center mx-auto" /></p>
<p><strong>Option 3: AWS EventBridge</strong></p>
<p>If we want to minimize logic within System A, we can use AWS EventBridge.</p>
<p>System A sends all messages to EventBridge without any filtering. EventBridge uses pattern matching to route messages based on the insurance type.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716336834558/dd16cfa5-cf03-45f3-b1ea-7653ec2a8875.png" alt class="image--center mx-auto" /></p>
<p>Messages for car insurance are sent to the car insurance SQS queue. Other messages are sent to a different SQS queue. Similar to the SQS setup, use EC2 or Lambda to process messages from the respective queues.</p>
<p><strong>SQS &amp; Amazon EventBridge</strong></p>
<p>Both queues can be configured with DLQs to handle message processing failures. DLQs ensure that unprocessed messages are saved for later reprocessing.</p>
<p>If EventBridge fails to deliver a message, it can send the message to a DLQ. However, once a message is delivered to an EC2 instance or Lambda, EventBridge does not handle failures. The application must manage DLQ integration.</p>
<hr />
<h3 id="heading-data-analytics-designs">Data analytics designs</h3>
<p>When it comes to data analytics, there are four main steps:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716365220128/f2340857-11c2-4c49-8c5b-c3e14d50073e.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p>Collect the data.</p>
</li>
<li><p>Transform those data as per the analytics requirement.</p>
</li>
<li><p>Query those data to find out the necessary information.</p>
</li>
<li><p>Create some sort of report that gives you some business insight.</p>
</li>
</ol>
<p>So if we divide this with services, this would look something like this:</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716365243791/eb0ad7a9-acd2-4e06-b5ea-e82a96585de7.png" alt class="image--center mx-auto" /></a></p>
<p>Let's start with the sample architecture.</p>
<h3 id="heading-query-and-report-on-click-stream">Query and Report on Click Stream</h3>
<p>Let's say you need to design an architecture that can query and report on some clickstream data. When we talk about clickstream, there has to be some sort of website, and you need to track all the clicks that users are doing. Generally, you stream it using some sort of streaming service such as Amazon Kinesis Data Firehose, or you could use Kafka as well.</p>
<p>Amazon Kinesis Data Firehose can dump all the data into Amazon Simple Storage Service (S3). As we already know, S3 is a very scalable and cost-effective object-based storage service. The data in S3 is kind of unstructured. Even if you put structured data or comma-separated data in S3, there are no tables defined in S3 because it's object-based storage.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716365470854/301d66c0-a483-4087-b4da-80fa6ac8f503.png" alt class="image--center mx-auto" /></p>
<p>This is where AWS Glue comes in.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716366399193/22014eba-549b-4503-beeb-6d62eeb5ad13.png" alt class="image--center mx-auto" /></a></p>
<p>Say we're working with a CSV file in an S3 bucket containing sales data. The file has columns for things like order ID, product name, price, quantity, and customer location.</p>
<ul>
<li><p><strong>Without AWS Glue:</strong> In raw S3 storage, this data is just a flat file. You wouldn't know the structure (columns) or data types (numeric, text) by looking at it directly. Analyzing or querying this data would be a manual process.</p>
</li>
<li><p><strong>With AWS Glue:</strong> You create a crawler in AWS Glue and point it to the location of your CSV file in S3. The crawler scans the file and automatically discovers the structure. Based on the scan, the crawler creates a schema in the Glue data catalog. This schema defines the table structure, including:</p>
<ul>
<li><p>Column names (order_id, product_name, etc.)</p>
</li>
<li><p>Data types (integer, string, etc.)</p>
</li>
</ul>
</li>
</ul>
<p>Now you have a clear understanding of your data. You can see the table structure and know what kind of information each column holds. This makes it much easier to query the data &amp; transform the data.</p>
<p>In essence, AWS Glue crawlers and the data catalog <strong>act as a bridge between your raw data in S3 and data processing or querying tools</strong>. They bring structure and understanding to your data, making it easier to work with and analyze.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716366593739/b4ca369b-3954-45d7-9c0b-2f53c75023dd.png" alt class="image--center mx-auto" /></a></p>
<p>You can also define dashboards using QuickSight, and in the QuickSight dashboard, you can reuse those Amazon Athena queries.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716366678018/2b8c38be-c359-49fb-89e5-67efe51c3e33.png" alt class="image--center mx-auto" /></a></p>
<hr />
<h3 id="heading-etl-and-data-warehouse">ETL and Data Warehouse</h3>
<p>ETL stands for Extract, Transform, and Load. The data collection part remains similar.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716365470854/301d66c0-a483-4087-b4da-80fa6ac8f503.png" alt class="image--center mx-auto" /></p>
<p>You have clickstream data going through Amazon Kinesis Data Firehose, dumping into Amazon S3. AWS Glue can define metadata and read data based on that from one S3 bucket, transform those data (such as removing some columns or changing the values based on certain criteria), and then load that data into another S3 bucket. That's the ETL part.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716367120013/f4ceb566-6ba8-4724-b858-d18b5290ccbd.png" alt class="image--center mx-auto" /></a></p>
<p>The data warehousing part can be done using Amazon Redshift.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716367155540/e031ca0a-ed81-4740-be88-06b9cb7b23d4.png" alt class="image--center mx-auto" /></a></p>
<p>In this case, Amazon Redshift, using Redshift Spectrum, is directly running SQL queries from the Amazon S3 bucket. Note that in this case, <strong>the data is not being loaded into Redshift tables</strong>. It is <strong>being read directly from S3 using Redshift Spectrum</strong>.</p>
<p>The alternative is that AWS Glue, after doing the ETL, can also load the data into Redshift tables.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716367306507/baf934e7-5d31-4c55-bc65-fd97ace06fb2.png" alt class="image--center mx-auto" /></a></p>
<p><strong>What's the difference between querying S3 data using Athena and loading data into Redshift and querying it?</strong></p>
<p>Athena is primarily for ad-hoc (on the fly), serverless queries on S3 data, making it ideal for quick, flexible data analysis without infrastructure management. Redshift is designed for more complex, high-performance analytics on structured data, suitable for data warehousing and persistent, large-scale querying.</p>
<p>Now, let's take a quick detour into AWS Glue.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716367867799/6b903433-3be3-4ea9-83f5-49bd58f16a9d.png" alt class="image--center mx-auto" /></p>
<p>As we can see, this is a pretty powerful service. AWS Glue is a serverless data integration service that makes it easier to <strong>discover, prepare, and combine data</strong> for analytics, machine learning, and application development. Serverless means it will scale as needed, and you will only pay per use.</p>
<p>As we saw in the previous system design, Glue crawlers can run on data, discover the types of columns and types of data in it, and create metadata. Glue <strong>can visually create ETL flows</strong> and <strong>supports Python, Spark, and Scala</strong>. Glue DataBrew can be used to enrich, clean, and normalize data without writing code. Glue Elastic Views allows you to use familiar SQL to combine and replicate data across different data sources.</p>
<hr />
<h3 id="heading-unified-catalog-across-multiple-data-stores">Unified Catalog across Multiple Data Stores</h3>
<p>For this system design, we have the input data sources as S3, RDS, and a database running on Amazon EC2.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716368100596/e107fa0b-08f6-42af-b8dd-851637797169.png" alt class="image--center mx-auto" /></a></p>
<p>We have to run AWS Glue, which creates that Glue data catalog. You can even join this data catalog across different data sources and run SQL queries using Redshift or Athena. You can also run big data processing using Amazon EMR, reading data from all these different sources using the same Glue data catalog.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716368473982/71a87aa3-f308-4711-8270-920e1d661a9b.png" alt class="image--center mx-auto" /></a></p>
<p>For dashboards and reporting, Amazon QuickSight is the service to do that, and QuickSight can utilize queries from Athena, Redshift, or EMR.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716368561525/51a1e1fc-3f2c-4407-ad1a-f011b88e0602.png" alt class="image--center mx-auto" /></a></p>
<hr />
<h3 id="heading-big-data-analysis-on-clickstream-data">Big Data Analysis on Clickstream Data</h3>
<p>To begin with let's take a look at Amazon EMR (Elastic MapReduce).</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716369270307/fd5e1f8f-3617-4569-b7a4-6dc119cd5d2d.png" alt class="image--center mx-auto" /></p>
<p>EMR is the managed big data platform from AWS. EMR runs open-source tools such as Apache Spark, Hive, HBase, Flink, Hudi, and Presto. EMR runs on EC2, EKS, or on-premises using EMR on Outposts. This <strong>takes away the management overhead of running your own big data cluster so that you can focus on the business problem</strong>. So whenever you need to do some big data processing, think of Amazon EMR.</p>
<p>One example of big data analysis on clickstream data could be the data getting dumped into Amazon S3 storage and then EMR reading from it.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716369485559/a12fcdec-d86f-4890-a475-02d20ad991aa.png" alt class="image--center mx-auto" /></a></p>
<p>However, there is an important consideration: Amazon EMR cannot directly read from S3 without metadata. AWS Glue must first crawl the data and create the Glue Data Catalog. Additionally, you can run machine learning algorithms using Amazon SageMaker, which can also read from the same Glue Data Catalog.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716369523249/d6bbd495-fb2b-4858-9d97-6c53d7168baa.png" alt class="image--center mx-auto" /></a></p>
<hr />
<h3 id="heading-in-stream-querying-amp-etl">In Stream Querying &amp; ETL</h3>
<p>In a traditional ETL pipeline, data is processed in batches after it's been stored. However, some scenarios require Real-time querying and in-stream ETL**.**</p>
<p><strong>What if your system design demands querying and transforming data as it arrives in the stream, rather than waiting for it to be dumped first?</strong></p>
<p>Storing everything can be expensive and unnecessary. You might only need a specific subset of the data for further analysis (<strong>Selective data storage</strong>).</p>
<p>To achieve this we utilize streaming services like Kinesis Data Streams or Managed Streaming for Kafka to continuously collect data. We then employ Amazon Kinesis Data Analytics to process the incoming data stream in real-time using Apache Flink.</p>
<p>We leverage SQL queries, Java, Scala, or Python programs within Kinesis Data Analytics to analyze and transform the data stream. This allows for selective processing, focusing only on relevant data &amp; send the transformed data to Amazon Kinesis Data Firehose, a service that acts as a delivery stream. Kinesis Data Firehose can be configured to selectively load the processed data into specific S3 buckets, ensuring only the essential information is stored. Now, the data stored in S3 can then be used for further processing with tools like AWS Glue, as previously discussed.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716371058888/e48a483f-740b-4b76-b9e2-d85aee146c64.png" alt class="image--center mx-auto" /></a></p>
<hr />
<h3 id="heading-data-lake">Data Lake</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716371653402/69f08f5d-fb96-4526-bc0e-438340dca368.png" alt class="image--center mx-auto" /></p>
<p>A Data Lake itself isn't a specific technology, but rather a design philosophy and approach to data management. It leverages a combination of existing services to achieve its core functionalities.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716372209843/2f071e36-2cb6-449d-9deb-a1f136d1a9ac.png" alt class="image--center mx-auto" /></a></p>
<p>The most critical aspect to remember is that a Data Lake stores vast amounts of data. Typically, Amazon S3 is at the core of a Data Lake due to its scalability, cost-effectiveness, and multiple storage tiers. Implementing lifecycle policies allows for the migration of data between these tiers, further optimizing storage costs. This flexibility and efficiency make S3 an ideal foundation for a Data Lake, enabling organizations to handle large volumes of data efficiently and cost-effectively.</p>
<hr />
<h3 id="heading-authentication-amp-authorization">Authentication &amp; Authorization</h3>
<p><strong>Authentication</strong> answers the question:</p>
<p><em>Do you have access to the application?</em></p>
<p>For example, when you log in to Tinder or Amazon, you provide a user ID and password, and if they match, you gain access.</p>
<p><strong>Authorization</strong> determines:</p>
<p><em>What can you do within the application once authenticated?</em></p>
<p>For instance, can you create a Kubernetes cluster or delete a database?</p>
<p>This is dictated by the permissions assigned to your account.</p>
<p><strong>System Design Overview</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716385555866/a078772d-6533-4c10-96d6-ee69904c5377.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>User and Identity Provider:</strong> Users provide their user ID and password. An identity provider (e.g., Active Directory, Auth0, AWS Cognito) stores these credentials. Upon successful authentication, the identity provider issues a token (JWT token).</p>
</li>
<li><p><strong>API Gateway and Token Validation:</strong> The application sends the user ID and JWT token in the API call header. The API Gateway validates the JWT token, either by directly checking with the identity provider or through a lambda authorizer function. This validation ensures the token is still valid and hasn't expired.</p>
</li>
<li><p><strong>Scopes and Policies:</strong> The identity provider can define scopes within the JWT token, indicating what actions the user can perform. Alternatively, a Lambda function (Lambda Authorizer) can handle this validation, returning policies dictating access permissions.</p>
</li>
<li><p><strong>Token Caching:</strong> To optimize performance, JWT tokens are cached in the API Gateway for a predefined period. This caching reduces the need for repeated validation, improving response times for subsequent requests.</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716389067814/7269a30a-a2c1-461d-849b-62f383d933e2.png" alt class="image--center mx-auto" /></p>
<hr />
]]></content:encoded></item><item><title><![CDATA[System Design Basics  II]]></title><description><![CDATA[AWS Well-Architected Framework
The AWS Well-Architected Framework helps cloud architects build secure, high-performing, resilient, and efficient infrastructure. It's based on six key areas called pillars:
1. Operational Excellence
Focus: How well you...]]></description><link>https://sujanmagar.com.np/system-design-basics-ii</link><guid isPermaLink="true">https://sujanmagar.com.np/system-design-basics-ii</guid><category><![CDATA[AWS]]></category><category><![CDATA[System Design]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Sat, 25 May 2024 15:00:01 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1716649156667/1fd6f953-b012-4d41-90a0-ee41d54e19dc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-aws-well-architected-framework"><strong>AWS Well-Architected Framework</strong></h3>
<p>The AWS Well-Architected Framework helps cloud architects build secure, high-performing, resilient, and efficient infrastructure. It's based on six key areas called pillars:</p>
<p><strong>1. Operational Excellence</strong></p>
<p><strong>Focus</strong>: How well you run and monitor your systems.</p>
<ul>
<li><p><strong>Automate Everything</strong>: Use code to manage your systems and processes.</p>
</li>
<li><p><strong>Small Changes</strong>: Make frequent, small updates to minimize risk.</p>
</li>
<li><p><strong>Regular Updates</strong>: Continuously improve your procedures.</p>
</li>
<li><p><strong>Plan for Failure</strong>: Think ahead and prepare for things going wrong.</p>
</li>
<li><p><strong>Learn from mistakes</strong>: Use past failures to improve your processes.</p>
</li>
<li><p><strong>Use Managed Services</strong>: Let AWS handle some tasks to reduce your workload.</p>
</li>
</ul>
<p><strong>2. Security</strong></p>
<p><strong>Focus</strong>: Protecting your systems and data.</p>
<ul>
<li><p><strong>Strong Access Controls</strong>: Only let the right people access your resources.</p>
</li>
<li><p><strong>Track Everything</strong>: Monitor and record all actions and changes.</p>
</li>
<li><p><strong>Multi-layer Security</strong>: Use multiple security measures at different levels.</p>
</li>
<li><p><strong>Automate Security</strong>: Use automated tools to enhance security.</p>
</li>
<li><p><strong>Protect Data</strong>: Encrypt data both when it's stored and when it's moving.</p>
</li>
<li><p><strong>Limit Direct Access</strong>: Reduce the need for manual data handling.</p>
</li>
<li><p><strong>Prepare for Incidents</strong>: Have a plan for dealing with security issues.</p>
</li>
</ul>
<p><strong>3. Reliability</strong></p>
<p><strong>Focus</strong>: Ensuring your system works correctly and consistently.</p>
<ul>
<li><p><strong>Automatic Recovery</strong>: Set up systems to fix themselves when problems occur.</p>
</li>
<li><p><strong>Test Failures</strong>: Regularly test how your system handles failures.</p>
</li>
<li><p><strong>Scale Horizontally</strong>: Use multiple smaller resources instead of one big one.</p>
</li>
<li><p><strong>No Capacity Guessing</strong>: Scale resources based on actual demand.</p>
</li>
<li><p><strong>Automate Changes</strong>: Use automation to manage changes to your infrastructure.</p>
</li>
</ul>
<p><strong>4. Performance Efficiency</strong></p>
<p><strong>Focus</strong>: Using resources efficiently.</p>
<ul>
<li><p><strong>Leverage Advanced Tech</strong>: Use AWS's services to handle complex tasks.</p>
</li>
<li><p><strong>Global Deployment</strong>: Deploy your systems worldwide for better performance.</p>
</li>
<li><p><strong>Serverless Options</strong>: Use serverless technologies to reduce management overhead.</p>
</li>
<li><p><strong>Frequent Experimentation</strong>: Regularly test different configurations to improve performance.</p>
</li>
<li><p><strong>Tech Matching</strong>: Choose the right technology for your specific needs.</p>
</li>
</ul>
<p><strong>5. Cost Optimization</strong></p>
<p><strong>Focus</strong>: Reducing unnecessary expenses.</p>
<ul>
<li><p><strong>Pay-as-You-Go</strong>: Only pay for what you use.</p>
</li>
<li><p><strong>Measure Efficiency</strong>: Track the cost vs. benefit of your services.</p>
</li>
<li><p><strong>Avoid Heavy Lifting</strong>: Let AWS manage infrastructure to save costs.</p>
</li>
</ul>
<p><strong>6. Sustainability</strong></p>
<p><strong>Focus</strong>: Building environmentally friendly systems.</p>
<ul>
<li><p><strong>Efficient Infrastructure</strong>: Use energy-efficient data centers.</p>
</li>
<li><p><strong>Reduce Carbon Footprint</strong>: Implement strategies to lower carbon emissions.</p>
</li>
<li><p><strong>Innovative Data Centers</strong>: Invest in new technologies for better efficiency.</p>
</li>
<li><p><strong>Data Management</strong>: Optimize storage to reduce waste.</p>
</li>
<li><p><strong>Transparency</strong>: Report on environmental impact.</p>
</li>
<li><p><strong>Education</strong>: Learn and promote sustainable practices.</p>
</li>
</ul>
<hr />
<h3 id="heading-three-tier-architecture">Three-tier Architecture</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716000145748/640691b3-a209-4970-a083-b1d160049182.png" alt class="image--center mx-auto" /></p>
<p>It has 3 distinct layers/architecture.</p>
<ol>
<li><p>Presentation tier (Frontend)</p>
</li>
<li><p>Logic tier (Backend)</p>
</li>
<li><p>Data tier (Database)</p>
</li>
</ol>
<p>A brief explanation of the three distinct layers of architecture:</p>
<ol>
<li><p><strong>Presentation Tier (Frontend)</strong>:</p>
<ul>
<li><p><strong>Description</strong>: This layer is responsible for the user interface and user experience. It’s what the end-user interacts with directly.</p>
</li>
<li><p><strong>Components</strong>: Web pages, mobile apps, desktop applications, and other client interfaces.</p>
</li>
<li><p><strong>Technologies</strong>: HTML, CSS, JavaScript, React, Angular, Flutter.</p>
</li>
</ul>
</li>
<li><p><strong>Logic Tier (Backend)</strong>:</p>
<ul>
<li><p><strong>Description</strong>: This layer contains the business logic and processes user inputs from the presentation tier. It’s responsible for data processing, application logic, and communications between the frontend and the database.</p>
</li>
<li><p><strong>Components</strong>: Application servers, APIs, microservices.</p>
</li>
<li><p><strong>Technologies</strong>: Java, Python, Node.js, Ruby on Rails, Django.</p>
</li>
</ul>
</li>
<li><p><strong>Data Tier (Database)</strong>:</p>
<ul>
<li><p><strong>Description</strong>: This layer is responsible for storing, retrieving, and managing data. It serves as the central repository where data is kept.</p>
</li>
<li><p><strong>Components</strong>: Databases, data storage systems.</p>
</li>
<li><p><strong>Technologies</strong>: SQL databases (MySQL, PostgreSQL), NoSQL databases (MongoDB, Cassandra).</p>
</li>
</ul>
</li>
</ol>
<p>These three layers work together to create a well-organized, scalable, and maintainable application architecture.</p>
<p><strong>Securing different tiers</strong></p>
<ol>
<li><p><strong>Presentation tier:</strong></p>
<ul>
<li><p><strong>Use HTTPS:</strong> Encrypt data transmitted between the client &amp; the server to prevent eavesdropping &amp; tampering.</p>
</li>
<li><p><strong>Input validation:</strong> Validate all user inputs or client-side (using JS) &amp; server-side to prervent injection attacks.</p>
</li>
</ul>
</li>
<li><p><strong>Application tier:</strong></p>
<ul>
<li><p><strong>Authentication &amp; Authorization</strong>: Implement strong authentication mechanisms like OAuth, JWT, or SAML to verify user identity. Use role-based access control (RBAC) or attribute-based access control (ABAC) to restrict access to resources based on user roles.</p>
</li>
<li><p><strong>Secure session Management:</strong> Use secure session management practices such as using unique session identifiers, setting expiration times &amp; using HTTPS for sesssion data transmission.</p>
</li>
</ul>
</li>
<li><p><strong>Data tier:</strong></p>
<ul>
<li><p><strong>Data Encryption</strong>: Encrypt sensitive data at rest (using database encryption) and in transit (using TLS/SSL) to protect it from unauthorized access.</p>
</li>
<li><p><strong>Database security best practices:</strong> Follow database security best practices such as keeping db s/w update, applying patches and regularly auditing db access logs.</p>
</li>
</ul>
</li>
</ol>
<p><strong>Three tier architecture on AWS</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716000244857/55cb4e30-0006-4921-b742-33e9cf6a72ff.png" alt class="image--center mx-auto" /></p>
<p><strong>Can you guess single point of failures in the above architecture?</strong></p>
<ul>
<li><p>Yes there are multiple points. Web server, App server and the DB.</p>
</li>
<li><p>About the load balancer, they're actually highly available, they span across 3 AZs under the hood. It just appears like a single aspect.</p>
</li>
</ul>
<p><strong>Then, how to make them highly available?</strong></p>
<ul>
<li>Deploying into multi AZs.</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716000731877/4caeace0-d9a3-44bf-a0a6-a5c3d1d96d2f.png" alt class="image--center mx-auto" /></p>
<p><strong>For network security,</strong></p>
<ul>
<li><p>We can deploy ELB in public subnet, while keeping web &amp; app server in private subnets.</p>
</li>
<li><p>We can use WAF with ELB.</p>
</li>
<li><p>Using NACLs and SGs to enhance the security for instances.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716000835963/8ce47352-87cb-4280-8fe4-891388557f2b.png" alt class="image--center mx-auto" /></p>
<p><strong>What about database?</strong></p>
<ul>
<li><p>We can use either SQL or NoSQL database.</p>
</li>
<li><p>Prefer AWS native databases. Say, for Aurora, it has Multi AZ, Global database replication features just to mention few.</p>
</li>
<li><p>For database optimization, we can use read replica, caching layer &amp; query tuning.</p>
</li>
</ul>
<p><strong>A well architected 3 tiered architecture example:</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716001531533/493f307c-72ce-42d6-a5ba-21ae4e078e5a.png" alt class="image--center mx-auto" /></p>
<p><strong>Three-Tier Architecture with Serverless</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716005415534/7cd99311-1a18-470a-803d-a113d01db88b.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>S3 is used for serving static contents while any interactive contents are handle using API through API Gateway. Using lambda as compute and Amazon Aurora as database.</p>
</li>
<li><p><strong>Amazon S3 (Simple Storage Service)</strong> is designed for high durability, availability, and scalability. It can handle massive amounts of data and serves static content such as images, videos, CSS, and JavaScript files. S3 automatically scales to meet the needs of your application, and its integration with Amazon CloudFront (a Content Delivery Network) enhances performance and availability by distributing content closer to users globally.</p>
</li>
<li><p><strong>Amazon API Gateway</strong> serves as the front door for applications to access data, business logic, or functionality from backend services. It handles thousands of concurrent API calls and scales seamlessly with your application’s traffic.</p>
<p>  <strong>AWS Lambda</strong> is a serverless compute service that automatically scales up and down based on the number of incoming requests. Each invocation of a Lambda function is run in a separate execution environment, allowing for high concurrency without the need to manage servers.</p>
</li>
<li><p><strong>Amazon Aurora</strong> is a MySQL and PostgreSQL-compatible relational database built for the cloud, combining the performance and availability of high-end commercial databases with the simplicity and cost-effectiveness of open-source databases.</p>
</li>
</ul>
<p><strong>Three-Tier Architecture with K8's</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716005854829/6e86e0d5-602b-49d8-9202-a8b2818bfbac.png" alt class="image--center mx-auto" /></p>
<p><strong>Description:</strong></p>
<ul>
<li><p>Web/App running in a container within a pod.</p>
</li>
<li><p>Pods can run either in EC2 worker node under EKS service or Fargate.</p>
</li>
<li><p>We make this scalable using K8's scaling constructs which is Replica Set, HPA (horizontal pod autoscaler) &amp; Cluster Autoscaler.</p>
</li>
<li><p>The load balancer fronting the webserver will be ALB ingress while in the back-end, the ELB could be another ingress or a K8's service.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Encryption 101]]></title><description><![CDATA[Encryption
Encryption is a process that converts data into a coded form to prevent unauthorized access. It uses algorithms and keys to transform readable data (plaintext) into an unreadable format (ciphertext). Only authorized parties with the correc...]]></description><link>https://sujanmagar.com.np/encryption-101</link><guid isPermaLink="true">https://sujanmagar.com.np/encryption-101</guid><category><![CDATA[AWS]]></category><category><![CDATA[encryption]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Thu, 23 May 2024 02:50:20 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1716432588011/b1bcafa9-beb1-4431-a99c-7ed4a79cff71.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-encryption">Encryption</h3>
<p>Encryption is a process that converts data into a coded form to prevent unauthorized access. It uses algorithms and keys to transform readable data (plaintext) into an unreadable format (ciphertext). Only authorized parties with the correct decryption key can revert the ciphertext back to plaintext.</p>
<p><a target="_blank" href="https://learn.cantrill.io/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716422657068/70bb9999-19f8-4215-8355-56378e6e52e7.png" alt class="image--center mx-auto" /></a></p>
<h3 id="heading-encryption-at-rest">Encryption at Rest</h3>
<p>Encryption at rest refers to encrypting data stored on a disk or other storage media. This protects the data from unauthorized access when it is not being transmitted or actively used. Common use cases include encrypting files on hard drives, databases, or cloud storage.</p>
<p><a target="_blank" href="https://learn.cantrill.io/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716422750694/ead3f321-0229-43be-ac23-b4c0d5fd8bc1.png" alt class="image--center mx-auto" /></a></p>
<p><strong>Benefits:</strong></p>
<ul>
<li><p>Protects data from physical theft of devices</p>
</li>
<li><p>Safeguards against unauthorized access in case of a data breach</p>
</li>
<li><p>Ensures compliance with data protection regulations</p>
</li>
</ul>
<h3 id="heading-encryption-in-transit">Encryption in Transit</h3>
<p>Encryption in transit protects data as it moves from one location to another, such as over the internet or a private network. It ensures that data remains confidential and integral while being transmitted between clients, servers, and other systems.</p>
<p><a target="_blank" href="https://learn.cantrill.io/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716423121834/2175785e-5222-4a46-a8dc-fc335593d1ee.png" alt class="image--center mx-auto" /></a></p>
<p><strong>Benefits:</strong></p>
<ul>
<li><p>Prevents eavesdropping and man-in-the-middle attacks</p>
</li>
<li><p>Ensures data integrity during transmission</p>
</li>
<li><p>Secures sensitive information exchanged over networks</p>
</li>
</ul>
<hr />
<h3 id="heading-public-amp-private-key">Public &amp; Private Key</h3>
<p><a target="_blank" href="https://learn.cantrill.io/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716429739846/37501bb6-e982-4f3f-ac34-de4c3c9f39e2.png" alt class="image--center mx-auto" /></a></p>
<p><strong>Public Key:</strong> This key is intended to be shared publicly and is used for encryption. It allows anyone to encrypt a message or data that can only be decrypted by the corresponding private key. When you want to send a secure message to someone, you use their public key to encrypt it. However, even if someone knows your public key, they cannot decrypt messages encrypted with it.</p>
<p><strong>Private Key:</strong> This key must be kept secret and is used for decryption. It allows you to decrypt messages or data that have been encrypted with your public key. Since only you should have access to your private key, only you can decrypt messages encrypted with your public key.</p>
<hr />
<h3 id="heading-types-of-encryption">Types of Encryption</h3>
<p><strong>1. Symmetric Encryption:</strong></p>
<ul>
<li><p>Uses a single key for both encryption and decryption</p>
</li>
<li><p>Faster and more efficient for large data volumes</p>
</li>
<li><p>Examples: AES (Advanced Encryption Standard), DES (Data Encryption Standard)</p>
</li>
</ul>
<p><a target="_blank" href="https://learn.cantrill.io/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716423256078/1d5015f4-c53d-4863-8017-ae0bc416713a.png" alt class="image--center mx-auto" /></a></p>
<p><strong>2. Asymmetric Encryption:</strong></p>
<ul>
<li><p>Uses a pair of keys: a public key for encryption and a private key for decryption</p>
</li>
<li><p>Provides strong security for data transmission</p>
</li>
<li><p>Examples: RSA (Rivest-Shamir-Adleman), ECC (Elliptic Curve Cryptography)</p>
</li>
</ul>
<p><a target="_blank" href="https://learn.cantrill.io/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716423311869/bbebd438-3593-4e60-8ea0-d84af8a539df.png" alt class="image--center mx-auto" /></a></p>
<p><strong>3. Hybrid Encryption:</strong></p>
<ul>
<li><p>Combines symmetric and asymmetric encryption</p>
</li>
<li><p>Often used in protocols like SSL/TLS where a symmetric key is exchanged using asymmetric encryption</p>
</li>
</ul>
<hr />
<h3 id="heading-client-amp-server-side-encryption">Client &amp; Server Side Encryption</h3>
<p><strong>Client-Side Encryption</strong></p>
<p>Client-side encryption involves <strong>encrypting data on the client’s side before it is sent to a server or cloud storage</strong>. The client retains control of the encryption keys, providing a higher level of security.</p>
<p><strong>Benefits:</strong></p>
<ul>
<li><p>Data is protected before it leaves the client’s environment</p>
</li>
<li><p>Client retains control over encryption keys</p>
</li>
<li><p>Reduces the risk of data exposure even if the server is compromised</p>
</li>
</ul>
<p><strong>Challenges:</strong></p>
<ul>
<li><p>Managing and securing encryption keys can be complex</p>
</li>
<li><p>Performance overhead on the client device</p>
</li>
</ul>
<p><strong>Server-Side Encryption</strong></p>
<p>Server-side encryption occurs when <strong>data is encrypted after it is sent to the server or storage system</strong>. The server handles the encryption and decryption processes, often using managed encryption services provided by cloud providers.</p>
<p><strong>Benefits:</strong></p>
<ul>
<li><p>Simplifies key management for clients</p>
</li>
<li><p>Integrates seamlessly with cloud storage services</p>
</li>
<li><p>Provides built-in encryption options with minimal configuration</p>
</li>
</ul>
<p><strong>Challenges:</strong></p>
<ul>
<li><p>Relies on the server’s security measures</p>
</li>
<li><p>Potential exposure if the server is compromised</p>
</li>
</ul>
<hr />
<h3 id="heading-digital-signature">Digital Signature</h3>
<p>A digital signature is a cryptographic technique that ensures the authenticity and integrity of a message, document, or software. It provides a way to verify that a message was created by a known sender (authentication) and that it was not altered in transit (integrity).</p>
<p>Applications: Email verification, software distribution, financial transactions.</p>
<p><strong>How Does it Work?</strong></p>
<ol>
<li><p><strong>Hashing:</strong> The message or document is processed through a hash function to create a unique fixed-size string of characters, known as the hash value or message digest.</p>
</li>
<li><p><strong>Encryption:</strong> The hash value is encrypted using the sender’s private key, creating the digital signature. This private key is part of a public/private key pair used in asymmetric encryption.</p>
</li>
<li><p><strong>Verification:</strong> The recipient decrypts the digital signature using the sender’s public key. This produces the original hash value. The recipient also hashes t</p>
<p> he received the message or document and compares the two hash values. If they match, the message is verified as authentic and unaltered.</p>
</li>
</ol>
<p>Applications: Email verification, software distribution, financial transactions.</p>
<p><a target="_blank" href="https://learn.cantrill.io/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716430218402/0f76c85e-975f-472c-9bb3-5c99b5909e07.png" alt /></a></p>
<hr />
<h3 id="heading-steganography">Steganography</h3>
<p>Steganography is the practice of hiding information within another file, message, image, or video. Unlike encryption, which makes data unreadable without a key, steganography hides the existence of the message itself.</p>
<p><strong>How Does it Work?</strong></p>
<ol>
<li><p><strong>Embedding Data:</strong> The hidden message is embedded into a carrier medium (e.g., an image, audio, or video file) by slightly altering the least significant bits of the carrier file. These alterations are usually imperceptible to the human eye or ear.</p>
</li>
<li><p><strong>Extraction:</strong> The recipient uses a predefined algorithm or key to extract the hidden message from the carrier medium.</p>
</li>
</ol>
<p>Applications: Covert communication, digital watermarking, secure information hiding.</p>
<p>Example: Imagine you have a digital photo with a clear blue sky. You can use steganography software to slightly modify the color values of some pixels in the sky. These changes might be so subtle that they're undetectable to the naked eye, but the software can interpret them as a hidden message. Someone who knows the secret technique and has the right software can then extract the hidden message from the image.</p>
<p>Steganography doesn't necessarily make a message secure. If someone suspects hidden information, they might use steganalysis techniques to try to uncover it.</p>
<hr />
<h3 id="heading-envelope-encryption">Envelope Encryption</h3>
<p>Envelope encryption is a technique used to improve the performance and security of encrypting large amounts of data. It combines symmetric and asymmetric encryption to efficiently protect data while maintaining strong security.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1716426723723/0ec2cb72-6445-4a1d-8aa5-1bfb9c9471fa.png" alt class="image--center mx-auto" /></p>
<p><strong>How Envelope Encryption Works</strong></p>
<ol>
<li><p><strong>Data Encryption Key (DEK):</strong> A DEK is a symmetric key used to encrypt and decrypt actual data. It can be generated by AWS KMS or by the user and then encrypted using a KEK/CMK. Symmetric encryption is chosen for its speed and efficiency, making it suitable for encrypting large data sets.</p>
</li>
<li><p><strong>Encrypt Data:</strong> The data is encrypted using the DEK. This step produces the ciphertext of the data.</p>
</li>
<li><p><strong>Key Encryption Key (KEK):</strong> The <strong>DEK itself is then encrypted using a different key, called the Key Encryption Key (KEK)</strong>. KEKs are often asymmetric keys, providing strong security for the DEK.</p>
</li>
<li><p><strong>Store Encrypted DEK:</strong> The <strong>encrypted DEK (encrypted with the KEK) is stored alongside the encrypted data</strong>. This allows the DEK to be retrieved and decrypted only by authorized entities with access to the KEK.</p>
</li>
<li><p><strong>Decryption Process:</strong> To decrypt the data, the encrypted DEK is first decrypted using the KEK to obtain the original DEK. The DEK is then used to decrypt the data, returning it to plaintext.</p>
</li>
</ol>
<hr />
<h3 id="heading-aws-key-management-service-kms">AWS Key Management Service (KMS)</h3>
<p>AWS Key Management Service (KMS) is <strong>a managed service</strong> that makes it <strong>easy to create and control cryptographic keys</strong> used for encryption across AWS services and applications. KMS integrates with various AWS services to provide seamless encryption and key management.</p>
<p><strong>Key Features:</strong></p>
<ul>
<li><p>Centralized Key Management: Create, rotate, and manage keys from a central location.</p>
</li>
<li><p>Integration: Easily integrates with AWS services like S3, EBS, RDS, Lambda, and more for automatic encryption.</p>
</li>
<li><p>Fine-Grained Access Control: Define and enforce policies for key usage and access through AWS Identity and Access Management (IAM).</p>
</li>
<li><p>Auditing: Provides detailed logging of all key usage through AWS CloudTrail, helping with compliance and auditing.</p>
</li>
<li><p>High Availability: Ensures keys are available and secure, leveraging AWS's robust infrastructure.</p>
</li>
</ul>
<p><strong>Customer Master Key (CMK)</strong></p>
<p>A CMK is a key stored in AWS KMS that is used to <strong>encrypt and decrypt data encryption keys (DEKs)</strong>. It serves as a key encryption key (KEK).</p>
<hr />
<h3 id="heading-managing-customer-master-keys-cmks-in-aws-kms">Managing Customer Master Keys (CMKs) in AWS KMS</h3>
<p>When using AWS Key Management Service (KMS) to secure your data, you have the option to manage your Customer Master Keys (CMKs) yourself or to let AWS KMS manage them for you. Both approaches come with their own benefits, challenges, and considerations.</p>
<p><strong>AWS-Managed CMKs</strong></p>
<p>AWS KMS provides AWS-managed CMKs, which are automatically created, rotated, and managed by AWS on your behalf. These keys are used by various AWS services to encrypt your data without requiring manual intervention.</p>
<ul>
<li><p><strong>Pros:</strong> Simplified management, seamless integration, cost-effective.</p>
</li>
<li><p><strong>Cons:</strong> Limited control and customization.</p>
</li>
</ul>
<p><strong>Customer-Managed CMKs</strong></p>
<p>Customer-managed CMKs are created, managed, and controlled by you. You have full control over the key lifecycle, including creation, rotation, and deletion, as well as the policies and permissions associated with the keys.</p>
<ul>
<li><p><strong>Pros:</strong> Full control, customization, compliance support.</p>
</li>
<li><p><strong>Cons:</strong> Increased complexity, administrative responsibility, higher cost.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[System Design Basics]]></title><description><![CDATA[The Monolith Architecture
In software development, a monolithic architecture is an approach where all the components of an application are built as a single, indivisible unit. This means that the application's codebase is typically a single codebase,...]]></description><link>https://sujanmagar.com.np/system-design-basics</link><guid isPermaLink="true">https://sujanmagar.com.np/system-design-basics</guid><category><![CDATA[AWS]]></category><category><![CDATA[System Design]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Fri, 17 May 2024 04:05:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1715918719343/65e0eb1c-631f-44fe-88a9-808801370475.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-the-monolith-architecture">The Monolith Architecture</h3>
<p>In software development, a monolithic architecture is an approach where <strong>all the components of an application are built as a single, indivisible unit</strong>. This means that the application's codebase is typically a single codebase, and all the functionality is developed, deployed, and scaled as a single unit.</p>
<p>Pros of Monolithic Architecture:</p>
<ul>
<li><p><strong>Simplicity:</strong> Easy to develop and deploy, with all code in one place.</p>
</li>
<li><p><strong>Easy debugging:</strong> Easier to track down issues since all code is centralized.</p>
</li>
<li><p><strong>Performance:</strong> Can offer good performance when optimized due to minimal communication overhead.</p>
</li>
</ul>
<p>Cons of Monolithic Architecture:</p>
<ul>
<li><p><strong>Scalability:</strong> Difficult to scale as the application grows, requiring entire application replication.</p>
</li>
<li><p><strong>Agility:</strong> Slow to adapt to changes, as a small change might require a full redeployment.</p>
</li>
<li><p><strong>Single point of failure:</strong> If one part crashes, the entire application can be affected.</p>
</li>
</ul>
<p><strong>Can you use API with monolith?</strong></p>
<ul>
<li><p>Yes, you can. API has nothing to do with monolith or microservices.</p>
<p>  <a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715603542796/2d7f88b1-19db-429b-8493-7bc4cb736768.png" alt class="image--center mx-auto" /></a></p>
<p>  Monolith can be fronted by either an API Gateway or a Load balancer. And, when different URLs or paths hit API/LB, they forward all the calls to the same monolithic. This monolithic will have entry functions or entry paragraph which will check the URL/paths and invoke different functions within the monolithic and execute the logic accordingly.</p>
</li>
</ul>
<p><strong>Issue of Scaling</strong></p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715603590577/b4717936-2320-4dda-991a-a85f127d72b2.png" alt class="image--center mx-auto" /></a></p>
<p>Say, the traffic for store/get component increases, then we can see CPU reaching its limit.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715603635010/96fae4c2-5473-42f9-9e0a-ba35cdc3b89c.png" alt class="image--center mx-auto" /></a></p>
<p>Now, instead of scaling just the store/get component, you've to scale the entire monolith.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715603660156/49c97eb2-5575-4559-aed7-ccc98b205598.png" alt class="image--center mx-auto" /></a></p>
<h3 id="heading-the-microservices">The microservices</h3>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715603695214/d836ce27-cdb1-4e1a-93e4-f931d1ee3d80.png" alt class="image--center mx-auto" /></a></p>
<p>Different components will have separate codebase and with different virtual machines.</p>
<p>Now, say the traffic for store/get component increases then, instead of increasing all VMs, only the required VM is scaled.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715603762679/4ca60807-13e2-4d14-b892-9851de4be4d3.png" alt class="image--center mx-auto" /></a></p>
<p>Now, since the backend servers operate independently and can be managed by separate teams, these microservices can be developed in various programming languages based on the needs.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715603797482/0a16c507-e459-4a7c-8492-46ec0961132c.png" alt class="image--center mx-auto" /></a></p>
<p><strong>Characteristics of microservice architectures</strong></p>
<ul>
<li><p><strong>Independent:</strong> Microservices are self-contained units with well-defined functionalities.</p>
</li>
<li><p><strong>Scaling:</strong> Microservices can be scaled independently based on their specific needs.</p>
</li>
<li><p><strong>Governance:</strong> Each microservice can have its governance model, such as API contracts and versioning. This provides better control and flexibility for individual services.</p>
</li>
<li><p><strong>Deployment:</strong> Microservices can be independently deployed using technologies like containers or virtual machines.</p>
</li>
<li><p><strong>Testing:</strong> Smaller codebases in each service make testing quicker and more focused.</p>
</li>
<li><p><strong>Functionality:</strong> Microservices are built around specific business capabilities, promoting modularity, reusability, and easier maintenance of the overall application.</p>
</li>
</ul>
<p><strong>Important:</strong> Not required to follow every characteristic.</p>
<hr />
<h3 id="heading-deploying-microservices-in-aws">Deploying microservices in AWS</h3>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715603837725/cc3cc23d-c7c8-4242-8c81-92170b1fcbed.png" alt class="image--center mx-auto" /></a></p>
<p>An EC2-based microservice architecture. Depending upon the requirements, we're using different instance families.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715603906376/5aa765e8-1935-4d4c-8e82-58daf3966dcc.png" alt class="image--center mx-auto" /></a></p>
<p>A serverless microservice architecture using lambda. Lambda handles the autoscaling automatically. They can also be fronted by ELB/API Gateway.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715603936938/dda4391c-9262-44fe-8677-ecf64dcbd01b.png" alt class="image--center mx-auto" /></a></p>
<p>Now, microservice architecture using containerized application and that run within Elastic Kubernetes Service (EKS) or Elastic Container Service (ECS), Here, as well they can be fronted by ELB/API Gateway.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715603951950/913072a3-8ed5-4ba5-a1b5-5db110bef3a1.png" alt class="image--center mx-auto" /></a></p>
<p>For Kubernetes, each microservice is fronted by different services as ServiceA, ServiceB and ServiceC and the code for each microservice will be running in a container and this container will run in a pod. And all these are fronted by a single ingress, which will be an ALB.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715603970123/acf635fd-5c36-4b6d-b63c-c9b35ecae3ca.png" alt class="image--center mx-auto" /></a></p>
<p>Since each microservice is independent of each other and can be even coded in different programming languages, you can mix and match all these AWS services.</p>
<p>For example:</p>
<ul>
<li><p>store/get can run on a pod where the backend of the microservice is dockerized into a container.</p>
</li>
<li><p>store/post can be hosted on Amazon EC2.</p>
</li>
<li><p>store/delete can run on AWS Lambda.</p>
</li>
</ul>
<p>So, depending on the requirements, you can use different services.</p>
<p>That is the beauty of microarchitecture.</p>
<hr />
<h3 id="heading-load-balancer">Load Balancer</h3>
<p><img src="https://github.com/aws/elastic-load-balancing-tools/blob/master/images/ELB.png?raw=true" alt="ELB.png" class="image--center mx-auto" /></p>
<p>Before load balancers, web applications struggled with uneven traffic distribution, limited availability, and scalability issues. Single servers often became overwhelmed, leading to slow response times and downtime. Adding capacity was manual and inefficient. Security was also a concern.</p>
<p>Load balancers now distribute traffic, improve availability by rerouting from failed servers, and enhance scalability by adding or removing servers as needed. They also offload SSL/TLS, ensure session persistence, and provide an additional security layer.</p>
<hr />
<h3 id="heading-api-amp-api-gateway">API &amp; API Gateway</h3>
<p><strong>What is an API?</strong></p>
<p>APIs are <strong>interfaces</strong> that define how software components should interact. They <strong>specify the methods and data formats that applications can use to request and exchange information</strong>. APIs are typically used to define how different software systems or components should communicate with each other, providing a higher-level abstraction that simplifies the development of software applications.</p>
<p>Imagine you're at a restaurant. You (the user) tell the waiter (the API) what you want (make a request), the waiter relays your order to the kitchen (the other application), the kitchen prepares your food (processes the request), and the waiter brings it back to you (delivers the response).</p>
<p>APIs are everywhere in the modern world and are what make many of the things we take for granted possible. For instance, when you use a rideshare app, the app uses an API to connect to the rideshare company's system and request a ride for you. Similarly, when you use a weather app, the app uses an API to get weather data from a weather service.</p>
<p><strong>What is an API Gateway?</strong></p>
<p>An API Gateway is a server that acts as an API front-end, receiving API requests, enforcing throttling and security policies, passing requests to the back-end service, and then passing the response back to the requester. The API Gateway encapsulates the internal system architecture and provides an API that is tailored to the client's needs.</p>
<p><strong>Functions of API Gateway</strong></p>
<ul>
<li><p><strong>Single Entry Point:</strong> An API gateway provides a <strong>unified interface for client applications to access all backend APIs</strong>. This eliminates the need for client applications to interact with individual backend URLs, streamlining communication and reducing complexity.</p>
</li>
<li><p><strong>Traffic Management:</strong> API gateways efficiently route incoming API requests to the appropriate backend services. They <strong>can distribute traffic load across multiple backend instances</strong> to ensure scalability and prevent overloading any single service.</p>
</li>
<li><p><strong>Security:</strong> API gateways enforce security measures to protect backend services from unauthorized access. They <strong>can implement authentication and authorization mechanisms</strong> to restrict access based on user roles or permissions.</p>
</li>
<li><p><strong>Monitoring and Analytics:</strong> API gateways <strong>track API usage patterns</strong> and provide valuable insights. You can monitor metrics like request rates, latencies, and error codes to identify potential issues and optimize API performance.</p>
</li>
<li><p><strong>Transformation:</strong> API gateways can transform data between formats to ensure compatibility between client applications and backend services. This eliminates the need for developers to write separate code for data formatting on each side.</p>
</li>
<li><p><strong>Versioning:</strong> API gateways <strong>can manage different versions of APIs simultaneously</strong>. This allows developers to introduce new features or make changes to existing APIs without disrupting existing client applications that are using older versions.</p>
</li>
<li><p><strong>Caching:</strong> API gateways can <strong>cache frequently accessed data</strong> to improve performance and reduce load on backend services. This can be especially beneficial for static data or data that doesn't change frequently.</p>
</li>
<li><p><strong>Policy Enforcement:</strong> API gateways can <strong>enforce policies that govern how APIs are used</strong>. These policies can include rate limiting, throttling, and quota restrictions to prevent abuse and ensure fair use of resources.</p>
</li>
<li><p><strong>Integration with Diverse Backends:</strong> API gateways <strong>can connect to various backend services, regardless of their programming language or technology stack</strong>. This flexibility allows you to integrate different backend systems and expose them as a unified set of APIs.</p>
</li>
</ul>
<hr />
<h3 id="heading-application-load-balancer-amp-amazon-api-gateway">Application Load Balancer &amp; Amazon API Gateway</h3>
<p><strong>Application Load Balancer</strong></p>
<ul>
<li><p>Automatically distributes incoming traffic across backend targets</p>
</li>
<li><p>Layer 7 load balancer</p>
</li>
<li><p>Infrastructure managed by AWS, highly available, elastic</p>
</li>
</ul>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715613055711/3b108348-bc93-418e-9643-822b285e92f3.png" alt class="image--center mx-auto" /></a></p>
<p><strong>API Gateway</strong></p>
<ul>
<li><p>Fully managed and serverless API service from AWS</p>
</li>
<li><p>Automatically scales up and down</p>
</li>
<li><p>Infrastructure managed by AWS, highly available, elastic</p>
</li>
</ul>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715613159615/58dd68bf-63c1-47b7-937d-a675eeaba58e.png" alt class="image--center mx-auto" /></a></p>
<p><strong>What is the difference?</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715613621875/1163c1f0-9d4b-4ec0-83cd-4e13d6f62553.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715613707462/45012ca6-3b94-409e-baf8-946228da2595.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-vertical-scaling-amp-horizontal-scaling">Vertical Scaling &amp; Horizontal Scaling</h3>
<p><strong>Vertical Scaling (Scaling Up)</strong>: This method involves boosting the capabilities of a single machine by adding more resources like CPU, memory, storage, or a faster network card. Imagine upgrading your computer's RAM to handle more complex software.</p>
<p><strong>Horizontal Scaling (Scaling Out)</strong>: Here, instead of beefing up a single machine, you add more machines to distribute the workload. This is like adding more lanes to a highway to handle increased traffic. New machines are brought into the system and configured to work together as a team.</p>
<p><strong>Different types of scaling for different AWS services</strong></p>
<ol>
<li><p><strong>EC2 instance</strong></p>
<ul>
<li><p>Vertical Scaling: ALB ---&gt; EC2. We can do vertical scaling, provisioning bigger and more powerful instance when the traffic goes up.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715645303475/cb1aa088-901d-4c9d-85ca-17defddb6998.png" alt class="image--center mx-auto" /></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715645388912/30519953-f3a1-45a9-abcf-baed3042658f.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Horizontal Scaling: ALB --&gt; ASGs. Depending on our requirements, ASGs will either add up or remove instances.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715645959196/3a9ae24b-788f-457b-9378-e0462d39c86b.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p><strong>Lambda</strong></p>
<ul>
<li><p>Lambda can only scale horizontally only.</p>
</li>
<li><p>For each traffic, a new instance of your lambda scales up.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715646113351/b44c8aec-72d2-4901-95cf-65fc8ac3795a.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p><strong>Container using EC2</strong></p>
<ul>
<li><p>Your container is running inside a pod.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715646586500/1a9b5d06-c4ac-4e9a-8f14-7afcd3d561ad.png" alt class="image--center mx-auto" /></p>
<p>  A single pod can handle multiple traffic connections. But with each traffic, the CPU &amp; memory utilization will go up. And at certain point, using Horizontal Pod Autoscaler (HPA), it'll scale. During horizontal scaling of container, it doesn't create another container in the same pod. The smallest unit of scaling is pod. Thus, it'll create another pod within that EC2 node.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715646860788/f1a8324b-8588-466d-b5f9-bc368d7109a6.png" alt class="image--center mx-auto" /></p>
<p>  <strong>But what will happen when the EC2 is filled up?</strong></p>
<p>  Each EC2, depending upon the family type, can only have a certain number of pods. As you put more pods in the same EC2, the CPU utilization of this EC2 also goes up. So, at a certain point, it is required to scale the EC2 node, and we call it Cluster Autoscaler.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715647501029/c9e00f10-65fd-41b9-843e-f5fd68bb4cc2.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p><strong>Container using Fargate</strong></p>
<ul>
<li><p>Underlying infrastructure node is managed by AWS.</p>
</li>
<li><p>So, we're starting with one pod, and as the traffic goes up, the no. of pods increases. Under the hood, all infrastructure is managed.</p>
</li>
</ul>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715647711489/0b2ff9bb-fefe-4e8f-a0b6-3e229847fbf6.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-synchronous-amp-asynchronous-event-driven-architectures">Synchronous &amp; Asynchronous (Event Driven) Architectures</h3>
<p><strong>Synchronous Architecture</strong></p>
<ol>
<li><p>In a synchronous architecture, operations are executed one after the other, in a sequential manner.</p>
</li>
<li><p>When a request is made to a synchronous system, the system blocks further execution until the operation is completed and a response is returned.</p>
</li>
<li><p>Synchronous systems are easier to understand and debug, as the flow of operations is straightforward.</p>
<p> <a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715650804682/645a9101-4faa-457c-87a3-be11b1681086.png" alt /></a></p>
</li>
<li><p>However, they can suffer from scalability issues, especially in scenarios where there are many concurrent requests, as each request must wait for the previous one to complete.</p>
<p> <a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715650849681/d5f82f3a-11c4-4700-8a75-272bf2593f80.png" alt class="image--center mx-auto" /></a></p>
<p> At certain point, following condition may occur.</p>
<p> <a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715650901035/159904ec-053c-4281-b92b-80adcd44478c.png" alt class="image--center mx-auto" /></a></p>
<p> <strong>Challenges of Synchronous Architecture:</strong></p>
<ul>
<li><p>All components must scale together,</p>
</li>
<li><p>Consumer needs to resend transaction for re-processing incase of failure,</p>
</li>
<li><p>Expensive approach.</p>
</li>
<li><p>Error handling in synchronous systems can be more complex, as failures at any step can result in the entire operation failing.</p>
</li>
</ul>
</li>
</ol>
<p><strong>Asynchronous (Event-Driven) Architecture:</strong></p>
<ul>
<li><p>In an asynchronous architecture, operations are not executed immediately. Instead, they are queued up and processed later.</p>
</li>
<li><p>When a request is made to an asynchronous system, the system does not block further execution. It accepts the request, queues it up, and continues with other operations.</p>
<p>  <a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715651268723/1e2c7827-28ac-4002-8822-f1ca49461503.png" alt class="image--center mx-auto" /></a></p>
</li>
<li><p>Asynchronous systems are more scalable, as they can handle a large number of concurrent requests more efficiently than synchronous systems.</p>
<p>  <a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715651380022/c9a1e107-9d7b-430f-92e4-4eaac5268a62.png" alt class="image--center mx-auto" /></a></p>
</li>
<li><p>In this event-driven architecture, the key component for handling busy traffic is SQS (Simple Queue Service). SQS acts as a buffer, absorbing spikes in incoming requests and ensuring that no data is lost even during high traffic periods. Its ability to decouple the components and store messages temporarily allows the system to scale efficiently, handling varying workloads without overwhelming downstream services.</p>
<p>  <strong>Advantages of event driven architectures</strong></p>
<ul>
<li><p>Each component can scale independently,</p>
</li>
<li><p>Automatically retries processing a failed event,</p>
</li>
<li><p>Cost effective than synchronous architecture.</p>
</li>
</ul>
</li>
</ul>
<hr />
<h3 id="heading-queue-amp-pub-sub-model">Queue &amp; Pub-Sub Model</h3>
<p><strong>Queue Model</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715657790108/f5891077-e03d-4037-8586-4189fcdca952.png" alt class="image--right mx-auto mr-0" /></p>
<p>A queue model mimics a waiting line, helping us understand how things are processed in a system. Producers, like people joining a line, add items to a queue. Consumers, the servers at the front, then take items and process them at their own pace. The queue acts as a buffer, holding items until a consumer is free.</p>
<p>This model considers factors like who gets served next (first-come-first-served?) and how many can wait in line. By analyzing these elements, we can predict waiting times, queue lengths, and overall system efficiency, allowing for smoother handling of incoming requests or tasks.</p>
<p>Example include: Amazon SQS</p>
<p><strong>Pub-Sub Model</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715658905302/434141b2-4740-4548-bbd1-0d3be8bd2589.png" alt class="image--center mx-auto" /></p>
<p>In contrast to the queue model's orderly line, the pub-sub model functions more like a public announcement system. Here, publishers, instead of sending messages directly, broadcast them to channels or topics. Subscribers interested in those topics can listen in and receive relevant messages. This asynchronous communication keeps publishers and subscribers independent.</p>
<p>Example: Amazon SNS, Amazon EventBridge.</p>
<hr />
<h3 id="heading-messaging-amp-streaming">Messaging &amp; Streaming</h3>
<p><strong>Messaging</strong></p>
<p>A communication method where information is exchanged in <strong>individual, self-contained messages</strong>. Each message represents a complete unit of data, similar to a letter in traditional mail.</p>
<ul>
<li><p><strong>Use Cases:</strong> Perfect for situations where decoupling applications is important. The sender doesn't need to wait for the receiver to be available, and vice versa. Messaging queues are also great for ensuring messages are delivered reliably, even if there are failures. Examples include sending notifications, processing payments, or updating databases asynchronously.</p>
</li>
<li><p><strong>Benefits:</strong> Decoupling, reliability, asynchronous processing.</p>
</li>
<li><p><strong>Example:</strong> Amazon SQS.</p>
</li>
</ul>
<p><strong>Streaming</strong></p>
<p>A continuous flow of data delivered in a sequence. Unlike messaging, a <strong>single chunk (stream) doesn't provide the full context</strong>. To understand the bigger picture, you need to analyze the entire stream or a significant portion of it.</p>
<ul>
<li><p><strong>Use Cases:</strong> Ideal for scenarios where low latency and real-time processing are essential. Examples include analyzing sensor data, processing financial transactions, or building chat applications.</p>
</li>
<li><p><strong>Benefits:</strong> Real-time processing, low latency, large data volumes.</p>
</li>
<li><p><strong>Example:</strong> Kinesis Data Stream.</p>
</li>
</ul>
<hr />
<h3 id="heading-sql-and-nosql-database">SQL and NoSQL Database</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715680520487/d7d55418-aef8-4631-bf6a-e2616e34f489.png" alt class="image--center mx-auto" /></p>
<p><strong>Understanding CAP theorem</strong></p>
<ol>
<li><p>Consistency (Every read operation gets the latest data or an error)</p>
</li>
<li><p>Availability (Every request receives a response, even if it's not the most recent data)</p>
</li>
<li><p>Partition Tolerance (The <strong>system continues to function despite network partitions</strong>): This property ensures the system can handle disruptions in communication between nodes. Network partitions can occur due to hardware failures, outages, or network congestion. Partition tolerance allows the system to continue operating even during such events.</p>
</li>
</ol>
<p><strong>NOTE:</strong> There is no one-size-fits-for-all. Amazon Aurora Serverless can support horizontal scaling &amp; DDB Transaction follows ACID properties.</p>
<p><strong>SQL Database:</strong> Amazon RDS, Amazon Aurora</p>
<p><strong>NoSQL Database:</strong> DDB, Amazon DocumentDB ( with MongoDB compatibility), Amazon Managed Apache Cassandara Service.</p>
<blockquote>
<p>Do not use a cannon to kill the mosquito. (choosing the appropirate database as requiements)</p>
</blockquote>
<hr />
<h3 id="heading-websockets">WebSockets</h3>
<p>WebSockets are a powerful communication protocol that <strong>enables real-time, full-duplex communication between a client (like a web browser) and a server</strong>. Unlike traditional HTTP requests that are typically one-way (client requests, server responds), WebSockets allow for ongoing, bi-directional communication, making them ideal for applications requiring real-time updates, such as chat applications, live sports scores, collaborative editing tools, and financial trading platforms.</p>
<p><strong>How does it begin?</strong></p>
<p>The WebSocket protocol begins with a process known as the WebSocket handshake, which is based on HTTP. Here's a basic overview of how it starts:</p>
<ol>
<li><p><strong>Client Request</strong>: The process begins when a client (usually a web browser) sends a regular HTTP request to the server, indicating its desire to upgrade the connection to a WebSocket connection. This request includes a special header called <code>Upgrade</code> with the value <code>websocket</code>, along with other required headers.</p>
</li>
<li><p><strong>Server Response</strong>: Upon receiving the client's request, the server checks if it supports the WebSocket protocol. If it does, the server responds with a 101 status code (Switching Protocols), indicating that the connection is being upgraded to a WebSocket connection. The response also includes a special header called <code>Upgrade</code> with the value <code>websocket</code>, confirming the upgrade.</p>
</li>
<li><p><strong>Establishment of WebSocket Connection</strong>: Once the handshake is complete and the connection is upgraded, the WebSocket connection is established. From this point onward, both the client and server can send messages to each other in a full-duplex manner.</p>
</li>
<li><p><strong>Communication</strong>: With the WebSocket connection established, the client and server can now exchange data using the WebSocket protocol. Messages can be sent and received in real-time, enabling interactive and responsive web applications.</p>
</li>
<li><p><strong>Closing the Connection</strong>: When either the client or server decides to close the WebSocket connection, they send a special message indicating their intention to close. Upon receiving this message, the receiving party also sends a closing message, and once both sides have acknowledged the closure, the connection is closed.</p>
</li>
</ol>
<hr />
<h3 id="heading-caching">Caching</h3>
<p>Caching is the process of storing copies of files or data in a cache, which is a temporary storage area, so that they can be accessed more quickly when requested. Caching is used to improve the performance and efficiency of systems by reducing the need to access the original, often slower, data source.</p>
<ul>
<li><p>Reduces load on servers and network bandwidth usage.</p>
</li>
<li><p>Enables faster response times and better user experience.</p>
</li>
<li><p>Can be implemented at various levels including browser, server-side, and Content Delivery Networks (CDNs).</p>
</li>
</ul>
<p>A cache hit occurs when a requested piece of content is found in the cache.</p>
<p>A cache miss occurs when a requested piece of content is not found in the cache.</p>
<p><strong>How does cache get populated?</strong></p>
<p>Caches get populated through a process called caching. When data is requested, the system checks if it's in the cache. If not, it fetches the data from the original source and stores it in the cache for future requests.</p>
<p>The process of adding data to the cache is known as cache population. This can happen in several ways:</p>
<ul>
<li><p><strong>On-Demand</strong>: Data is added to the cache only when it's requested and not already present. This is known as lazy loading.</p>
<p>  <a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715732597398/46c7d195-5b4c-4585-9c7f-17bd0e6dff6b.png" alt class="image--center mx-auto" /></a></p>
</li>
<li><p><strong>Preloading</strong>: Data is added to the cache in advance, typically during system startup or during periods of low traffic, to ensure that frequently accessed data is already available in the cache.</p>
</li>
<li><p><strong>Write-Through</strong>: Data is simultaneously written to both the cache and the original data source, ensuring that the cache is always up-to-date.</p>
<p>  <a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715732617990/58733b84-af5f-4331-8bec-54c8845f13da.png" alt class="image--center mx-auto" /></a></p>
</li>
<li><p><strong>Write-Behind (Write-Back)</strong>: Data is initially written only to the cache and then periodically flushed to the original data source in the background.</p>
</li>
</ul>
<p><strong>How does cache get deleted?</strong></p>
<p>Caches can be deleted or cleared in several ways:</p>
<ol>
<li><p><strong>Manual Clearing</strong>: Users or administrators can manually clear the cache. This is often done through settings or options in the application or system.</p>
</li>
<li><p><strong>Time To Live (TTL)</strong>: Caches can be configured with TTL, where items are automatically removed from the cache after a certain period of time. This helps ensure that the cache does not contain stale data.</p>
</li>
<li><p><strong>Cache Invalidation</strong>: When data in the original data source is modified or deleted, the corresponding data in the cache needs to be updated or removed to prevent stale data. This process is known as cache invalidation.</p>
</li>
<li><p><strong>Eviction Policies</strong>: Caches can also use eviction policies to remove items from the cache when it reaches a certain size or when memory is needed for other purposes. Common eviction strategies include Least Recently Used (LRU), Most Recently Used (MRU), or First-In-First-Out (FIFO).</p>
</li>
<li><p><strong>Programmatic Clearing</strong>: Applications can programmatically clear or remove items from the cache based on certain criteria or events, such as when a user logs out or when a session expires.</p>
</li>
</ol>
<p>Caching is not restricted to database only. You can enable caching in different parts of your system.</p>
<p><strong>Which caching service to use &amp; when?</strong></p>
<p>Use managed caching of the service. For example, using caching feature of API Gateway in case of API Gateway.</p>
<p>If service doesn't provide caching then use cache database.</p>
<ul>
<li>Cache databases like Redis and Memcached are suitable when you need more than just caching and require features like persistence, data structures, or advanced caching strategies. They're also suitable for applications that require high-performance caching and can benefit from the flexibility and scalability of cache databases.</li>
</ul>
<hr />
<h3 id="heading-high-availability-amp-fault-tolerant">High Availability &amp; Fault Tolerant</h3>
<p><strong>High Availability</strong></p>
<p>High Availability (HA) refers to the ability of a system or service to <strong>remain operational and accessible for a high percentage of time</strong>, typically 99.999% (often referred to as "five nines" availability). Achieving high availability involves implementing redundant components and failover mechanisms to ensure that if one component fails, another can take over seamlessly, minimizing downtime and ensuring continuous operation.</p>
<p>To make system highly available we've to identify single point of failure</p>
<ul>
<li><p>Servers running your applications</p>
</li>
<li><p>Database</p>
</li>
<li><p>Load balancer</p>
</li>
<li><p>Analyze each component and validate single point of failure</p>
</li>
</ul>
<p><strong>Achieving High Availability on the Cloud</strong></p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715733491052/7cd45c04-d402-4fc3-99f2-fbce241487b4.png" alt class="image--center mx-auto" /></a></p>
<p>Deploying in more than one AZ makes our system more available.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715733464031/5cd3940b-5be7-49a6-bbcc-4e36b67cbef6.png" alt class="image--center mx-auto" /></a></p>
<p>This case for containers ensuring high availabilty.</p>
<p><strong>Fault Tolerant</strong></p>
<p>Fault tolerance refers to a system's ability to <strong>continue operating properly in the event of the failure</strong> of some of its components. It is a key aspect of high availability and is achieved through redundancy and error detection mechanisms.</p>
<p>It is more expensive approach than HA. For example, airplanes have redundant systems for critical functions such as engine power, navigation, and control surfaces.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715734461557/bc6e09d0-59fc-489b-992b-07cdb141fd9c.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-centralized-amp-distributed-system">Centralized &amp; Distributed System</h3>
<p><strong>Centralized System</strong></p>
<p>A centralized system is a computing architecture where most or all of the processing, storage, and management functions are performed by a single central node or entity. In such a system, all user requests, data, and resources typically flow through this central point.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715735001180/e88f9667-f0d8-4c7d-b096-0500963cb443.png" alt class="image--center mx-auto" /></a></p>
<p>Here are some key characteristics and considerations of centralized systems:</p>
<ol>
<li><p><strong>Centralized Control:</strong> One central entity has control over the entire system, making decisions and managing resources. This centralization can simplify management but can also become a bottleneck if the central node fails or is overloaded.</p>
</li>
<li><p><strong>Single Point of Failure:</strong> Centralized systems are vulnerable to single points of failure. If the central node fails, the entire system can become inaccessible or non-functional. Redundancy and fault tolerance mechanisms are essential to mitigate this risk.</p>
</li>
<li><p><strong>Scalability Challenges:</strong> Scaling a centralized system can be challenging. As the system grows, the central node may become a bottleneck, limiting the system's ability to handle increased traffic or data volume.</p>
</li>
<li><p><strong>Data Consistency:</strong> Ensuring data consistency can be more straightforward in a centralized system compared to distributed systems. However, it also means that data access and processing may be slower if everything needs to go through the central node.</p>
</li>
<li><p><strong>Resource Utilization:</strong> Centralized systems may struggle with efficient resource utilization, as resources are typically provisioned based on peak loads, leading to underutilization during off-peak times.</p>
</li>
<li><p><strong>Security Concerns:</strong> Centralized systems can be more vulnerable to security threats, as compromising the central node can potentially expose the entire system. Strong security measures are crucial to protect against such threats.</p>
</li>
<li><p><strong>Examples:</strong> Traditional client-server architectures, where a central server handles requests and manages resources, are examples of centralized systems. Many legacy systems and some modern applications still use centralized architectures.</p>
</li>
</ol>
<p><strong>Distributed System</strong></p>
<p>A distributed system is a computing architecture that consists of multiple interconnected nodes that work together to achieve a common goal. In a distributed system, tasks are divided among the nodes, and coordination is achieved through message passing or shared storage.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715735181763/93d9d90e-678c-4e21-b207-1f990bd54399.png" alt class="image--center mx-auto" /></a></p>
<p>Here are some key characteristics and considerations of distributed systems:</p>
<ol>
<li><p><strong>Decentralized Control:</strong> Unlike centralized systems, distributed systems have no single point of control. Each node in the system may make independent decisions based on local information, leading to more flexible and scalable architectures.</p>
</li>
<li><p><strong>Scalability:</strong> Distributed systems are inherently more scalable than centralized systems. Adding more nodes to the system can increase its capacity to handle larger workloads, making it easier to accommodate growth.</p>
</li>
<li><p><strong>Fault Tolerance:</strong> Distributed systems are designed to be fault-tolerant. If one node fails, the system can continue to operate using other nodes. Redundancy and replication are often used to ensure data availability and system reliability.</p>
</li>
<li><p><strong>Data Consistency:</strong> Ensuring data consistency in a distributed system can be challenging, especially in the presence of network partitions or node failures. Various consistency models, such as eventual consistency or strong consistency, can be used based on the application's requirements.</p>
</li>
<li><p><strong>Resource Utilization:</strong> Distributed systems can achieve better resource utilization by dynamically allocating resources based on demand. This can lead to more efficient use of hardware resources compared to centralized systems.</p>
</li>
<li><p><strong>Concurrency and Parallelism:</strong> Distributed systems can take advantage of parallelism and concurrency to improve performance. Tasks can be divided among nodes, and multiple tasks can be executed simultaneously, leading to faster processing times.</p>
</li>
<li><p><strong>Security Concerns:</strong> Distributed systems face unique security challenges, such as ensuring data privacy and integrity across multiple nodes. Encryption, authentication, and access control mechanisms are essential to protect against security threats.</p>
</li>
<li><p><strong>Examples:</strong> Modern web applications, cloud computing platforms, and blockchain networks are examples of distributed systems. These systems leverage the benefits of distributed architectures to provide scalable, fault-tolerant services to users.</p>
</li>
</ol>
<hr />
<h3 id="heading-hashing">Hashing</h3>
<p>Hashing is a process used in computer science to convert input data (often of arbitrary size) into a fixed-size value, typically a string of characters. The output of a hash function, known as a hash value or hash code, is unique to the input data, meaning that even a small change in the input will produce a significantly different hash value.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715736078469/7e8b397c-f392-4b80-9536-c3ceb20852fc.png" alt class="image--center mx-auto" /></a></p>
<p><strong>How is hashing applied in system design?</strong></p>
<p>Hashing is applied in system design in various ways to improve performance, security, and efficiency. Here are some common applications of hashing in system design:</p>
<ol>
<li><p><strong>Hash Tables:</strong> Hash tables are a fundamental data structure that uses hashing to map keys to their corresponding values. They are used to implement associative arrays, databases, caches, and symbol tables. Hash tables provide fast insertion, deletion, and lookup operations, making them ideal for scenarios where quick data access is essential.</p>
<p> <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/7d/Hash_table_3_1_1_0_1_0_0_SP.svg/1024px-Hash_table_3_1_1_0_1_0_0_SP.svg.png" alt="undefined" /></p>
</li>
<li><p><strong>Caching:</strong> Hashing is used in caching mechanisms to quickly retrieve cached data. Each piece of data is hashed to determine its storage location in the cache. When retrieving data, the system computes the hash of the requested data and checks the cache for a matching hash. If found, the cached data is returned, avoiding the need to perform expensive computations or database queries.</p>
</li>
<li><p><strong>Password Storage:</strong> Hashing is used to securely store passwords. Instead of storing passwords in plain text, systems hash the passwords using a cryptographic hash function before storing them. When a user attempts to log in, the system hashes the provided password and compares it to the stored hash. This ensures that even if the password database is compromised, the actual passwords remain protected (as only hash value of the password is stored).</p>
</li>
<li><p><strong>Data Integrity Checking:</strong> Hashing is used to verify the integrity of data. By hashing data before transmission or storage and comparing the hash values before and after, systems can ensure that the data has not been tampered with.</p>
</li>
<li><p><strong>Load Balancing:</strong> Hashing is used in load balancing algorithms to distribute incoming requests among multiple servers. Each request is hashed to determine which server should handle it, ensuring that the load is evenly distributed across the servers.</p>
</li>
</ol>
<p><strong>Use Case:</strong> When you create a DynamoDB table, you specify a primary key, which consists of a partition key and an optional sort key. The partition key is used to determine the partition in which the item will be stored.</p>
<p>DynamoDB uses a hashing algorithm on the partition key's value to determine the partition where the item will be stored. This ensures that items with the same partition key are stored together in the same partition, allowing for efficient retrieval of data using the partition key.</p>
<p><strong>Challenges of hashing</strong></p>
<ol>
<li><p><strong>Collision</strong>: Hash functions can produce the same hash value for different inputs, leading to a collision.</p>
</li>
<li><p><strong>Hashing Speed</strong>: Generating a hash value can be computationally intensive, especially for large datasets or complex hash functions.</p>
</li>
<li><p><strong>Hash Function Updates</strong>: Over time, vulnerabilities may be discovered in hash functions, necessitating updates or changes. <strong>Updating hash functions in a system can be complex and may require migrating data to a new hash function</strong>.</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715755385305/4e7c40a2-93c2-4913-9f76-507758df4b84.png" alt class="image--center mx-auto" /></p>
<p>Suppose, we've 4 servers s0 to s3. Now we have hash function that will do function: <code>given_value%no._of_servers.</code></p>
<p>And we see that the requests 1 and requests 2s are sent to the s2 and s0 servers respectively.</p>
<p>Now, say one server s3 went down,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715755641507/b8b9e6c3-78ff-4361-a636-d96ac476ca4a.png" alt class="image--center mx-auto" /></p>
<p>Then, that ends up re-mapping the entire thing because now, requests are going to different servers. All the existing mappings will be lost..</p>
<p>So, generally when a user comes to a particular server, some of the state informations are saved on the server. Since everything gets remapped with this kind of traditional hashing, the vacant server won't be able to easily recover the state for the same user request.</p>
<p><strong>How to solve the issue?</strong></p>
<p>We have other method called Consistent Hashing.</p>
<p><strong>Consistent Hashing</strong></p>
<p>Consistent hashing is a technique used in distributed systems to map resource requestors (like users or programs) and server nodes onto a virtual ring structure. This ring has an infinite number of points, and server nodes are placed at random locations on the ring. Requests are also placed on the ring using the same hash function.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715781522149/fe5c13ee-8bf3-49fb-889d-c5d66890cb5b.png" alt class="image--center mx-auto" /></p>
<p>Consistent hashing is used to keep the hash table independent of the number of servers available to minimize key relocation when changes of scale occur.</p>
<p>In consistent hashing, the decision about which request will be served by which server node is based on the location of the request and the server nodes on the ring. Here's how it works:</p>
<ol>
<li><p><strong>Mapping Requests:</strong> Each request (or key) is hashed to a value that corresponds to a point on the ring. This determines the location of the request on the ring.</p>
</li>
<li><p><strong>Locating Server Nodes:</strong> Server nodes are also hashed to points on the ring using the same hash function. Each server node covers a range of points on the ring, from its own point up to (but not including) the point of the next server node in clockwise order.</p>
</li>
<li><p><strong>Routing Requests:</strong> When a request is made, it is hashed to a point on the ring. The request is then routed to the server node whose range includes this point. This is done by moving clockwise around the ring until the first server node is encountered whose point is greater than or equal to the point of the request. If no such server node is found (i.e., the request's point is higher than the highest addressed node), the request is served by the server node with the lowest address, as the traversal through the ring goes in a circle.</p>
</li>
</ol>
<p>This method ensures that each request is consistently mapped to the same server node, even as nodes are added or removed from the system, minimizing the need for reorganization of data and ensuring efficient load balancing across the nodes.</p>
<p><strong>What happens when a server node fails?</strong></p>
<p>When a server node fails, only the range of keys that were assigned to that node need to be remapped. This remapping affects only a portion of the keys, relative to the total number of keys in the system, which is a significant advantage compared to traditional hashing techniques where a change in the hash table size can lead to remapping a large portion, if not all, of the keys.</p>
<p>This ability to minimize the impact of node failures or changes in the system topology is one of the key benefits of consistent hashing in distributed systems. It allows the system to maintain stability and efficient key-to-node mappings even as nodes are added, removed, or fail.</p>
<p>Consistent hashing is used by load balancers, distributed databases, caches, and distributed storage systems to evenly distribute traffic and data across nodes, ensuring efficient resource utilization and minimal disruption when nodes are added or removed.</p>
<hr />
<h3 id="heading-database-sharding">Database Sharding</h3>
<p>Database sharding is a technique used to partition a large database into smaller, more manageable pieces called shards. Each shard holds a subset of the data, and together, they make up the entire dataset. Sharding is often used to improve performance and scalability for databases that need to handle high volumes of transactions or queries.</p>
<p><a target="_blank" href="https://cloudwithraj.com/"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715913867240/e5e4a27c-e51b-479c-855a-68b494046267.png" alt class="image--center mx-auto" /></a></p>
<p><strong>Key Concepts in Database Sharding</strong></p>
<ol>
<li><p><strong>Horizontal Partitioning</strong>: Sharding is a form of horizontal partitioning where each shard contains rows of the database table, as opposed to vertical partitioning where each shard contains columns.</p>
</li>
<li><p><strong>Shard Key</strong>: This is a key that determines how the data is distributed across shards. It is usually chosen based on the most commonly queried fields to ensure even distribution and efficient querying.</p>
</li>
<li><p><strong>Shard Infrastructure</strong>: Each shard is typically hosted on a separate database server, allowing for load balancing and parallel processing.</p>
</li>
</ol>
<p><strong>Benefits of Sharding</strong></p>
<ol>
<li><p><strong>Scalability</strong>: By distributing data across multiple servers, sharding allows for horizontal scaling. When the load increases, new shards can be added to handle the extra data and queries.</p>
</li>
<li><p><strong>Performance</strong>: Shards reduce the amount of data each server needs to process, which can lead to faster query response times and improved overall performance.</p>
</li>
<li><p><strong>Availability</strong>: With data distributed across multiple servers, the failure of a single shard does not mean the entire database is down. This enhances the database's availability and fault tolerance.</p>
</li>
</ol>
<p><strong>Challenges of Sharding</strong></p>
<ol>
<li><p><strong>Complexity</strong>: Implementing sharding adds complexity to the database architecture. It requires careful planning and management of the shard key, data distribution, and ensuring data consistency across shards.</p>
</li>
<li><p><strong>Data Distribution</strong>: Uneven distribution of data can lead to hotspots, where some shards become overloaded while others are underutilized.</p>
</li>
<li><p><strong>Joins and Transactions</strong>: Performing joins and transactions across multiple shards can be complex and less efficient. Applications need to be designed to handle distributed queries and transactions.</p>
</li>
</ol>
<hr />
<h3 id="heading-disaster-recovery">Disaster Recovery</h3>
<p>Disaster recovery (DR) is a set of policies, tools, and procedures that enable the recovery or continuation of vital technology infrastructure and systems following a natural or human-induced disaster. It focuses on ensuring that an organization can quickly resume mission-critical functions after a disaster.</p>
<p><strong>Key Concepts in Disaster Recovery</strong></p>
<ol>
<li><p><strong>Recovery Point Objective (RPO)</strong>: The maximum acceptable amount of data loss measured in time. Simply, it means how often do you want your data to be backed up? The lesser the RPO, the expensive the approach for example, say, we decide to backup every 10 minutes. Here, we accepting the data loss of 9 minutes. Real time RPO? We have real time replication.</p>
</li>
<li><p><strong>Recovery Time Objective (RTO)</strong>: The maximum acceptable amount of time to restore a function or system after a disaster. It represents how long it can take to get back to normal operations.</p>
</li>
<li><p><strong>Disaster Recovery Plan (DRP)</strong>: A documented process or set of procedures to recover and protect a business IT infrastructure in the event of a disaster. The plan includes detailed instructions on how to respond to unplanned incidents.</p>
</li>
</ol>
<p>So, depending upon the RPO &amp; RTO, we have different strategies to follow:</p>
<p><img src="https://docs.aws.amazon.com/images/whitepapers/latest/disaster-recovery-workloads-on-aws/images/disaster-recovery-strategies.png" alt="Graph showing disaster recovery strategies and highlights of each strategy." /></p>
<ol>
<li><p>Backup &amp; Restore: Restoring the system after the disaster.</p>
<p> <img src="https://docs.aws.amazon.com/images/whitepapers/latest/disaster-recovery-workloads-on-aws/images/backup-restore-architecture.png" alt="Architecture diagram showing backup and restore architecture" /></p>
</li>
<li><p>Pilot Light: Minimal version of system is always running in the background.</p>
<p> <img src="https://docs.aws.amazon.com/images/whitepapers/latest/disaster-recovery-workloads-on-aws/images/pilot-light-architecture.png" alt="Reference architecture diagram for pilot light architecture" /></p>
</li>
<li><p>Warm-standby: Ready to takeover (Duplicate of a system is running but not actively serving user requets)</p>
<p> <img src="https://docs.aws.amazon.com/images/whitepapers/latest/disaster-recovery-workloads-on-aws/images/warm-standby-architecture.png" alt="Architecture diagram showing warm standby architecture." /></p>
</li>
<li><p>Mulit-site active/active: Fully functional environments in multiple AWS regions simultaneously.</p>
<p> <img src="https://docs.aws.amazon.com/images/whitepapers/latest/disaster-recovery-workloads-on-aws/images/multi-site-active-active-architecture.png" alt="Architecture diagram showing multi-site active/active architecture (change one Active path to Inactive for hot standby)" /></p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[Key Security Steps After Creating Your AWS Account]]></title><description><![CDATA[Hey there,
You've just created your AWS account—exciting!
Before you get started, let's make sure you do a few things to keep your account safe and secure.
Let's dive in.

Task 1: Assign MFA to your root account.
After creating your AWS account, you ...]]></description><link>https://sujanmagar.com.np/key-security-steps-after-creating-your-aws-account</link><guid isPermaLink="true">https://sujanmagar.com.np/key-security-steps-after-creating-your-aws-account</guid><category><![CDATA[AWS]]></category><category><![CDATA[securityawareness]]></category><dc:creator><![CDATA[SUJAN]]></dc:creator><pubDate>Sun, 12 May 2024 01:53:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1715478782311/f0e68530-3e74-4278-ba91-a00cbc7835d8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey there,</p>
<p>You've just created your AWS account—exciting!</p>
<p>Before you get started, let's make sure you do a few things to keep your account safe and secure.</p>
<p>Let's dive in.</p>
<hr />
<h3 id="heading-task-1-assign-mfa-to-your-root-account">Task 1: Assign MFA to your root account.</h3>
<p>After creating your AWS account, you become the root user, which means you have all the privileges. It's crucial to secure your account properly.</p>
<p>On your account, on right top corner,</p>
<p>Click on and then Select <code>Security Credentials</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715426090675/b2f4754d-54f9-408f-9df0-988e4862a61c.png" alt /></p>
<p>You'll see like the following interface.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715425916391/597ffb64-14ce-4d65-b6a7-dc4fd2abe05e.png" alt class="image--center mx-auto" /></p>
<p>Click on Assign MFA.</p>
<p>Name your MFA device.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715425954069/c19d520c-2a62-44e9-8051-33824f33aaef.png" alt /></p>
<p>I'm using Authenticator app for MFA purpose.</p>
<p>It authenticates using a code generated by an app on your mobile device. This code is unique and valid only for a short time, adding an extra layer of security to your accounts.</p>
<p>There are multiple authenticator apps. I've installed Google's <code>Google Authenticator</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715426507259/01f4b1d6-024d-48d5-b319-1409a27e1ffe.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715425990749/e505c575-5d86-40ce-ac2e-ee1b093f9fcd.png" alt /></p>
<p>Scan the QR code from your authenticator app.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715426006894/76bfc1bf-89a0-428a-be41-900ada850140.png" alt /></p>
<p>Fill the two consecutive codes from your Authenticator device.</p>
<p>So, our first task is completed.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715426731779/60b76eaf-b255-453a-b3c1-fe93070fc0f7.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-task-2-create-budget-alert">Task 2: Create Budget Alert</h3>
<p>Click on <code>Billing &amp; Cost Management</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715426848369/c045b5fb-75cb-4835-8aa8-89086c4f836d.png" alt /></p>
<p>Scroll a bit and click on <code>Billing Preferences</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715426933084/cb40f6c2-4c49-4c83-9cc8-63043d0af421.png" alt /></p>
<p>Now Click on the check boxes as below and provide your email address to receive Free Tier usage alerts.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715427035044/185e9185-a05c-4fef-ab99-6a27dd8f3028.png" alt class="image--center mx-auto" /></p>
<p>Now, we've setup our Billing preferences.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715427045656/184fda72-657b-47e3-82e5-f3075813a0e8.png" alt class="image--center mx-auto" /></p>
<p>On Billing &amp; Cost Management section, click on <code>Budgets</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715427247781/2fbeea99-8a12-49a6-9de8-65f0490f1e39.png" alt /></p>
<p>Create a budget.</p>
<p>Choose Customize option on Budget setup.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715427486206/4b0a4e73-a441-47e6-83dc-6cf9611434c3.png" alt class="image--center mx-auto" /></p>
<p>Scroll a bit and Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715427733077/c324c2ef-81f6-49f9-aa90-f1e4cac69956.png" alt class="image--center mx-auto" /></p>
<p>Provide name for your budget and also enter your budgeted amount.</p>
<p>Scroll down and Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715427809799/a552e36a-154e-4ff7-87d3-12e523258140.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Add an alert threshold</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715427903340/d9cde314-f7e2-4a4d-9844-e9a89e076dba.png" alt class="image--center mx-auto" /></p>
<p>In my case, I've applied 50%. Provide your desired Email recipients.</p>
<p>When your actual cost is greater than <strong>50.00% ($5.00)</strong> of your <strong>budgeted amount ($10.00)</strong>, the alert threshold will be exceeded.</p>
<p>Click on <code>Next</code>.</p>
<p>Review all of your information and click on Create Budget.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715428282003/372dcbc9-3e60-4fcf-ab57-d9fa5c424b9e.png" alt class="image--center mx-auto" /></p>
<p>That completes our second task.</p>
<hr />
<h3 id="heading-task-3-create-an-iam-user">Task 3: Create an IAM user.</h3>
<p><strong>Why we need IAM user?</strong></p>
<p>Daily tasks with the root user in AWS are risky, like giving everyone a house key. IAM users are better - create specific users with limited access, like assigning keys only to certain rooms. This keeps your AWS environment more secure!</p>
<p>Alright, On the services, search for IAM and click on it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715428604736/8c94b365-546c-4b7f-9d79-ae9e0521e2bd.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715428648795/963f8daf-b4f2-45b7-b58e-58e3141e7f27.png" alt class="image--center mx-auto" /></p>
<p>Click on Users and then <code>Create user</code> and provide a suitable username with password.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715474258773/bff15e16-e2cd-42d9-b1aa-a477a17c2f6d.png" alt class="image--center mx-auto" /></p>
<p>Click on <code>Next</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715474415433/6f5957b8-9145-492a-89f2-1c644231ec04.png" alt class="image--center mx-auto" /></p>
<p>Search for Administrator Access, tick the box and Click on <code>Next</code>.</p>
<p>Review what you've done and proceed to <code>Create user</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715474547082/c8943561-b4a4-4fc9-9c77-9be2d6e2f5e6.png" alt class="image--center mx-auto" /></p>
<p>Return to dashboard.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715474632229/2ae236a4-bf3d-4bd2-b033-0af2d508a6f8.png" alt /></p>
<p>Click on <code>Create</code> below Account Alias.</p>
<p>An AWS account alias is a custom name for your account ID, making it easier to remember and use when accessing AWS services.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715474676216/04b09558-a9c5-4b61-b52a-b28bf8754e17.png" alt /></p>
<p>Provide your preferred name.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715474759617/a33bea6c-8db9-49ea-8f0a-4505c10702c2.png" alt /></p>
<p>Copy the given <code>Sign-in URL</code> and paste it into your browser and bookmark it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715474805555/b37950ea-6f83-431d-8c3b-c5a59a7789e4.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715474945276/a071cc6d-961c-49fa-b208-4b99976006e0.png" alt class="image--center mx-auto" /></p>
<p>Provide your IAM username and enter password to <code>Sign in</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715475019083/a0339058-1e1b-4f7b-9465-58cb2135a773.png" alt /></p>
<p>We've signed in as an IAM user.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715475086448/80a233f4-4736-42cc-b9a9-d52a786eaad8.png" alt /></p>
<p>Click on <code>Security credentials</code>, for this new identity we've to setup MFA just like we did earlier for our root account.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715475151209/73ac4fc2-69e7-49dc-9d95-c456a12bc23f.png" alt class="image--center mx-auto" /></p>
<p>Assign MFA and do as we did earlier.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715475273370/8a9cc56b-37a9-4d2f-a48a-0163d2caa2d1.png" alt class="image--center mx-auto" /></p>
<p>I hope you've done yours as well.</p>
<p>Alright. We've finished the account setup and securing process.</p>
<p>This concludes the blog.</p>
<hr />
<p>In a nutshell, we accomplished the following:</p>
<ol>
<li><p>Assigned MFA to root account,</p>
</li>
<li><p>Created a Budget Alert,</p>
</li>
<li><p>Created IAM user and assigned MFA.</p>
</li>
</ol>
<p>Hope you guys had a wonderful time.</p>
<p>See you again in the next one.</p>
]]></content:encoded></item></channel></rss>