<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hasan Cheema on Medium]]></title>
        <description><![CDATA[Stories by Hasan Cheema on Medium]]></description>
        <link>https://medium.com/@hasan.cheema23?source=rss-5618d3eb17c1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*E89b9PdXjVBS5VPhekM4eQ@2x.jpeg</url>
            <title>Stories by Hasan Cheema on Medium</title>
            <link>https://medium.com/@hasan.cheema23?source=rss-5618d3eb17c1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 19:05:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hasan.cheema23/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Build and Host a Website on GCP]]></title>
            <link>https://medium.com/@hasan.cheema23/build-and-host-a-website-on-gcp-abd8ad0918e0?source=rss-5618d3eb17c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/abd8ad0918e0</guid>
            <category><![CDATA[web-hosting]]></category>
            <category><![CDATA[gcp]]></category>
            <dc:creator><![CDATA[Hasan Cheema]]></dc:creator>
            <pubDate>Sun, 08 Sep 2024 02:39:22 GMT</pubDate>
            <atom:updated>2024-09-08T02:39:22.825Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z9krWFVCrW4OQB3DywXJPA.jpeg" /></figure><h4><strong>Overview:</strong></h4><p>Google Cloud Platform (GCP), a suite of cloud computing services offered by Google, has experienced a surge in demand, particularly for the same infrastructure that powers Google’s popular products like Google Search, Gmail, file storage, and YouTube.</p><p>Cloud computing is a shared pool of adaptable resources, including networks, servers, storage, applications, and services, that customers can utilize to build and deploy their products and services.</p><p>In this article, I will explore how to host and build your web application or website on the Google Cloud Platform. Choosing GCP to host your website offers numerous advantages such as cost-effective services, high speed, reliability, and the ability to scale cloud storage as needed.</p><h4>What is Google Website Hosting?</h4><p>Google Cloud Platform offers a range of web hosting solutions, including Compute Engine, a powerful and flexible virtual server option often used by developers and businesses. Compute Engine is particularly well-suited for website hosting, providing the infrastructure and tools to build and manage websites efficiently.</p><h4>Objectives:</h4><blockquote>1. Create a VM to host your website<br>2. Install Apache Server to host the virtual machine<br>3. Build a first web page for your website on GCP<br>4. Configure Cloud DNS for your Website Domain name<br>5. Update the Nameservers in your Domain Provider Panel</blockquote><h4>Preconditions:</h4><blockquote>1. GCP Free Tier Account<br>2. Access to IAM and Admin</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5zf2M4HgjjWszLd4a5%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fjohnwick-john-wick-3-parabellum-5zf2M4HgjjWszLd4a5&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNm1wYXhudWY0aThoYW03M3c2dTY0ZThqNWx5dHYwM212bGd3ZXF0aSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F5zf2M4HgjjWszLd4a5%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="183" frameborder="0" scrolling="no"><a href="https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href">https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href</a></iframe><h4>Step 1: Create a Project</h4><p>Before we start, let’s create a new project. This way, you can easily delete the project and all its associated resources later if you don’t need to keep them. In the Google Cloud console, on the project selector page, select or create a new Google Cloud project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OaTDUhRrGPsq0YkVxJdOHw.jpeg" /></figure><h4>Step 2: Create a Virtual Machine (VM) to host your website</h4><p>Google Cloud makes hosting a secure and reliable website simple, allowing you to accomplish more while saving money. While invisible to the naked eye, virtual machines function similarly to physical computers and can be accessed over the internet via the cloud.</p><p>Follow the below steps to create a VM for your website.</p><blockquote>1. Go to <a href="https://console.cloud.google.com/">Google Cloud Platform Console</a><br>2. In the navigation menu click on <strong>Compute Engine</strong> <br>3. Click on <strong>VM Instance</strong> <br>4. Now, click on <strong>Create </strong>to create a new instance</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CR-4qp2-9Usp2de2I6drgQ.jpeg" /><figcaption>How to create an Instance</figcaption></figure><blockquote>1<strong>. </strong>Enter the name of an instance under the ‘Name’ heading<br>2. Select <strong>Region </strong>and <strong>Zone </strong>nearest to you<br>3. Select <strong>Machine Configuration</strong> as per your traffic and requirements. See the below image for better understanding.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OHrPXMrZPNZ2laENFNCuxw.jpeg" /><figcaption>Configure your Instance</figcaption></figure><blockquote>1. Under the <strong>Boot Disk</strong> option, select the boot disk you want to use. In this case, we will use <strong>Ubuntu</strong>. If you need to change the boot disk, click on <strong>Change</strong><br>2. To choose your boot disk, please click on “Select” <br>3. In the Firewall section, ensure both “Allow HTTP traffic” and “Allow HTTPS traffic” are checked <br>4. Click on <strong>Create </strong>to create the instance</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LjWyp7T_UPJyxLCKT8nHfg.png" /><figcaption>Configure your Instance/Create it</figcaption></figure><h4>Step 3: Install Apache Server to host the virtual machine</h4><p>Deploying an Apache web server on your GCP VM is straightforward. Execute a few commands, and your VM transforms into a versatile platform for hosting websites, files, and more.</p><blockquote>1. In the Navigation Menu, Click on <strong>Compute Engine&gt;&gt;VM Instances<br></strong>2. Click on the VM instances you’ve created <br>3. Click on <strong>SSH </strong>to connect to your VM<br>4. Wait for the instance to connect</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rupxlmWaR5FHA5iLfhaxDQ.png" /><figcaption>SSH into your Instance</figcaption></figure><blockquote>Run the below commands to install the Apache server on your machine</blockquote><pre>sudo su <br>apt-get install apache2 <br>(enter Y if prompted) <br>service apache2 status</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*Zw6Ds413lOMwuSR56tZ--Q.png" /><figcaption>Apache server installed and active</figcaption></figure><blockquote>2. You can check whether your server is running by going to the <strong>External IP</strong> address of the <strong>web-hosting-instance </strong>VM<br>3. You will see the below page if your server is running</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2dznzNhIhtIuQL99cB0RLA.jpeg" /></figure><h4>Step 4: Build a first web page for your website on GCP</h4><p>Kickstart your website development on the Google Cloud Platform (GCP). Harness its robust infrastructure to host your inaugural web page, ensuring a smooth user experience and global accessibility. GCP’s user-friendly tools empower you to effortlessly deploy your content and lay the groundwork for future growth as your online presence expands.</p><p>After installing the Apache server on your host machine. Let’s go ahead and modify the index.html web page stored in the <strong>/var/www/html</strong> folder.</p><p>Follow the below steps to create your first default home web page.</p><blockquote>1. Enter the commands into SSH of your <strong>web-hosting-instance</strong> VM<br>2. <strong>$ ls /var/www/html (</strong>You will see index.html file)<br>3. <strong>$ rm /var/www/html/index.html </strong>(To delete the default home web page)<br>4. <strong>$ vi /var/www/html/index.html </strong>(To create a new default home web page)<br>5. Enter i on the keyboard to edit the document in vi editor<br>6. Create your web page by using HTML<br>7. See below commands and image for reference.</blockquote><pre>Commands: <br>$ ls /var/www/html<br>$ rm /var/www/html/index.html <br>$ vi /var/www/html/index.html<br><br>------------------------------------------------------------------------------<br>Code:<br><br>&lt;html&gt;<br>&lt;head&gt;&lt;/head<br>&lt;body&gt;<br>&lt;h1&gt;Welcome to My Web Page&lt;/h1&gt;<br>&lt;marquee&gt;This is a simple website&lt;/marquee&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xYFhnNlB7x6eqiHn57Vngg.jpeg" /></figure><blockquote>1. Press <strong>Esc</strong>,<strong> Shift+Colon</strong> then type <strong>wq </strong>to save the file<br>2. Now, Enter command <strong>service apache2 restart</strong> to restart the server<br>3. Again, Go to the <strong>External IP</strong> address of the mywebsite VM. Congo, You will see the below page.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WAqQhcI8VgM8doZV0vvo4g.png" /></figure><h4>Step 5: Configure Cloud DNS for your Website Domain name</h4><p>Configuring Cloud DNS for your website domain is essential for making it accessible online. It involves pointing your domain name to the IP address where your website is hosted, ensuring visitors can find your site. Cloud DNS offers benefits like high availability, scalability, and easy management, making it a popular choice.</p><p>Follow these steps to Configure Cloud DNS for your Website Domain name</p><blockquote>1. Go back to Navigation Menu search for Network Services <br>2. Click on <strong>Network Services<br></strong>3. Click on<strong> Cloud DNS</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oF9CfOC6PiCthvO-Z__q8Q.png" /></figure><blockquote>1. Click on <strong>Create Zone</strong><br>2. Enter the Zone name under ‘<strong>Zone name</strong>’ field <br>3. Under <strong>DNS name</strong>, enter your website domain name that you want to host and build<br>4. Provide description if applicable (Optional)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7UZI-CdiXrhlD02D8308Jw.png" /></figure><blockquote>1. Click on <strong>Create</strong> button<br>2. Now, click on the <strong>Add Record Set</strong> button<br>3. Select Record Reference Type as A and under IPV4 enter the enternal address of the <strong>web-hosting-instance </strong>VM instance</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9fe3LH8VL2dG9LQcSEwsEA.jpeg" /></figure><blockquote>1. Once again click on the <strong>Add Record Set</strong> button <br>2. Select Record Reference Type as <strong>CNAME<br>3. </strong>Enter <strong>www </strong>into <strong>DNS Name</strong> and [your domain website name] into <strong>Canonical name<br>4. </strong>Click on<strong> Create</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IqXVgpKJm6a6rDbOn0jiDw.png" /></figure><p>Now that we have configured our Cloud DNS for the website domain name let’s go ahead and register it. On the top right side, you will see <strong>Registrar Setup </strong>click on it. But make sure to note down the nameservers on the notepad for future use. You will use these nameservers to point your domain to Google Cloud for hosting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZCQ7vhLJzwHV51GwQBQ5pQ.jpeg" /></figure><h4>Step 6: Update the Nameservers in your Domain Provider Panel</h4><p>To make your new website live, update your domain’s nameservers. These tell your domain where your website files are hosted. Get the new nameservers from your hosting provider, log into your domain registrar’s account, and replace the old nameservers with the new ones. Changes can take time to update, so be patient.</p><p>Login to any domain provider website like domain.com, Wix, etc. Then navigate to the <strong>DNS Management</strong> page of your domain. Update your nameservers into the fields that you have noted down before. Your website is now live on the Google Cloud Platform! The domain name may take 24–48 hours to update fully. In the meantime, you can set up your database and any other services your site needs.</p><p>Thank you for reading my post! Be sure to clean up your environment after.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abd8ad0918e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to deploy Jenkins on AWS EC2 Instance with Terraform]]></title>
            <link>https://medium.com/@hasan.cheema23/how-to-deploy-jenkins-on-aws-ec2-instance-with-terraform-becf14966a7a?source=rss-5618d3eb17c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/becf14966a7a</guid>
            <dc:creator><![CDATA[Hasan Cheema]]></dc:creator>
            <pubDate>Mon, 10 Apr 2023 00:45:06 GMT</pubDate>
            <atom:updated>2023-04-10T00:45:06.474Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*o7xyLZPuL0WNtc__4uBJhw.jpeg" /></figure><h4>Overview:</h4><p>In this article, I will be using Jenkins as a CI/CD tool to create pipelines for this project. I am going to create a Jenkins server using Terraform so that it can be used in other environments and changes to the environment can be tracked better.</p><h4>What is a CI/CD pipeline?</h4><p>A CI/CD pipeline <strong>automates your software delivery process</strong>. The pipeline builds code, runs tests (CI), and safely deploys a new version of the application (CD). Automated pipelines remove manual errors, provide standardized feedback loops to developers, and enable fast product iterations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DSYya-iZSJGhIXNdiXQdNw.png" /></figure><h4>What is Terraform?</h4><p>Terraform is an infrastructure as code tool (IaC) used primarily by DevOps teams to automate various infrastructure tasks. The provisioning of cloud resources, for instance, is one of the main use cases of Terraform. It’s a cloud-agnostic, open-source provisioning tool written in the Go language and created by HashiCorp.</p><h4>How does Terraform work?</h4><p>Terraform creates and manages resources on cloud platforms and other services through its application programming interfaces (APIs). Providers enable Terraform to work with virtually any platform or service with an accessible API.</p><p>The core Terraform workflow consists of three stages:</p><ul><li><strong>Write:</strong> You define resources, which may be across multiple cloud providers and services. For example, you might create a configuration to deploy an application on virtual machines in a Virtual Private Cloud (VPC) network with security groups and a load balancer.</li><li><strong>Plan:</strong> Terraform creates an execution plan describing the infrastructure it will create, update, or destroy based on the existing infrastructure and your configuration.</li><li><strong>Apply:</strong> On approval, Terraform performs the proposed operations in the correct order, respecting any resource dependencies. For example, if you update the properties of a VPC and change the number of virtual machines in that VPC, Terraform will recreate the VPC before scaling the virtual machines.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JYY6w6-JjRYcWipsHkyv2g.png" /></figure><h4>What is Jenkins?</h4><p>Jenkins is an open-source automation tool for Continuous Integration (CI) and Continuous Deployment (CD). It is a server-based system that runs in servlet containers like Apache Tomcat. Jenkins is one of the most used DevOps tools used, along with other cloud-native tools, and allows developers to build, test and deploy software seamlessly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fRjh8x8Pzi-v6SSoT9nYJA.png" /></figure><h4>Objectives:</h4><blockquote>1. Deploy 1 EC2 Instance in your Default VPC.<br>2. Bootstrap the EC2 instance with a script that will install and start Jenkins. Review the official Jenkins Documentation for more information: <a href="https://www.jenkins.io/doc/book/installing/linux/">Linux</a><br>3. Create and assign a Security Group to the Jenkins Security Group that allows traffic on port 22 from your IP and allows traffic from port 8080.<br>4. Create an S3 bucket for your Jenkins Artifacts that is not open to the public.</blockquote><h4>Preconditions:</h4><blockquote>1. AWS Free Tier Account with IAM access<br>2. Terraform CLI Installed<br>3. Basic knowledge of Terrafrom</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5zf2M4HgjjWszLd4a5%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F5zf2M4HgjjWszLd4a5%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExODhsMmNqYnZpYnNocjd3MTFkd2k2Mm96dzEwbTg2OGdwcGplMzQ1bSZlcD12MV9naWZzX2dpZklkJmN0PWc%2F5zf2M4HgjjWszLd4a5%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="181" frameborder="0" scrolling="no"><a href="https://medium.com/media/ceb4fd2380af661521a6e88c61bea3a3/href">https://medium.com/media/ceb4fd2380af661521a6e88c61bea3a3/href</a></iframe><h4>Step 1: Create a directory</h4><p>Use the following command to create a <strong><em>directory </em></strong>and cd into it.</p><pre>mkdir &lt;directory_name&gt;<br>cd &lt;directory_name&gt;</pre><h4>Step 2: Create the Files</h4><p>Our task is to generate Terraform files, including <strong><em>providers.tf, main.tf, and variables.tf,</em></strong> inside the new directory, and add some code to each of the newly created files. It’s important to note that Terraform files must have a <strong><em>.tf </em></strong>extension to indicate that they are Terraform files.</p><p>Use the following command to create the files.</p><pre>touch &lt;file name&gt;<br>touch provider.tf <br>touch variable.tf <br>touch main.tf </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jQ6WsMpIC7yXJH8BlUPfog.png" /></figure><h4>Step 3: Create the Provider.tf file</h4><p>The purpose of this file is to set the provider for Terraform to utilize in order to manage the resources in your infrastructure. In this instance, AWS is the chosen infrastructure, and therefore the AWS provider will be employed.</p><p>Use the following code for the provider file and make sure to save the file.</p><pre>#provider configuration’s <br>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;4.62.0&quot;<br>    }<br>  }<br><br>}<br><br>provider &quot;aws&quot; {<br>  region = &quot;us-west-1&quot;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XpnIPpZ12Ee0QbRCfqddxA.png" /></figure><h4>Step 4: Create the Variable.tf file</h4><p>Terraform allows you to set your variables in a dedicated file called <strong><em>variables.tf</em></strong>. This file includes a list of all the variables needed for your Terraform code, their corresponding data types, and default values.</p><p>Use the following code for the Variable file and make sure to save the file.</p><pre><br>variable &quot;region&quot; {<br>  type        = string<br>  description = &quot;Region to Deploy VPC&quot;<br>  default     = &quot;us-west-1&quot;<br>}<br><br>variable &quot;ami&quot; {<br>  description = &quot;AMI ID&quot;<br>  type        = string<br>  default     = &quot;ami-09e4e0c0e0b76a87a&quot;<br>}<br><br>variable &quot;instance&quot; {<br>  description = &quot;EC2 Instance Type&quot;<br>  type        = string<br>  default     = &quot;t2.micro&quot;<br>}<br><br>variable &quot;vpc_id&quot; {<br>  description = &quot;VPC ID&quot;<br>  type        = string<br>  default     = &quot;vpc-0b34f393cc8e2c060&quot;<br>}<br><br>resource &quot;aws_s3_bucket&quot; &quot;jenkinsartifactsbucket&quot; {<br>  bucket = &quot;jenkinsartifactsbucket&quot;<br><br>  tags = {<br>    Name = &quot;jenkins s3 bucket&quot;<br>  }<br>}<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tQLdOi4pJUn2vDsu-f0OGw.png" /></figure><h4>Step 5: Create the main.tf file</h4><p>The primary file for your infrastructure as a code project in Terraform is the <strong><em>main.tf</em></strong> file. It serves as the foundation and includes all the resources you intend to establish, oversee, and set up.</p><p>Use the following code for the Main file and make sure to save the file.</p><pre><br>resource &quot;aws_instance&quot; &quot;jenkins_server&quot; {<br>  ami           = var.ami<br>  instance_type = var.instance<br><br>  tags = {<br>    Name = &quot;Week20-project&quot;<br>  }<br><br>  user_data = &lt;&lt;EOF<br>    #!/bin/bash<br>    yum update –y<br>    wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo<br>    rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key<br>    yum upgrade -y<br>    amazon-linux-extras install java-openjdk11 -y<br>    yum install jenkins -y<br>    systemctl enable jenkins<br>    systemctl start jenkins<br>    EOF<br>}<br><br>resource &quot;aws_security_group&quot; &quot;jenkins_sg&quot; {<br>  name        = &quot;jenkins_sg&quot;<br>  description = &quot;Allow SSH and HTTP traffic&quot;<br>  vpc_id      = var.vpc_id<br><br>  ingress {<br>    from_port   = 22<br>    to_port     = 22<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    from_port   = 443<br>    to_port     = 443<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    from_port   = 8080<br>    to_port     = 8080<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  tags = {<br>    Name = &quot;jenkins-sg&quot;<br>  }<br>}<br><br>resource &quot;aws_s3_bucket&quot; &quot;jenkins_artifacts04092023&quot; {<br>bucket = &quot;jenkins-artifacts04092023&quot;<br>}<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qptsYGP8J86_DlYeC_zuBQ.png" /></figure><h4>Step 6: Execute the files</h4><p>After creating our files, the next step is to execute them in order to accomplish our goals. To begin, we must establish a working directory by running the following command:</p><pre>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N-zaet036IqItLPTYMNM7w.png" /></figure><h4>Step 7: Validate the Files</h4><p>Now we need to validate the terraform configuration files to ensure they are syntactically valid and internally consistent. Run the following command to validate the files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dt8FTQpe2dBcfsb_AwQamQ.png" /></figure><h4>Step 8: Plan the Files</h4><p>Now we will create an execution plan. Terraform performs a refresh and determines what actions are necessary to achieve the desired state specified in configuration files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TMkY2gLdkXXcQq0Vc29cZQ.png" /></figure><h4>Step 9: Apply the Files</h4><p>We can now go ahead and apply the changes required to reach the desired state of the configuration by default apply scans the current directory for confirmation and applies the changes appropriately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*COFPLpjVlrepsihRRhXM5w.png" /></figure><h4>Step 10: Verify if our deployments were created</h4><p>After completing the task with Terraform, we can proceed to verify everything by accessing the AWS console.</p><p>If you head over to the EC2 Instance dashboard, you should see the Instance we just created running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CkNZ8rwM3Bopc1P4G0wawQ.png" /></figure><p>If you head over to the S3 Bucket dashboard you should see our newly created private bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IKHmbiTfYcXDSKRGAhMXpg.png" /></figure><p>If you head over to the security groups in the EC2 dashboard, you can see our newly created security group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EqT_FU-g0EWWM-Ika0aliA.png" /></figure><h4>Step 11: Destroy our Deployment</h4><p>Run the following command to delete everything that we created in the main file.</p><pre>terraform destory </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ldZr4mVpOdJp-8Z0tYZoCQ.png" /></figure><p>Thank you for reading my post! Be sure to clean up your environment after.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=becf14966a7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes: How to Deploy an Nginx Image Using AWS EKS]]></title>
            <link>https://medium.com/@hasan.cheema23/kubernetes-how-to-deploy-an-nginx-image-using-aws-eks-df9ca5d0356d?source=rss-5618d3eb17c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/df9ca5d0356d</guid>
            <dc:creator><![CDATA[Hasan Cheema]]></dc:creator>
            <pubDate>Sun, 09 Apr 2023 01:23:55 GMT</pubDate>
            <atom:updated>2024-06-27T03:26:58.430Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sUIpuGmJlrvtQvEhhSwUjQ.jpeg" /></figure><h4>Overview:</h4><p>AWS Elastic Kubernetes Service (EKS) is a managed service that enables you to run Kubernetes on AWS without needing to install, operate, and maintain your own Kubernetes control plane.</p><p>In this article, I will show you how to deploy a Nginx web server with Kubernetes (CLI). We will create an EKS cluster and utilize kubectl to handle the deployment and scaling of Nginx. The aim of this article is to have a fundamental understanding of how to deploy and manage containerized applications in the cloud with EKS and kubectl.</p><h4>What is Kubernetes?</h4><p>Kubernetes <strong>automates operational tasks of container management</strong> and includes built-in commands for deploying applications, rolling out changes to your applications, scaling your applications up and down to fit changing needs, monitoring your applications, and more, making it easier to manage applications.</p><h4>What is Nginx Image?</h4><p>Ngnix is open-source software and a tool that has the feature set to be many things, a web server, reverse proxying, caching, load balancing, media streaming, logging, and many more.</p><h4>Objectives:</h4><blockquote><em>1. Create a deployment that runs the nginx image.<br>2. Display the details of this deployment<br>3. Check the event logs from the deployment<br>4. Delete the deployment<br>5. Do all of the above in EKS Cluster</em></blockquote><h4>Preconditions:</h4><blockquote>1. <em>Free tier AWS Account<br>2. AWS Cloud9 Environment<br>3. Kubernetes Installed<br>4. Basic Knowledge of Linux</em></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5zf2M4HgjjWszLd4a5%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fjohnwick-john-wick-3-parabellum-5zf2M4HgjjWszLd4a5&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNm1wYXhudWY0aThoYW03M3c2dTY0ZThqNWx5dHYwM212bGd3ZXF0aSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F5zf2M4HgjjWszLd4a5%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="183" frameborder="0" scrolling="no"><a href="https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href">https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href</a></iframe><h4>Step 1: Launch an EC2 Instance</h4><p>Log in to the AWS Management Console, navigate to EC2 Dashboard, and click on <strong><em>Launch Instance</em></strong>. Next, we will do the following configurations to create our Instance.</p><blockquote>1. Give your Instance a name<br>2. Select your AMI for purpose of this project we will select (Amazon Linux)<br>3. For instance type select t2.micro <br>4. Select a key pair (I will be creating a new one for this project)<br>5. Select create security group under Network settings <br>6. Click on Launch instance</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gaEhU8G8pYRLWzLL-2Lw7w.jpeg" /></figure><p>Now that we have our instance up and running, we will configure the command line tools. To build a Kubernetes cluster, you must use CLI tools and your AWS account. From the EC2 dashboard, select the check box and select an instance as shown below. Click <strong><em>Connect</em></strong> to initialize the connection to your instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Ah3RJGgCkSGfE3TpItj-A.jpeg" /></figure><p>Normally I would SSH into the instance, but for the purpose of this project, we will be using the <strong><em>ECE Instance Connect</em></strong> and click the <strong><em>Connect</em></strong> button to connect to the instance we selected earlier. Your browser will be redirected to a new window and show a temporary SSH session with your EC2 instance, shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O3z4ZBTvSbiijNUbe9562A.png" /></figure><h4>Step 2: Install and update CLI tools</h4><p>First, we need to make sure that our AWS CLI version is up to date. Use the following command to check your AWS version.</p><pre>aws --version </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cmrz1kK4zFsyUNvgEARvxg.png" /></figure><p>Next, we will run the following commands to update our AWS CLI version.</p><pre>curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;<br>unzip awscliv2.zip<br>sudo ./aws/install --bin-dir /usr/bin --install-dir /usr/bin/aws-cli --update<br></pre><p>After running the above commands, our CLI should be updated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TLRboD0BZK38EADUHCt3NQ.png" /></figure><h4>Step 3: Configure the CLI</h4><p>Run the <strong><em>aws configure</em></strong> command to configure your instance. You will need to enter your access key and secret access key and pick a region along with the format you want. I will be choosing the us-west-1 region, but you can select a region you are closer to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jDEmUpsD_whwQLFHtkC16w.png" /></figure><h4>Step 4: Install Kubectl and eskctl</h4><p>Use the following commands to install kubectl first.</p><pre>curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.16.8/2020-04-16/bin/linux/amd64/kubectl<br>chmod +x ./kubectl<br>mkdir -p $HOME/bin &amp;&amp; cp ./kubectl $HOME/bin/kubectl &amp;&amp; export PATH=$PATH:$HOME/bin<br>kubectl version --short --client</pre><p>Next, we will use the following commands to install eskctl.</p><pre>curl --silent --location &quot;https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz&quot; | tar xz -C /tmp<br>sudo mv /tmp/eksctl /usr/local/bin<br>eksctl version</pre><p>As you can see, we have successfully updated the kubectl and eksctl.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CsKjr9Rm3t2ehoKvfAtndA.png" /></figure><h4>Step 5: Create the EKS Cluster</h4><p>Use the following command to create an EKS cluster. The command will create an EKS cluster named week19-eks running in the us-west-1 region. I wanted to create 4 worker nodes with at least 1 minimum to 4 maximum that are managed.</p><pre> eksctl create cluster --name &lt;cluster_name&gt; --region us-west-1 --nodegroup-name &lt;worker_node_name&gt; --node-type t3.medium --nodes 3 --nodes-min 1 –-nodes-max 4 --managed</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JRm8Je9G31if3jyqBA_cOg.png" /></figure><h4>Step 6: Verify if our EKS cluster is created</h4><p>Go back to the AWS console and head over to the Cloudformation dashboard click on <strong><em>Stacks,</em></strong> select your cluster and navigate your way to the <strong><em>Events</em></strong> tab to see everything being created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OCrELJl_QImaQ8pCVKAHxA.png" /></figure><h4>Step 7: Verify if the cluster is active</h4><p>From the AWS console, navigate your way to the Elastic Kubernetes Service (EKS) to see if the cluster is activated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nt2yLTzDXBgDEbLS00qIvQ.png" /></figure><p>Navigate to the EC2 Instance, and you should see 4 instances running 1 should be the control plane and three worker nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AIAiLuTnyR2DpJ4zaTxRcA.png" /></figure><h4>Step 1: Create a deployment that runs the nginx image</h4><p>Head over to the CLI console and run the following commands.</p><pre>eksctl get cluster<br>aws eks update-kubeconfig --name week19-eks --region us-west-1<br>kubectl get nodes</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IYJ7p36p4jNg7Z_nytcFsQ.png" /></figure><p>Next, run the following command to create our deployment.</p><pre>kubectl create deployment &lt;deployment_name&gt; --image nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2qQIGUHj1kDQ3hgfz9huQA.png" /></figure><h4><em>2. Display the details of this deployment</em></h4><p>Use the following command to show all the information about the Pods.</p><pre>kubectl get deployments<br>kubectl get pods<br>kubectl describe deployment &lt;deployment name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jITzMHd4J_O8XwWxWp10dA.png" /></figure><h4><em>3. Check the event logs from the deployment</em></h4><p>Use the following command to check the event logs for the deployment.</p><pre>kubectl logs deployment/&lt;deployment name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BHqXaqsHerP43f9SMxCR7w.png" /></figure><h4><em>4. Delete the Cluster</em></h4><p>Use the following command to delete your cluster.</p><pre>eksctl delete cluster &lt;cluster name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ffjVTh1CDHgf7YuCczL0nA.png" /></figure><p>Just like that, we have deleted our cluster and EC2 instances.</p><h4>Conclusion:</h4><p>In conclusion, deploying an Nginx image using AWS EKS is a straightforward process that can be achieved using the command line interface. By creating a deployment, running the Nginx image, and displaying deployment details and event logs, it is possible to monitor and manage the application effectively. With AWS EKS, you can easily place all of these actions within a cluster, making it easier to manage multiple deployments and applications efficiently. By following these steps, you can deploy Nginx images on AWS EKS with ease and ensure the smooth operation of your application.</p><p>Thank you for reading my post! Be sure to clean up your environment after.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df9ca5d0356d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes: Deploying a customized Nginx web server with configmap]]></title>
            <link>https://towardsaws.com/kubernetes-deploying-a-customized-nginx-web-server-with-configmap-e47ec0a2f0c7?source=rss-5618d3eb17c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e47ec0a2f0c7</guid>
            <dc:creator><![CDATA[Hasan Cheema]]></dc:creator>
            <pubDate>Sat, 08 Apr 2023 05:13:48 GMT</pubDate>
            <atom:updated>2023-04-10T04:14:30.592Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8sdIQrS2suJnDVjhxy--Ng.png" /></figure><h4>Overview:</h4><p>Kubernetes is an open-source container orchestration platform that allows you to automate the deployment, scaling, and management of containerized applications. It provides a highly scalable and flexible environment for deploying and managing containerized applications, which makes it one of the most popular container orchestration platforms today.</p><p>In this article, I will show you how to spin up two deployments with Kubernetes and have them both accessible through a single service</p><h4>What is Nginx?</h4><p>NGINX is open-source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability.</p><h4>What is deployment and service in Kubernetes?</h4><p>What’s the difference between a Service and a Deployment in Kubernetes? A deployment is responsible for keeping a set of pods running. A service is responsible for enabling network access to a set of pods. We could use a deployment without a service to keep a set of identical pods running in the Kubernetes cluster.</p><h4>What is Configmap?</h4><p>ConfigMaps are a Kubernetes mechanism that lets you inject configuration data into application pods. The ConfigMap concept allows you to decouple configuration artifacts from image content to keep containerized applications portable.</p><h4>Objectives:</h4><blockquote>1. Spin up two Deployments <br> — 1st deployment contains 2 pods running the nginx image. Include a ConfigMap that points to a custom index.html page that contains the line “This is Deployment One”<br> — 2nd deployment contains 2 pods running the nginx image. Include a ConfigMap that points to a custom index.html page that contains the line “This is Deployment Two”<br>2. Create a service that points to both deployments <br> — You should be able to access both deployments using the same IP address and port number <br>3. Use the curl command to validate that you eventually see the index.html pages from both Deployment 1 and Deployment 2.</blockquote><h4>Preconditions:</h4><blockquote>1. <em>Free tier AWS Account<br>2. AWS Cloud9 Environment<br>3. Basic Knowledge of Linux<br>4. Kubernetes Installed</em></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5zf2M4HgjjWszLd4a5%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fjohnwick-john-wick-3-parabellum-5zf2M4HgjjWszLd4a5&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNm1wYXhudWY0aThoYW03M3c2dTY0ZThqNWx5dHYwM212bGd3ZXF0aSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F5zf2M4HgjjWszLd4a5%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="183" frameborder="0" scrolling="no"><a href="https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href">https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href</a></iframe><h4>Step 1: Create the ConfigMap for our first deployment</h4><p>We need to create a ConfigMap for each of our deployments. Which will give the deployment instructions to create a unique HTML file informing the user which deployment they are viewing.</p><p>We will use the <strong><em>Vim command</em></strong> to create and edit our first deployment ConfigMap YAML file. Copy and paste the below code into the editor and make sure to save it.</p><p>If you are not familiar with Vim editor, use the document below for reference.</p><p><a href="https://www.keycdn.com/blog/vim-commands">Popular Vim Commands - Comprehensive Vim Cheat Sheet - KeyCDN</a></p><pre>#use the following command to enter into the editor<br>vi nginx-config-1.yml<br><br>#copy and past the code below into the editor <br>#Don&#39;t forget to save the file<br>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: nginx-config-1<br>  namespace: default<br>data:<br>  index.html: |<br>    &lt;html&gt;<br>    &lt;h2&gt; This is Deployment #1 &lt;/h2&gt;<br>    &lt;/html&gt;</pre><h4>Step 2: Create the ConfigMap for our second deployment</h4><p>Use the <strong><em>vim command</em></strong> to create and edit our second deployment ConfigMap YAML file.</p><pre>#use the following command to enter into the editor<br>vi nginx-config-2.yml<br><br>#copy and past the code below into the editor <br>#Don&#39;t forget to save the file<br>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: nginx-config-2<br>  namespace: default<br>data:<br>  index.html: |<br>    &lt;html&gt;<br>    &lt;h2&gt; This is Deployment #2 &lt;/h2&gt;<br>    &lt;/html&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*0MPQi35E66f8lTX_cHSXxw.jpeg" /></figure><h4>Step 3: Deploy our ConfigMaps</h4><p>The ConfigMap file has our custom HTML code which we will use to customize our Ngnix Web page. Use the following command to deploy our configmap file.</p><pre>kubectl apply -f &lt;file name.yml&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzTb9f0RCeL1BSXKfC7tnw.png" /></figure><h4>Step 4: Verify if our ConfigMaps were created</h4><p>Use the following command to check if the configmap was created.</p><pre>kubectl get configmap</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fye1wB4fAEuzM_fi6F4qWQ.png" /></figure><h4>Step 4: Create our first Pods Deployment</h4><p>We will now create our two deployments. Just like how we created the ConfigMap. Use the <strong><em>Vim command</em></strong> to create and edit our first deployment file. To do so, copy and paste the below code to your YMLA file.</p><p>For this deployment, we are going to launch two pods with an Nginx image. Both pods are using our custom HTML code.</p><pre>#use the following command to enter into the editor<br>vi nginx-deployment-1.yml<br><br>#copy and past the code below into the editor<br>#Don&#39;t forget to save the file<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginx-deployment-1<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx<br>        ports:<br>        - containerPort: 80<br>        volumeMounts:<br>        - name: nginx-index-config<br>          mountPath: /usr/share/nginx/html<br>      volumes:<br>      - name: nginx-index-config<br>        configMap:<br>          name: nginx-config-1</pre><h4>Step 5: Create our second Pods Deployment</h4><p>Use the <strong><em>Vim command</em></strong> to create and edit our second deployment YAML file.</p><pre>#use the following command to enter into the editor<br>vi nginx-deployment-2.yml<br><br>#copy and past the code below into the editor<br>#Don&#39;t forget to save the file<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginx-deployment-2<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx<br>        ports:<br>        - containerPort: 80<br>        volumeMounts:<br>        - name: nginx-index-config<br>          mountPath: /usr/share/nginx/html<br>      volumes:<br>      - name: nginx-index-config<br>        configMap:<br>          name: nginx-config-2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9DOg2uak9eci3qX82T01iQ.jpeg" /></figure><h4>Step 6: Deploy our Nginx Deployments</h4><p>Use the following command to deploy our configmap file.</p><pre>kubectl apply -f &lt;file name.yml&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E5ZizHdgRjB1cG3p-M5OXw.png" /></figure><h4>Step 7: Verify if our Deployments were created</h4><p>Use the following command to check if the configmap was created.</p><pre>kubectl get pods -o wide</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wSeEueMS8g6c3bE8ozBYOw.png" /></figure><h4>Step 8: Create a service that points to both deployments</h4><p>A service is responsible for enabling network access to a set of pods. We could use a deployment without a service to keep a set of identical pods running in the Kubernetes cluster.</p><p>Use the <strong><em>Vim command</em></strong> to create and edit our first deployment file. To do so, copy and paste the below code to your YMLA file.</p><pre>#use the following command to enter into the editor <br>vi nginx-service.yml<br><br>#copy and past the code below into the editor <br>#Don&#39;t forget to save the file<br><br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: nginx-service<br>spec:<br>  selector:<br>    app: nginx<br>  type: NodePort<br>  ports:<br>  - name: http<br>    port: 80<br>    targetPort: 80<br>    nodePort: 30080</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MO6YEn76IfA14y8FD1fSig.jpeg" /></figure><h4>Step 9: Deploy the service</h4><p>Use the following command to deploy our service file.</p><pre>kubectl apply -f nginx-service.yml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hhsza6zfLi8jtqN3BAHdIA.png" /></figure><h4>Step 10: Verify if our service was created</h4><p>Use the following command to check if the service was created.</p><pre>kubectl get service -o wide</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XNHkSIJY_5FaXaMzB5mt0w.png" /></figure><h4>Step 11: Test the webpage using the CURL command</h4><p>Now we can test to see if both of our web pages are using the custom HTML code using the curl command below.</p><pre>curl localhost:30080</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dCpi_srwOvljZcG4xOGb9Q.png" /></figure><h4>Step 12: Verify our deployment in the web browser</h4><p>Lastly, we can go ahead and check if our deployments are working in the web browser. Grap your Control Plane Instance public IPv4 address and paste it into the web browser with the port number at the end. If you refresh the browser, you should see both deployments.</p><p>Note: keep the curl command running until you see both nginx deployments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3o3fsJPd9Hl87SLqMDmK7w.jpeg" /></figure><p>In conclusion, this article demonstrates the process of creating two deployments with custom index.html pages using ConfigMaps and creating a service that points to both deployments. The end result is that both deployments can be accessed using the same IP address and port number, which can be validated using the curl command.</p><p>Thank you for reading my post! Be sure to clean up your environment after.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e47ec0a2f0c7" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/kubernetes-deploying-a-customized-nginx-web-server-with-configmap-e47ec0a2f0c7">Kubernetes: Deploying a customized Nginx web server with configmap</a> was originally published in <a href="https://towardsaws.com/">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Quick Guide on How to Build a Kubernetes Cluster Using AWS Cloud9]]></title>
            <link>https://aws.plainenglish.io/a-quick-guide-on-how-to-build-a-kubernetes-cluster-using-aws-cloud9-54a3e00dc67c?source=rss-5618d3eb17c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/54a3e00dc67c</guid>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Hasan Cheema]]></dc:creator>
            <pubDate>Wed, 05 Apr 2023 07:17:00 GMT</pubDate>
            <atom:updated>2023-04-05T07:17:00.353Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*dIPrZszfQEsdk7YovoaFWw.png" /></figure><h4>Overview:</h4><p>Kubernetes is an open-source container orchestration platform that helps automate container deployment, scaling, and management. Setting up a Kubernetes cluster on AWS Cloud9 is a simple and straightforward process that can be accomplished in a few steps. This article will guide you through the process of setting up Control Planes and Worker Nodes and installing Kubernetes and its components on AWS Cloud9.</p><h4>What is a Kubernetes Cluster?</h4><p>Kubernetes cluster is a set of nodes that run containerized applications. Containerizing applications package an app with its dependencies and some necessary services. They are more lightweight and flexible than virtual machines.</p><h4>What is a Node?</h4><p>A Node is a worker machine in Kubernetes and may be either a virtual or a physical machine, depending on the cluster. Each Node is managed by the control plane. A Node can have multiple pods, and the Kubernetes control plane automatically handles scheduling the pods across the Nodes in the cluster.</p><h4>What is a Control Plane?</h4><p>The control plane manages the worker nodes and the Pods in the cluster. In production environments, the control plane usually runs across multiple computers, and a cluster usually runs multiple nodes, providing fault tolerance and high availability.</p><h4>What is a Worker Node?</h4><p>A worker node is a node that runs the application in a cluster and reports to a control plane. The main responsibilities of a worker node are to process data stored in the cluster and handle networking to ensure traffic between the application across the cluster and outside of the cluster is properly facilitated.</p><h4>Preconditions:</h4><blockquote>1. Free tier AWS Account with IAM permissions <br>2. AWS Cloud9 IDE <br>3. Create 3 Environments within Cloud9</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5zf2M4HgjjWszLd4a5%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fjohnwick-john-wick-3-parabellum-5zf2M4HgjjWszLd4a5&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNm1wYXhudWY0aThoYW03M3c2dTY0ZThqNWx5dHYwM212bGd3ZXF0aSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F5zf2M4HgjjWszLd4a5%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="183" frameborder="0" scrolling="no"><a href="https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href">https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href</a></iframe><h4>Step 1: Setting up the Enviermontes</h4><p>Log in to the AWS Management Console, navigate to <strong><em>Cloud9</em></strong>, and then Click on <strong><em>Create Environment</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fgrsWdhqyz1guXW0n2D5CQ.png" /></figure><p>After you click Create Environment, you will be promoted to the Create Environment page. Here we will do the following configurations to create our necessary environments. We need to create one environment for Control Plane and two for the worker nodes. For the purpose of this guide, we will select the t3.small instance type and Ubuntu Server.</p><p>Create your environment with the following configurations.</p><blockquote>1. Give your Environment a name<br>2. Selecte your Environment Type <br>3. Select EC2 Instance Type<br>4. Select EC2 Instance Platform<br>5. Leave rest of the settings default</blockquote><p>Repeat the same steps for the remaining two environments, and once you are done, you should have three total environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f6Hqsh6p56DMB9DFrGVj1w.jpeg" /></figure><h4>Step 2: Modify Security Groups</h4><p>Before we head over to Cloud9 and start building our Cluster, we need to modify our inbound security rules. Before we do that, we need to know our IP address. You can use <strong>ShowMyIP </strong>to find your IP address.</p><p><a href="https://www.showmyip.com/">What Is My IP Address? (IPv4 &amp; IPv6) - Show My IP</a></p><p>Now that we have our IP address, head over to the AWS Console and navigate to the EC2 Instance dashboard. Here we will select each Cloud9 Instance that we created earlier and click on the <strong><em>security groups</em></strong> under the security section and then click on <strong><em>Edit inbound rules</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k9bx8WNytukHg2MJP-0R3A.jpeg" /></figure><p>For the two worker nodes, we need to modify the inbound rules with the following configurations. Add your IP address and Controle Plane security group ID. Repeat the same steps for the second worker node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zjs5qrVLDpFWHJxe8DOXvg.jpeg" /></figure><p>For the Controle Plane, we need to modify the inbound rules with the following configurations. Add your IP address and Security group ID for both worker nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NqSjYZNkBkXihKErbjQbjg.png" /></figure><h4><strong>Step 3: Building the Kubernetes Cluster</strong></h4><p>Head over to the Cloud9 dashboard and select your <strong><em>Control Plane</em></strong> environment and click on <strong><em>open in Cloud9</em></strong>. Here we will assign a unique hostname for each node to easily identify them. For the Control Plane, enter the following.</p><pre>sudo hostnamectl set-hostname control-plane</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nGmEaxkR9kUtxkEUtPVN9w.png" /></figure><p>For the two worker node, enter the following unique names.</p><pre>sudo hostnamectl set-hostname worker-1<br>sudo hostnamectl set-hostname worker-2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zvhoZE7HG4v3cTj0sbsVxw.jpeg" /></figure><p>Our container runtime of choice is containerd. Prior to installing it, we will activate specific kernel modules to load during start-up, ensuring that the <strong><em>overlay</em></strong> and <strong><em>br_netfilter</em></strong> modules are enabled each time the server is started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kY0k14n_BIUs3lZ7z3_w_A.png" /></figure><p>To activate these modules right away, input the following command:</p><pre>sudo modprobe overlay<br>sudo modprobe br_netfilter</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4dmmnTjIjmgQijOOyZxpEg.png" /></figure><p>After this, we will configure our network settings.</p><pre>cat &lt;&lt; EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf<br>net.bridge.bridge-nf-call-iptables = 1<br>net.bridge.bridge-nf-call-ip6tables = 1<br>net.ipv4.ip_forward = 1<br>EOF</pre><p>Next, run a sudo sysctl --system to enable the configurations</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IVTbygGPYFu9JWmVHJWk6A.png" /></figure><p>Now, we’ll install containerd:</p><pre>sudo apt-get update &amp;&amp; sudo apt-get install -y containerd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-u4mxqzrWoXoAo1ZTNWFKg.png" /></figure><h4>Step 4: Create a containerd configuration file</h4><p>Create a containerd configuration file by creating a directory with the following command and cd into that directory.</p><pre>sudo mkdir -p /etc/containerd<br><br>#after the directory is created cd into it <br>cd /ect/containerd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ErDinC8ox1twFLfS3F6QQA.png" /></figure><p>Next, we’ll create the configuration file with the following command.</p><pre>sudo containerd config default | sudo tee /etc/containerd/config.toml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GBPWDAU_AUQqGvYeJmSM1A.png" /></figure><p>To begin using the updated configuration file, we need to restart containerd with the following command.</p><pre>sudo systemctl restart containerd</pre><p>It is important to deactivate the swap function before installing the Kubernetes packages. If a node has swap enabled, a kubelet will not start properly. To disable the swap, execute the following commands:</p><pre>sudo swapoff -a &amp;&amp; sudo sed -i &#39;/ swap / s/^/#/&#39; /etc/fstab</pre><p>Next, we can go ahead and install the required Kubernetes packages with the following command.</p><pre>sudo apt-get update &amp;&amp; sudo apt-get install -y apt-transport-https curl</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SCpZISCKR_xn5NNOdkpm7w.png" /></figure><p>Next, in order to set up our package repository, we need to download a gpg signing key with the following command.</p><pre>curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0rYvGbnvHBKydQR5JhddvA.png" /></figure><p>Now we can configure our repository:</p><pre>cat &lt;&lt; EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list<br>deb https://apt.kubernetes.io/ kubernetes-xenial main                                                                                                                                                                                             <br>EOF</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3P7h-QxBoWRBk5pbDxh7lA.png" /></figure><h4>Step 5: Update package listings</h4><p>Run the following command to update the package listings.</p><pre>sudo apt-get update</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fT4HOSlZVM0p9FEo9ZjtXA.png" /></figure><p>Next, we need to install the Kubernetes packages that include kubelet, kubeadm, and kubectl.</p><ul><li><strong><em>Kubelet</em></strong> — Is responsible for handling various tasks related to Kubernetes on the node, such as initiating, upgrading, and terminating containers.</li><li><strong><em>Kubeadm</em></strong> — This is a utility that executes the essential steps to set up and launch a cluster.</li><li><strong><em>Kubectl — </em></strong>This is a CLI tool that allows you to interact with the Kubernetes cluster.</li></ul><p>Run the following command to install the packages.</p><pre>sudo apt-get install -y kubelet=1.24.0-00 kubeadm=1.24.0-00 kubectl=1.24.0-00</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ObcBx3yjXafWLe6DqwnkQw.png" /></figure><p>Next, run the following command to prevent Kubernetes from automatically upgrading the installation packages.</p><pre>sudo apt-mark hold kubelet kubeadm kubectl</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4MmIb2Wi8cbTPCh64YD4Kw.png" /></figure><p>Now we need to repeat all the steps in our two worker nodes. Enter the following commands one at a time in each node individually.</p><pre>cat &lt;&lt; EOF | sudo tee /etc/modules-load.d/containerd.conf<br>overlay<br>br_netfilter<br>EOF<br><br>sudo modprobe overlay<br>sudo modprobe br_netfilter<br><br>cat &lt;&lt; EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf<br>net.bridge.bridge-nf-call-iptables = 1<br>net.bridge.bridge-nf-call-ip6tables = 1<br>net.ipv4.ip_forward = 1<br>EOF<br><br>sudo sysctl --system<br><br>sudo apt-get update &amp;&amp; sudo apt-get install -y containerd<br><br>sudo mkdir -p /etc/containerd<br><br>cd /etc/containerd<br><br>sudo containerd config default | sudo tee /etc/containerd/config.toml<br><br>sudo systemctl restart containerd<br><br>sudo swapoff -a &amp;&amp; sudo sed -i &#39;/ swap / s/^/#/&#39; /etc/fstab<br><br>sudo apt-get update &amp;&amp; sudo apt-get install -y apt-transport-https curl<br><br>curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -<br><br>cat &lt;&lt; EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list<br>deb https://apt.kubernetes.io/ kubernetes-xenial main                                                                                                                                                                                             <br>EOF<br><br>sudo apt-get update<br><br>sudo apt-get install -y kubelet=1.24.0-00 kubeadm=1.24.0-00 kubectl=1.24.0-00<br><br>sudo apt-mark hold kubelet kubeadm kubectl</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*73myi6_ibGTea2jwL6otIg.jpeg" /></figure><h4>Step 6: Initialize our Control Plane Cluster</h4><p>Use the following command to initialize the control plane cluster.</p><pre>sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --kubernetes-version 1.24.0</pre><p>If you followed along correctly, you should get a message that the control plane has been initialized successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FyuJlwDDwRhRWn_RqW689Q.png" /></figure><p>Now, we will execute the three commands that were provided to us in the output of our last command to start using the cluster. If we run the following command <strong><em>kubectl get nodes </em></strong>we should get something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6bYTl2_iBYzHp0herVfLjg.png" /></figure><p>As you can see, we are now able to interact with our cluster. However, the node appears to be unavailable, indicating that we must establish a pod network for the cluster. To do that, we can run the following command, which will deploy the Calico networking plugin:</p><pre>kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kbBeqatZ7fh4jpNt7o_6eQ.png" /></figure><p>We have successfully installed our Calico plugin. Now if we run the <strong><em>kubectl get nodes</em></strong> command again, we can see that our status for the control plane node is “Ready” now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*13v_-q4GV5PDAb0JvvdTVA.png" /></figure><p>Now we can join both of our worker nodes to the control plane node. To do that, go ahead and grab the<strong><em> kubeadm join</em></strong> from the init command output we ran earlier and paste it into each worker node environment but make sure to put <strong><em>sudo</em></strong> in front of it.</p><pre>sudo kubeadm join 172.31.89.121:6443 --token b1a3t1.igj1kwvk3zwf4uz1 --discovery-token-ca-cert-hash sha256:9b3c0165fb7d9cf76fa8f4e307bff7f106fd99fd25f4410d68cb83eb2a4da931</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CQ_jwOC7JsCKAx1QsvS28Q.jpeg" /></figure><p>As you can see, both nodes have successfully joined the cluster.</p><p>Lastly, let’s go ahead and run the kubectl get nodes command again in the control panel environment.</p><pre>kubectl get nodes </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eyeflwilt20TcKPn5cMOjw.png" /></figure><p>Congratulations! You have now set up a control plane and worker nodes using AWS Cloud9 and installed Kubernetes and its components. You can now start deploying and managing containerized applications using Kubernetes.</p><p>Thank you for reading my post! Be sure to clean up your environment after.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Interested in scaling your software startup</em></strong><em>? Check out </em><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54a3e00dc67c" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/a-quick-guide-on-how-to-build-a-kubernetes-cluster-using-aws-cloud9-54a3e00dc67c">A Quick Guide on How to Build a Kubernetes Cluster Using AWS Cloud9</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes: How to Deploy an Nginx Image Using AWS CLI]]></title>
            <link>https://towardsaws.com/kubernetes-how-to-deploy-an-nginx-image-using-aws-cli-b7436b86bfe0?source=rss-5618d3eb17c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7436b86bfe0</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Hasan Cheema]]></dc:creator>
            <pubDate>Sat, 01 Apr 2023 06:59:20 GMT</pubDate>
            <atom:updated>2023-04-01T06:59:20.315Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*V-pPQgrU7x0BW9syqmilCg.jpeg" /></figure><h4>Overview:</h4><p>Kubernetes is an open-source container orchestration platform that allows you to automate the deployment, scaling, and management of containerized applications. It provides a highly scalable and flexible environment for deploying and managing containerized applications, which makes it one of the most popular container orchestration platforms today.</p><p>In this article, I will show you how to deploy an Nginx image on Kubernetes using the AWS CLI. You will be guided through the steps of setting up a deployment that runs the Nginx image, checking its details, viewing the event logs, and deleting it.</p><h4>What is Nginx Image?</h4><p><strong>Nginx is the most popularly used ingress controller for Kubernetes clusters</strong>. Nginx has most of the features enterprises are looking for and will work as an ingress controller for Kubernetes regardless of which cloud, virtualization platform, or Linux operating system your Kubernetes cluster is running on.</p><h4>What is Kubernetes and how does it work?</h4><p>Kubernetes networking works <strong>by creating pods and services</strong>. A pod is a group of one or more containers that are deployed together and share a network namespace and IP address. Containers within a pod can communicate with each other using a local host. Services are used to expose one or more pods to the outside world.</p><h4>What are the benefits of Kubernetes?</h4><p>One of the best things about using Kubernetes is that <strong>the platform helps you drive better business productivity</strong>. Since it eliminates the need for most manual processing, you can enhance productivity and drive results. Kubernetes automates many processes, making your business much more efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QGbxZ60_tMO2FF6KAZvpjg.png" /></figure><h4>Fundamental Objectives:</h4><blockquote>1. Create a deployment that runs the nginx image.<br>2. Display the details of this deployment<br>3. Check the event logs from the deployment<br>4. Delete the deployment</blockquote><h4>Advanced Objectives:</h4><blockquote>1. Create the same deployment using a yaml file <br>2. Display the details of this deployment via the command line<br>3. Update the yaml file to scale the deployment to 4 nginx containers <br>4. Verify the change via the command line</blockquote><h4>Preconditions:</h4><blockquote>1. Free tier AWS Account <br>2. AWS Cloud9 Environment <br>3. Kubernetes Installed <br>4. Basic Knowledge of Linux</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5zf2M4HgjjWszLd4a5%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fjohnwick-john-wick-3-parabellum-5zf2M4HgjjWszLd4a5&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNm1wYXhudWY0aThoYW03M3c2dTY0ZThqNWx5dHYwM212bGd3ZXF0aSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F5zf2M4HgjjWszLd4a5%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="183" frameborder="0" scrolling="no"><a href="https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href">https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href</a></iframe><h4>Step 1: Check the version</h4><p>Use the command below to check your Kubernetes version</p><pre>kubectl version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1pVFtNO9b-a7hU_pj_gRFQ.png" /></figure><h4>Step 2: Create a deployment that runs the Nginx Image</h4><p>Use the following command to create your deployment.</p><pre>kubectl create deployment &lt;name it&gt; --image=nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFzOqkfILqWhDYPZmOy0Cg.png" /></figure><h4>Step 3: Verify that the deployment has been created</h4><p>Use the following command to check if our deployment was created.</p><pre>kubectl get deployment &lt;deployment name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*USpqw-RG9ylCNpHkkC7uqw.png" /></figure><h4>Step 4: Display the Pods</h4><p>Use the following command to check if your Pod is running.</p><pre>kubectl get pods</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o19n5AAd4ZKlpc8oYhW8hw.png" /></figure><h4>Step 5: Display the details of the deployment</h4><p>Use the following command to show all the information about the Pods.</p><pre>kubectl describe deployment &lt;deployment name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j4rvYxTn1Gt5_8WlAn7OrQ.png" /></figure><h4>Step 6: Check the deployment’s event logs</h4><p>Use the following command to check the event logs for the deployment.</p><pre>kubectl logs deployment/&lt;deployment name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wt46x_fmrXsNgp56dSI7Xg.png" /></figure><h4>Step 7: Delete the deployment</h4><p>Use the following command to delete your deployment.</p><pre>kubectl delete deployment &lt;deployment name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8jmsZxglxEYkjbBcDQT0Ug.png" /></figure><p>For the advanced portion of this article, we will create the same deployment using a YAML file, and display the details of the deployment via CLI. Then we will update the YAML file to scale the deployment to 4 Nginx containers and lastly verify the changes via the command line.</p><h4>Step 1: Create a YAML file</h4><p>To create the same deployment using a YAML file we can use the following command.</p><pre>vim &lt;filename.yaml&gt;<br><br>#code <br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: week17-deployment<br>  labels:<br>    app: nginx<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx:1.14.2<br>        ports:<br>        - containerPort: 80</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6W08cNOIjJByx4xiahO4Vg.png" /></figure><h4>Step 2: Create the deployment using a .yaml file</h4><p>Use the following command to create the deployment.</p><pre>$ kubectl apply -f &lt;enter the file name.yaml&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b6cq3sngC9hCzLCGhC3VjA.png" /></figure><h4>Step 3: Verify if our deployment is running</h4><p>Use the following command to check if the deployment was created.</p><pre>Kubectl get pod</pre><h4>Step 4: Display the details of the deployment</h4><p>To display the details of the deployment we can use the following command.</p><pre>kubectl describe deployment &lt;deployment name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZUpmMrNQP12WB0TyFt95vw.png" /></figure><h4>Step 5: Update the YAML file to scale the deployment to 4 Nginx containers</h4><p>To update the YAML file to scale the deployment to 4 Nginx containers, we can edit the “week17.yaml” file and change the “replicas” value to 4 and save the file. Then run the following command to check if it updated.</p><pre>kubectl apply -f &lt;enter file name.yaml&gt;<br><br>or <br><br>kubectl describe deployment &lt;deployment name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gDBYH5GlhTJ6Y2-dY2S5FQ.png" /></figure><h4>Step 6: Verify if our deployment is running</h4><pre>Kubectl get pod</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xmZDjj150vodtC9dsdCDFA.png" /></figure><h4>Step 7: Verify the changes via the command line</h4><p>Use the following command to verify the changes.</p><pre>kubectl get deployments</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*akhPh3Fpf-J9Dk4tSeBUKQ.png" /></figure><h4>Conclusion:</h4><p>In this article, we discussed how to deploy an Nginx image using AWS CLI. We created a deployment that runs the Nginx image, displayed the details of the deployment, checked the event logs from the deployment, and finally deleted the deployment. Kubernetes is a powerful tool for container orchestration, and with AWS CLI, you can easily deploy and manage your containerized applications.</p><p>Thank you for reading my post! Be sure to clean up your environment after.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7436b86bfe0" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/kubernetes-how-to-deploy-an-nginx-image-using-aws-cli-b7436b86bfe0">Kubernetes: How to Deploy an Nginx Image Using AWS CLI</a> was originally published in <a href="https://towardsaws.com/">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy a custom Nginx Docker Image and Push it to Docker Hub]]></title>
            <link>https://medium.com/@hasan.cheema23/deploy-a-custom-nginx-docker-image-and-push-it-to-docker-hub-118f1ab2186b?source=rss-5618d3eb17c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/118f1ab2186b</guid>
            <dc:creator><![CDATA[Hasan Cheema]]></dc:creator>
            <pubDate>Thu, 02 Mar 2023 02:37:07 GMT</pubDate>
            <atom:updated>2023-03-02T02:37:07.138Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*zp-UZUFB1PVPMlGUs7CzKA.png" /></figure><h4>Overview:</h4><p>In this article, I will guide you through the process of creating your own customized Docker image to host a static webpage. After that, I’ll launch a Docker Container with my unique image inside of it and store the Docker Image in the AWS Elastic Container Registry (ECR).</p><h4>What is Docker?</h4><p>Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications.</p><h4>What is a Docker Container Image?</h4><p>A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application for instance code, runtime, system tools, system libraries, and settings.</p><h4>What is ECR?</h4><p>Amazon Elastic Container Registry (Amazon ECR) is an AWS-managed container image registry service that is secure, scalable, and reliable. Amazon ECR supports private repositories with resource-based permissions using AWS IAM.</p><h4>Objectives:</h4><blockquote>1. Create your own image using Nginx. Include a customized index.html file that can be viewed from a local browser.<br>2. Deploy your container with port 8080 open<br>3. Save your container data to the AWS Elastic Container Registry (ECR), and to your Docker Hub account.</blockquote><h4>Preconditions:</h4><blockquote>1. AWS Free Tier Account<br>2. DockerHub Account <br>3. Basic Knowledge of HTML<br>4. IDE of your chouse (I will be using Cloud9)</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5zf2M4HgjjWszLd4a5%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fjohnwick-john-wick-3-parabellum-5zf2M4HgjjWszLd4a5&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNm1wYXhudWY0aThoYW03M3c2dTY0ZThqNWx5dHYwM212bGd3ZXF0aSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F5zf2M4HgjjWszLd4a5%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="183" frameborder="0" scrolling="no"><a href="https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href">https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href</a></iframe><h4>Step 1: Create the Docker image</h4><p>Before we get started with creating the <strong><em>Docker Image </em></strong>we will create a <strong><em>Directory</em></strong> to keep all the necessary files and resources in one place, making it easier to manage, maintain, and update the image.</p><p>The directory will also help Docker to find and use the required files during the image-building process.</p><p>Use the <strong><em>mkdir</em></strong> command to create the directory<br><strong><em>cd</em></strong> to move into the directory</p><pre>mkdir directory name<br>cd directory name </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qnx_4B1UCTzhnOUL90HE-Q.png" /></figure><h4>Step 2: Pull the Docker image</h4><p>For us to deploy our website we need to pull the latest Nginx Image from Docker. We can use the following command to accomplish that.</p><pre>docker pull nginx:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZYdscc7MBwV7PDnHdZLHw.png" /></figure><h4>Step 3: Verify that the NGINX image was pulled successfully</h4><p>We can confirm from the Status line that the Nginx image is the latest and that the pull was successful. We can also use the <strong><em>docker images</em></strong> command to confirm that our pull was successful.</p><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RblN7_ajThF9x9VD2yO_1A.png" /></figure><h4>Step 4: Create the Dockerfile and Index.HTML</h4><p>We will use the t<strong><em>ouch</em></strong> command to create the index.html and dockerfile and <strong><em>vim</em></strong> command to edit the files.</p><p>Dockerfile</p><pre>FROM nginx:1.10.1-alpine<br>COPY index.html /usr/share/nginx/html<br>EXPOSE 8080<br>CMD [&quot;nginx&quot;, &quot;-g&quot;, &quot;daemon off;&quot;]</pre><p>index.html</p><pre>&lt;!doctype html&gt;<br>&lt;html&gt;<br> &lt;body style=&quot;backgroud-color:rgb(49, 214, 220);&quot;&gt;&lt;center&gt;<br>    &lt;head&gt;<br>     &lt;title&gt;Docker Project&lt;/title&gt;<br>    &lt;/head&gt;<br>    &lt;body&gt;<br>     &lt;p&gt;Welcome to my Docker Project!&lt;p&gt;<br>        &lt;p&gt;Today&#39;s Date and Time is: &lt;span id=&#39;date-time&#39;&gt;&lt;/span&gt;&lt;p&gt;<br>        &lt;script&gt;<br>             var dateAndTime = new Date();<br>             document.getElementById(&#39;date-time&#39;).innerHTML=dateAndTime.toLocaleString();<br>        &lt;/script&gt;<br>        &lt;/body&gt;<br>&lt;/html&gt;</pre><p>Make sure to save the files by using hitting the esc button and using :wq command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AP4nC1schWEfZO7icoEWCw.png" /></figure><h4>Step 5: Build the image</h4><p>Run the following command in the Terminal to build the Image.</p><pre>#make sure to add a dot at the end <br>docker build -t &lt;new_image_name&gt; .</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZqjaAGSjRFg_KxBpuQ0aVA.png" /></figure><p>Use the following command to verify the Image was successfully built.</p><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HcO8KHvk-TCZMVyVDFccDg.png" /></figure><h4>Step 6: Build and deploy the container</h4><p>Use the following command to create a container with the image we created earlier using the following command.</p><pre>docker run -d --name &lt;name-container&gt; -p 8080:80 &lt;new_image_name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jsHtVE__o0uqUNtf7ypxew.png" /></figure><h4>Step 7: Check if the container was successfully created.</h4><p>With the following command, we can verify that our container was successfully created.</p><pre>docker ps -a</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qie9bHEcWt5XHgMJCvl8eA.png" /></figure><h4>Step 8: Verify that the container is running</h4><p>Take the Public IPv4 Address of the Instance your Cloud9 is running on and paste it into a web browser. Make sure to add :8080 at the end.</p><pre>&lt;public_ip&gt;:8080</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1zG2D_QiKseSToKFYJyAww.png" /></figure><h4>Step 9: Push the container image to the AWS Elastic container Registry (ECR)</h4><p>Now that our container is built we can go ahead and push it to Amazon ECR. But before doing that we need to create a Repository. Use the command below to create a Repo.</p><pre>aws ecr create-repository --repository-name &lt;repo name&gt; --region us-west-1</pre><p>You should get something like this if the command was run successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dbx3ZVNG3NyNRjpBNOH75g.png" /></figure><h4>Step 10: Verify if our Repo was created</h4><p>Another way to verify if the Repo was created is to navigate to the Amazon <strong><em>Elastic Container Registry</em></strong> (ECR) from the management console and click on Repositories and you should see the Repository we just created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jlup8Zh40QjpE5tXkRNlRA.png" /></figure><p>Now that we have our Repository we can run the following command to log in to the ECR.</p><pre>aws ecr get-login-password --region us-west-1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Il7mFKI1g7k23Pjx_57Lag.png" /></figure><p>Save this output of the command above somewhere safe because we will need it later. Next, run the following command.</p><pre>aws ecr --region us-east-1| docker login -u AWS -p &lt;Token Output&gt; &lt;ECR Repository URI&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lcj43wNp-bWCQQDAe1dAUA.png" /></figure><h4>Step 11: Tag the image and push it to ECR</h4><p>We have now successfully logged in. Next, we will tag our image before we push it to the ECR Repo with the following command</p><pre>docker tag &lt;image name&gt; &lt;ECR Repo url&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9sGbjDa8V2yJWTyKlnhKKA.png" /></figure><p>We have successfully tagged our image and can now push it to the ECR with the following command.</p><pre>docker push &lt;ECR repo url&gt; </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zklDz_oVoJjMGOXFylJSvQ.png" /></figure><h4>Step 12: Verify if the image was pushed to the Repo</h4><p>Navigate back to the ECR Dashboard and click on the Repository name we just created and under images you should see the image we just pushed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qaEkAvUfxfsIBO-eXHQ7lQ.png" /></figure><h4>Step 1: Push the image to Docker Hub</h4><p>Now that we have our image in the ECR Repo we can go ahead and push that to our Docker Hub account. Run this command in the terminal to push the image to Docker Hub.</p><pre>docker login -u &lt;docker username&gt; </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C1UnHsleLv-dlOM5o859BA.png" /></figure><h4>Step 2: Create a Repository in Docker</h4><p>Now that we have successfully logged in to our Docker Hub account we can go ahead and create a repository within the Docker Hub account.</p><p>From the main page click on <strong><em>Create Repository</em></strong>.</p><blockquote>Give your Repo a name<br>Give it a description <br>Select either Private or Public <br>Click on Create</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CSSzlo_daAGegWovBMd2cA.png" /></figure><h4>Step 3: Commit the image</h4><p>Now that we have created the Repository let’s go ahead and commit our image to it with the following command.</p><pre>docker commit &lt;container id&gt; &lt;dockerhub username/docker hub repo name:tag name</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lswnw01T70CuMxT-bPtCXg.png" /></figure><h4>Step 4: Push the image to Docker Repo</h4><p>Lastly, we can push the image to our Docker Repo with the following command. For the tag, name use the tag we created earlier.</p><pre>docker push dockerhub username/dockerhub repo:tagname</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qXfrIPDO77ACOQRQdwZjQw.png" /></figure><h4>Step 5: Verify if the image was pushed</h4><p>Navigate back to the Docker Hub home page and click on your Repository and you should see your image under the <strong><em>Tags</em></strong> section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HOTqURNLf01OXqxaOypmvg.png" /></figure><p>Thank you for reading my post! Be sure to clean up your environment after.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=118f1ab2186b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to trigger Lambda to send an SQS message with Python]]></title>
            <link>https://python.plainenglish.io/how-to-trigger-lambda-to-send-an-sqs-message-with-python-dbb0dc6183aa?source=rss-5618d3eb17c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbb0dc6183aa</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Hasan Cheema]]></dc:creator>
            <pubDate>Thu, 23 Feb 2023 08:16:37 GMT</pubDate>
            <atom:updated>2024-09-16T10:15:54.685Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8TOEouPs81Wb6W4dUXdY2Q.png" /></figure><h4>Overview:</h4><p>In this article, I will teach you how to use Python and Boto3 to create an SQS queue. In addition, we’ll deploy a Lambda function to deliver a message to our SQS queue. Next, we will configure an HTTP API trigger for an API Gateway to call the function.</p><h4>What is SQS Queue?</h4><p><strong>Amazon Simple Queue Service</strong> (SQS) lets you send, store, and receive messages between software components at any volume without losing messages or requiring other services to be available.</p><h4>What is Lambda Function?</h4><p>A lambda function is an anonymous function (i.e., defined without a name) that can take any number of arguments but unlike normal functions, it evaluates and returns only one expression. A lambda function in Python has the following syntax: lambda parameters: expression.</p><h4>What is API Gateway?</h4><p>An API gateway is an Application Programming Interface (API) management tool that sits between a client and a collection of backend services.</p><h4>Preconditions:</h4><blockquote>1. You will need an IAM User<br>2. AWS Credentials <br>3. AWS CLI Tools<br>4. Have Python3 and Boto3 Installed <br>5. Cloud9 IDE</blockquote><h4>Objectives:</h4><blockquote>1. Create a Standard SQS Queue using Python.<br>2. Create a Lambda function in the console with a Python 3.7 or higher runtime.<br>3. Modify the Lambda to send a message to the SQS queue. Your message should contain either the current time or a random number. You can use the built-in test function for testing.<br>4. Create an API gateway HTTP API type trigger.<br>5. Test the trigger to verify the message was sent.</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5zf2M4HgjjWszLd4a5%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fjohnwick-john-wick-3-parabellum-5zf2M4HgjjWszLd4a5&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNm1wYXhudWY0aThoYW03M3c2dTY0ZThqNWx5dHYwM212bGd3ZXF0aSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F5zf2M4HgjjWszLd4a5%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="183" frameborder="0" scrolling="no"><a href="https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href">https://medium.com/media/b09f87dc7516cae58e74341cd3a8ac58/href</a></iframe><blockquote><em>💡</em> <strong>Learn how to efficiently store one million small objects to S3 for your stock analytics app with AWS Athena integration:</strong></blockquote><p><a href="https://differ.blog/p/how-to-write-one-million-small-objects-to-s3-c69e8c">How to write one million small objects to S3</a></p><blockquote><em>👉</em> To read more such acrticles, <a href="https://differ.blog/"><strong>sign up for free on Differ</strong></a>.</blockquote><p>Before we get started let’s set up our workspace. I’ve already installed the AWS CLI and boto3. But if you haven’t run the following commands in the Terminal to install them.</p><pre>pip3 install awscli<br>pip3 install boto3</pre><p>Now that we have our environment setup let’s get started.</p><h4>Step 1: Create a Standard SQS Queue</h4><p>Log into the <strong><em>AWS Management Console</em></strong>, navigate to <strong><em>Cloud9</em></strong>, and either create a new Environment or pick an existing one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l-e1TV3ThhDIz8IvMwgOvQ.png" /></figure><p>Once you have the Environment open create a new <strong><em>Python file</em></strong> by navigating to <strong><em>File</em></strong> and selecting <strong><em>New from Template</em></strong> and <strong><em>Python File</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ec3HDE8gFf86KCOHgzEgqA.png" /></figure><p>Next, let’s write our code and save it by navigating back to <strong><em>File</em></strong> and selecting <strong><em>Save as</em></strong>. Give the file a name and click <strong>Save</strong>. After that <strong><em>run,</em></strong> the code and you will see at the bottom of the terminal if your code ran successfully without any errors.</p><pre>import boto3 <br># setup the SQS Service<br>sqs = boto3.resource(&#39;sqs&#39;)<br><br># Create the queue<br>queue = sqs.create_queue(QueueName=&#39;week15_queue&#39;)<br><br># Print the queue url<br>print(queue.url)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Egpe8Q-RXF4U4gpcefLEOg.jpeg" /></figure><h4>Step 2: Verify if the SQS Queue was created</h4><p>Navigate back to the <strong><em>AWS Management Console</em></strong> and search for <strong><em>SQS</em></strong> in the search bar. Select Simple Queue Service (SQS) which will take you to the SQS dashboard and there you will see that our <strong><em>Queue</em></strong> has been generated in the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d7sxkiFBA--tltMQlqtE7w.png" /></figure><h4>Step 3: Create the Lambda Function</h4><p>In order to send a message to our <strong><em>SQS Queue</em></strong> we first need to create a <strong><em>Lambda Function</em></strong>. Head back to the Management Console and navigate to the Lambda dashboard and select <strong><em>Create Function</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IWDAVc6UQd4IeT6sTLEJaQ.png" /></figure><p>Once you navigate to the <strong><em>Lambda Dashboard,</em></strong> select <strong><em>Create Function</em></strong> option. Where we will do the following configurations.</p><blockquote>1. Select Author from scratch <br>2. Give your Function a name <br>3. For Runtime select Python 3.9 from the drop bar <br>4. Leave rest of the settings as Default <br>5. Select Create Function</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_j_1Uh7B-ATB49ZNoZwgyQ.png" /></figure><p>For us to interact with our SQS Queue, we will need to modify our Lambda Function so that we can send out a message. In order to establish communication between SQS and Lambda, it is necessary to configure permissions. For the purpose of this tutorial, we will grant complete access to SQS, but it is important to keep in mind the principle of least privilege and only grant the necessary permissions.</p><p>From the AWS Console navigate to the Lambda Dashboard and click on the Function we created earlier. Navigate to <strong><em>Configuration</em></strong> and select <strong><em>Permissions</em></strong>. Next under <strong><em>Execution Role</em></strong> click on the <strong><em>Role name </em></strong>which will open a new tab for <strong><em>IAM Management Console</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-7rO8jYvt4oXMZ_jqRtRRg.png" /></figure><p>Once you are on the <strong><em>IAM Dashboard</em></strong> navigate to <strong><em>Roles</em></strong> and select <strong><em>Add Permissions. </em></strong>Next, click on <strong><em>Attach policies</em></strong> and search for the appropriate SQS policy and attach it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TpRLKCB4_qThWTW4ycEjHg.jpeg" /></figure><p>Once our permissions have been added, go back to the Lambda function Dashboard and select <strong><em>Code</em></strong>. Here we’ll input a Lambda script that will send a message to the SQS queue.</p><p>Once the code is ready click on <strong><em>Deploy </em></strong>to save the code and click on <strong><em>Test</em></strong>.</p><pre>import json<br>import boto3<br>from datetime import datetime<br><br><br>def lambda_handler(event, context):<br><br>    now = datetime.now()                                        <br>    date = &quot;%m/%d/%Y&quot;                                           <br>    time = &quot;%H:%M&quot;                                          <br>    current_time = now.strftime(date+&quot; &quot;+time)<br>    message = &quot;This message was sent: &quot; + current_time<br><br>    sqs = boto3.client(&#39;sqs&#39;)<br><br>    sqs.send_message(<br>        QueueUrl=&quot;https://sqs.us-west-1.amazonaws.com/340928755085/week15_queue&quot;,<br>        MessageBody=current_time<br>    )<br><br>    return {<br>        &#39;statusCode&#39;: 200,<br>        &#39;body&#39;: json.dumps(message)<br>    } </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uKF1KlKY4_sfyZm_si8t-Q.png" /></figure><h4>Step 4: Test the Lambda Function</h4><p>To see if the function is working click on Test which will prompt you to the Configure Test Event window here we need to do some configurations.</p><blockquote>Select Create new event<br>Give your Event a name<br>For Event sharing settings select Private<br>Although Template is optional we will be selecting apigatway-aws-proxy<br>Click on Save</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*Es0xo80J7C-QYOnh-5_UrQ.png" /></figure><p>After you are done configuring the Test Event and saving it click on <strong><em>Test</em></strong>.</p><p>You will know your lambda function is operating once the response displays a<strong><em> status code of 200 </em></strong>and the body contains the <strong><em>time</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xGAvUndVJVMAYztY3Z_y6g.png" /></figure><h4>Step 5: Creating the API Gateway Trigger</h4><p>While you are still on the Lambda function dashboard, click on <strong><em>Add trigger</em></strong> under the Function overview header to create and configure the API Gateway trigger. Here we will do the following configurations.</p><blockquote>Under Trigger Configuration drop down menu, select API Gateway<br>Select Create a new API<br>For API type select HTTP API <br>Select open from the drop down menu for Security <br>Give your API a name under Additional settings <br>Leave everything else as default and click on Add</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vEN41Kr4HZmIkH6BQBAq6A.jpeg" /></figure><h4>Step 6: Verify if the Function is working with our API</h4><p>From the Function dashboard navigate to Triggers and click on the Configuration tab. Enter the <strong><em>API endpoint URL</em></strong> into the browser after copying it there to utilize the function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IsS_iJc_8Cr8dEMFsmh4Yw.png" /></figure><p>A new tab will launch that will show the current date and time which confirms that the Trigger worked successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*02b99ChtmCTTQ1IC9_J64Q.png" /></figure><p>Another way to confirm that our API Trigger is successfully working is by navigating back to the SQS dashboard and doing the following.</p><blockquote>Click on the Queue we created earlier <br>Click on Send and Receive Messages <br>Click on Poll for messages<br>Click on the latest message received</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZaBr7lef39JYqbKbijADeg.jpeg" /></figure><p>Lastly, click on <strong><em>body</em></strong> to confirm that our Trigger was successfully working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*VYcHa0fRsCyKC8GpXPfUTw.png" /></figure><p>Thank you for reading my post!</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbb0dc6183aa" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/how-to-trigger-lambda-to-send-an-sqs-message-with-python-dbb0dc6183aa">How to trigger Lambda to send an SQS message with Python</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a DynamoDB Table with Boto3 in AWS IDE using Python]]></title>
            <link>https://python.plainenglish.io/create-a-dynamodb-table-with-boto3-in-aws-ide-using-python-f9867d7096c3?source=rss-5618d3eb17c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9867d7096c3</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[dynamodb]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[boto3]]></category>
            <dc:creator><![CDATA[Hasan Cheema]]></dc:creator>
            <pubDate>Tue, 14 Feb 2023 16:16:29 GMT</pubDate>
            <atom:updated>2023-02-14T16:16:29.203Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*xnBWnJM2K9NC6AcgbpMNOw.png" /></figure><h4>Overview:</h4><p>In this article, I will guide you through the process of creating a DynamoDB table using the Cloud9 Integrated Development Environment (IDE). We will be using Python and the Boto3 library, which we will install in our workspace. Additionally, I will provide code snippets for inserting data into the table, searching the table, removing an item from the table, and deleting the entire table.</p><h4>What is AWS Cloud9?</h4><p><strong><em>AWS Cloud9</em></strong> is a cloud-based integrated development environment (IDE) that <strong>lets you write, run, and debug your code with just a browser</strong>. It combines the rich code editing features of an IDE such as code completion, hinting, and step-through debugging, with access to a full Linux server for running and storing code.</p><h4>What is Boto3?</h4><p>Boto3 is <strong>the name of the Python Software Development Kit (SDK) for AWS</strong>. It allows you to directly create, update, and delete AWS resources from your Python scripts.</p><h4>Preconditions:</h4><ol><li>You will need an IAM user</li><li>AWS Credentials</li><li>AWS CLI tools</li><li>Have Python3 Installed</li><li>Cloud9 IDE</li></ol><h4>Objectives:</h4><ol><li>Create a DynamoDB table for something of your choosing (e.g. movies, food, games).</li><li>Add 10 or more items to the table</li><li>Use boto3 and Python to scan the DynamoDB table.</li><li>Use boto3 and Python to query the table</li><li>Remove an item from a table</li><li>Lastly, delete the table</li></ol><p>let&#39;s start by breaking down the objectives into smaller steps.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3o6ZtfVrAQ7jdkwnrW%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Frobin-schulz-tomorrowland-robin-schulz-3o6ZtfVrAQ7jdkwnrW&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2F3o6ZtfVrAQ7jdkwnrW%2Fgiphy.gif%3Fcid%3D790b76115a69d07a4ceabc981c80409efd3238efd7a1edbd%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="228" frameborder="0" scrolling="no"><a href="https://medium.com/media/031a150779f05440f296a9e555810c61/href">https://medium.com/media/031a150779f05440f296a9e555810c61/href</a></iframe><p>I am going to create a table for my 10 favorite music festivals. To get started, when using Python, the first step is to “<strong><em>import boto3.</em></strong>” It’s important to ensure that the AWS credentials and region name are specified when creating the DynamoDB. The table will initially have 2 attributes, the P<strong><em>rimary Key</em></strong>, and the <strong><em>Sort Key</em></strong>, and additional attributes can be added later when items are inserted into the table.</p><h4>Step 1: Create our workspace in AWS Console</h4><p>Log in to the AWS Management Console, navigate to <strong><em>Cloud9</em></strong>, and then Click on <strong><em>Create Environment</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AVqqHRfzjLO-Fg70Rqs6Jw.jpeg" /></figure><p>Give your environment a name and leave the rest of the settings as default and click on <strong><em>Create</em></strong> to move forward.</p><p>Now that our Environment is created, select it and click on <strong><em>open in Cloud9</em></strong>. Wait a few minutes and your workspace will open up in another browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PaoWeRj7u9TE-B8Hm_5kPA.jpeg" /></figure><p><strong>Step 2: Configure the Boto3 SDK and connect to AWS</strong></p><p>After the environment is created we need to install Boto3 and connect to the AWS account. For that, you need to use your AWS account and an IAM user with the correct permissions.</p><p>Go ahead and install the Boto3 SDK so we can create, update, and delete AWS resources from the Python scripts.</p><p>Enter the following command to install Boto3 in the terminal at the bottom of the screen.</p><pre>pip install boto3</pre><p>Once the installation is completed you should see the following outcome.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zjdEvhRRLzb6P_po3XktYA.png" /></figure><p>Next, we will connect to our environment using the following command. Enter your own <strong><em>Access Key </em></strong>and <strong><em>Secret Access Key</em></strong>. You can leave the Region and output format default.</p><pre>aws configure <br><br>AWS Access Key ID [None]: <br>AWS Secret Access Key [None]: <br>Default region name [None]: us-west-1<br>Default output format [None]: json</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3MikdvezYXrncDfPtVkkaQ.png" /></figure><h4>Step 3: Create the DynamoDB Table</h4><p>Before we get started let’s go ahead and navigate to <strong><em>File</em></strong> and select <strong><em>New from Template</em></strong> and <strong><em>Python File</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f9RGTv2lLNu19tPcKjgxwg.png" /></figure><pre>#!/usr/bin/env python3 <br>import boto3<br>dynamodb = boto3.resource(&#39;dynamodb&#39;,<br>    aws_access_key_id=&#39;*******************&#39;,<br>    aws_secret_access_key=&#39;***********************&#39;,<br>    region_name=&#39;us-west-1&#39;,<br>    )<br>#Connect to DynamoDB<br>dynamodb = boto3.resource(&#39;dynamodb&#39;)<br><br>#Create the table<br>table = dynamodb.create_table(<br>    TableName=&#39;EDM_Music_Festival&#39;,<br>    KeySchema=[<br>        {<br>            &#39;AttributeName&#39;: &#39;ID&#39;,<br>            &#39;KeyType&#39;: &#39;HASH&#39;<br>        },<br>        {<br>            &#39;AttributeName&#39;: &#39;Name&#39;,<br>            &#39;KeyType&#39;: &#39;RANGE&#39;<br>        }<br>    ],<br>    AttributeDefinitions=[<br>        {<br>            &#39;AttributeName&#39;: &#39;ID&#39;,<br>            &#39;AttributeType&#39;: &#39;N&#39;<br>        },<br>        {<br>            &#39;AttributeName&#39;: &#39;Location&#39;,<br>            &#39;AttributeType&#39;: &#39;S&#39;<br>        }<br>    ],<br>    ProvisionedThroughput={<br>        &#39;ReadCapacityUnits&#39;: 10,<br>        &#39;WriteCapacityUnits&#39;: 10<br>    }<br>)<br><br>#<br>print(table)</pre><p>After you have written the code, go ahead and save it by navigating back to <strong><em>File</em></strong> and selecting <strong><em>Save as</em></strong>. Give the file a name and click <strong>Save</strong>. After that <strong><em>run,</em></strong> the code and you will see at the bottom of the terminal if your code ran successfully without any errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2wRlkJMcB-wIT-yo3KxZAw.png" /></figure><p>Now, that our code ran successfully head back to the AWS console and navigate to the <strong><em>DynamoDB</em></strong> dashboard and click on <strong><em>Tables</em></strong>. There you will see the Table you just created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vQBRtY3pUTIPxTg4SEOF9Q.png" /></figure><h4><strong><em>Step 4: Insert data into the table</em></strong></h4><p>We will write another code to insert items into our table. For this table, I will be adding my favorite EDM Music Festivals. To speed up the process we are going to create a script to batch write them which will allow us to add multiple items at the same time.</p><pre># Import the boto3 library<br>import boto3<br><br># Connect to the DynamoDB table<br>dynamodb = boto3.resource(&#39;dynamodb&#39;)<br>table = dynamodb.Table(&#39;EDM_Music_Festival&#39;)<br><br># Define the data to be added to the table<br>items = [<br>    {&#39;Festival Name&#39;: &#39;Rolling Loud&#39;, &#39;Location&#39;: &#39;San Bernardino, California&#39;},<br>    {&#39;Festival Name&#39;: &#39;EDC&#39;, &#39;Location&#39;: &#39;Las Vegas, Nevada&#39;},<br>    {&#39;Festival Name&#39;: &#39;Lollapalooza&#39;, &#39;Location&#39;: &#39;Grant Park, Chicago&#39;},<br>    {&#39;Festival Name&#39;: &#39;Lost Land&#39;, &#39;Location&#39;: &#39;Thornville, Ohio&#39;},<br>    {&#39;Festival Name&#39;: &#39;Electric Forest&#39;, &#39;Location&#39;: &#39;Rothbury, Michigan&#39;},<br>    {&#39;Festival Name&#39;: &#39;Okeechobee&#39;, &#39;Location&#39;: &#39;Okeechobee, Florida&#39;},<br>    {&#39;Festival Name&#39;: &#39;Audiotistic&#39;, &#39;Location&#39;: &#39;Mountain View, California&#39;},<br>    {&#39;Festival Name&#39;: &#39;Hard Summer&#39;, &#39;Location&#39;: &#39;San Bernardino, California&#39;},<br>    {&#39;Festival Name&#39;: &#39;Tomorrowland&#39;, &#39;Location&#39;: &#39;Antwerp, Belgium&#39;},<br>    {&#39;Festival Name&#39;: &#39;Coachella&#39;, &#39;Location&#39;: &#39;Indio, California&#39;},<br>]<br><br># Loop through the items and add them to the table<br>for item in items:<br>    table.put_item(Item=item)<br><br># Print a message to confirm that the items have been added<br>print(&quot;10 items have been added to the table.&quot;)</pre><p>If the code runs successfully you should see the following outcome in the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*diMCPiQE6CjytkEiFnBIGA.png" /></figure><h4>Step 5: Verify if items were added to the table</h4><p>Navigate back to the <strong><em>DynamoDB</em></strong> dashboard and click on <strong><em>Tables </em></strong>and<strong><em> Explore items</em></strong>. There you will see all the items that were added to the Table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*010xKS-PEsBXVzEgSa67IQ.png" /></figure><h4>Step 6: Scan the DynamoDB Table</h4><p>Use the following code to scan the table.</p><pre>import boto3<br><br>dynamodb = boto3.resource(&#39;dynamodb&#39;)<br>table = dynamodb.Table(&#39;EDM_Music_Festival&#39;)<br><br>response = table.scan()<br><br>for item in response[&#39;Items&#39;]:<br>    print(item)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0yfPF6R1h_ONAkRUIn7nNA.png" /></figure><h4>Step 7: Query the DynamoDB Table</h4><p>Use the following code to Query the table.</p><pre>import boto3<br>from boto3.dynamodb.conditions import Key<br>dynamodb = boto3.resource(&#39;dynamodb&#39;, region_name = &#39;us-west-1&#39;)<br>table = dynamodb.Table(&#39;EDM_Music_Festival&#39;)<br><br>response = table.query(<br>    KeyConditionExpression = Key(&#39;Festival Name&#39;).eq(&#39;EDC&#39;)<br>)<br>print(response[&#39;Items&#39;])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ge_hNPiFFhchLaebEiOfuQ.png" /></figure><h4>Step 8: Remove an Item from the Table</h4><p>Use the following code to remove an item from the Table.</p><pre>import boto3<br><br>dynamodb = boto3.resource(&#39;dynamodb&#39;)<br><br>table = dynamodb.Table(&#39;EDM_Music_Festival&#39;)<br><br>response = table.delete_item(Key = {&#39;Festival Name&#39;: &#39;Sickick&#39;, &#39;Location&#39;: &#39;San Jose&#39;})<br><br>print(response)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v2iEI74753jy3LIcNNErlQ.png" /></figure><h4>Step 9: Verify that the item was deleted</h4><p>Navigate back to the <strong><em>DynamoDB</em></strong> dashboard and click on <strong><em>Tables </em></strong>and<strong><em> Explore items</em></strong>. You should see that one of the items was successfully removed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mSWKb0VE6yI89zip_szIOg.png" /></figure><h4>Step 10: Delete the Entire Table</h4><p>Remove the following code to Delete the entire Table.</p><pre>import boto3<br><br>dynamodb = boto3.resource(&#39;dynamodb&#39;)<br>table = dynamodb.Table(&#39;EDM_Music_Festival&#39;)<br><br>table.delete()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4o3qydakEuFERE2E38CRlQ.png" /></figure><p>As you can see, the table was successfully deleted.</p><p>Thank you for reading my post!</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Interested in scaling your software startup</em></strong><em>? Check out </em><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9867d7096c3" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/create-a-dynamodb-table-with-boto3-in-aws-ide-using-python-f9867d7096c3">Create a DynamoDB Table with Boto3 in AWS IDE using Python</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building and implementing a 3-Tier Architecture with AWS]]></title>
            <link>https://faun.pub/building-and-implementing-a-3-tier-architecture-with-aws-29a7a69c0ac?source=rss-5618d3eb17c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/29a7a69c0ac</guid>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[3-tier-architecture]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <dc:creator><![CDATA[Hasan Cheema]]></dc:creator>
            <pubDate>Fri, 10 Feb 2023 13:02:23 GMT</pubDate>
            <atom:updated>2023-02-10T13:02:23.770Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r0vHLSvcpLBcNhwmeMXefA.png" /></figure><h4>Overview:</h4><h4>Benefits of 3-tier architecture:</h4><blockquote>1. <strong>Faster development</strong>: Because each tier can be developed simultaneously by different teams, an organization can bring the application to market faster, and programmers can use the latest and best languages and tools for each tier.</blockquote><blockquote>2<strong>. Improved scalability</strong>: Any tier can be scaled independently of the others as needed.</blockquote><blockquote>3<strong>. Improved reliability</strong>: An outage in one tier is less likely to impact the availability or performance of the other tiers.</blockquote><blockquote>4<strong>. Improved security</strong>: Because the presentation and data tiers can’t communicate directly, a well-designed application tier can function as an internal firewall, preventing SQL injections and other malicious exploits.</blockquote><h4>Scenario:</h4><p>You have been asked to design and create a highly available, 3-Tier Architecture for your company’s new Web Application. We will build our Web Application based on the 3-tier diagram below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*qQfi8pWbVSkCt95-goDeJw.png" /></figure><h4>Objectives:</h4><h4>Web Tier:</h4><blockquote>1. Create two public subnets.<br>2. Minimum of 2 EC2 instances with an OS of your choice (free tier) in an Auto Scaling Group.<br>3. EC2 Web Server Security Group allows inbound permission from the internet.<br>4. Bootstrap a static web page or create a custom AMI that already includes the static web page.<br>5. Create a public route table and associate the 2 public subnets.</blockquote><h4>Application Tier:</h4><blockquote>1. Create two private subnets.<br>2. Minimum of 2 EC2 instances with an OS of your choice (free tier) in an Auto Scaling Group.<br>3. EC2 Application Server Security Group allows inbound permission from the Web Server Security Group.<br>4. Associate with a private route table.<br>Note: This is not a true application tier, as we don’t have any provided code to run on the EC2 instances.</blockquote><h4>Database Tier:</h4><blockquote>1. Use a free Tier MySql RDS Database.<br>2. The Database Security Group should allow inbound traffic for MySQL from the Application Server Security Group.<br>3. Create 2 private subnets.<br>4. Associate with a private route table.<br>Note: No need to use Multi-AZ but be sure to document how you would add it.</blockquote><h4>Preconditions:</h4><blockquote>1. You will need an AWS Account.<br>2. An IAM user with admin-level privileges.</blockquote><p>The best way to approach this project is to break down the objectives into sections and go from there.</p><ul><li><strong>VPC: </strong>(Subnets, Internet Gateway, Route Tables, NAT Gateway, etc)</li><li><strong>Web Tier:</strong> (EC2 Instances, Auto Scaling Group, Security Group, Key Pair, BootStrap Static Web Page, Public Route Table association)</li><li><strong>Application Tier</strong>: (EC2 Instances, Auto Scaling Group, Security Group, Key Pair, Private Route Table association)</li><li><strong>Database Tier:</strong> (MySQL RDS Database, Security Group, Key Pair, Private Route Table association)</li><li><strong>Bastion Host:</strong> (To access our Private Instances)</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5zf2M4HgjjWszLd4a5%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F5zf2M4HgjjWszLd4a5%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExODhsMmNqYnZpYnNocjd3MTFkd2k2Mm96dzEwbTg2OGdwcGplMzQ1bSZlcD12MV9naWZzX2dpZklkJmN0PWc%2F5zf2M4HgjjWszLd4a5%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="181" frameborder="0" scrolling="no"><a href="https://medium.com/media/ceb4fd2380af661521a6e88c61bea3a3/href">https://medium.com/media/ceb4fd2380af661521a6e88c61bea3a3/href</a></iframe><h4>Create your VPC</h4><p>Before we begin to configure our Web Tier and launch an EC2 Instance, we need to do some configurations to our Network within AWS. Here we will create our VPC which will consist of six subnets (two public and four private) we will also create our Subnets, Internet Gateway, and Route Tables.</p><p>Now let’s begin by logging into the <strong><em>AWS Dashboard</em></strong>, here we can either choose <strong><em>Services</em></strong> and navigate to <strong><em>VPC</em></strong> or simply type “<strong><em>VPC</em></strong>” into the search field to get there faster and click on <strong><em>Create VPC</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v70rGJ07fY12trn81KZusQ.png" /></figure><p>Once you navigate to the <strong><em>VPC Dashboard</em></strong>, select the <strong><em>VPC and more </em></strong>options<strong><em>. </em></strong><em>W</em>here we will do the following configurations.</p><ol><li><em>Give your VPC a name:</em></li><li><em>Determine the IPv4 CIDR 10.0.0.0/16</em></li><li><em>Select the number of Availability Zones</em></li><li><em>Select the number of Public subnets</em></li><li><em>Select NAT Gateways</em></li><li><em>Select VPC endpoints</em></li><li><em>Select Create VPC</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*yCZyo4cU_gt8J89nmScTdQ.jpeg" /></figure><p>Once you are done with the configurations click on Create VPC, after that the VPC workflow will take a few minutes to create and it will look something like the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9xR64fO13AD9dXZi4cNCNw.jpeg" /></figure><p>After we have finished our workflow, we must check that our environment includes all of the items we require to continue. Verify that there is a total of <strong><em>six</em></strong> Subnets<strong><em> Two Public and Four Private</em></strong>.</p><p>After that, we must enable our <strong><em>Public Subnets</em></strong> to get automatically assigned IP addresses. To do that navigate to the Subnets tab under the VPC Dashboard and check the box next to the Public Subnets you just created.</p><p>In the upper right corner, click on <strong><em>Actions</em></strong> and <strong><em>then Edit Subnet Settings</em></strong>. From there, check the box <strong><em>Enable auto-assign public IPv4 address</em></strong> under the auto-assign IP settings. Make sure you do this for both of your Public Subnets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gbGGEVtuQM92pvHYAj1N7g.jpeg" /></figure><p>Great! Now that we have a good base for our structure. Let’s begin with building the Web Tier now.</p><h4>Web Tier</h4><p>First, we are going to configure the Web Tier part of the Architecture for that, we need to ensure that it includes the following components:</p><blockquote>EC2 Instances<br>Auto Scaling Group<br>Security Group<br>Key Pair<br>BootStrap Static Web Page<br>Public Route Table association</blockquote><h4>Create an EC2 Auto-Scaling Group</h4><p>Navigate to the EC2 dashboard, scroll down to <strong><em>Auto Scaling Group =&gt; Create Auto Scaling Group. </em></strong>Give your Auto Scaling group a name and click on<strong><em> Create a launch template.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kfrhz24NJFi1rmEqsV7goA.jpeg" /></figure><blockquote>Give the Template a name (Web-ASG)<br>Check the box for Auto Scaling Guidance <br>Choose your AMI (Amazon Linux 2) <br>Choose your Instance type (t2.micro)<br>Keypair: I created a new one, but you can use an existing one</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H_7YWNI-0lVKEWTWEWU2fw.jpeg" /></figure><p>Now, we will create a new <strong><em>Security Group</em></strong> under Network settings to allow <strong><em>HTTP</em></strong> and <strong><em>SSH</em></strong> access to our Instance in Public Subnets. Click on <strong><em>Add security groups rules</em></strong> to configure the rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i7fnanEQqnmAhHKbbn8AVA.jpeg" /></figure><p>Leave the rest of the settings as default and scroll down to <strong><em>Advanced Details</em></strong> here we will include a bootstrap in the <strong><em>User Data</em></strong> textbox. The bootstrap will deploy an <strong><em>Apache Webserver </em></strong>on our instances and create a scrip-based webpage. Once you are done click on <strong><em>Create Launch Template</em></strong>.</p><p>See the bootstrap example below.</p><pre>#!/bin/bash<br>yum update -y<br>yum install httpd -y<br>systemctl start httpd<br>systemctl enable httpd<br><br>echo &#39;&lt;!DOCTYPE html&gt;&#39; &gt; /var/www/html/index.html<br>echo &#39;&lt;html lang=&quot;en&quot;&gt;&#39; &gt;&gt; /var/www/html/index.html<br>echo &#39;&lt;body style=&quot;background-color:Black;&quot;&gt;&#39; &gt;&gt; /var/www/html/index.html<br>echo &#39;  &lt;h1 style=&quot;color:White;&quot;&gt; Hello, Black Team! Welcome to my Web Tier of a 3-Tier Architecture-&lt;/h1&gt;&#39; &gt;&gt; /var/www/html/index.html<br>echo &#39;&lt;/body&gt;&#39; &gt;&gt; /var/www/html/index.html<br>echo &#39;&lt;/html&gt;&#39; &gt;&gt; /var/www/html/index.html</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gFDqS5z5xK4_4rQFyxcyEw.jpeg" /></figure><p>I would like to emphasize that you are now creating an ASG using your newly created launch template. After the Launch Template has been successfully created head back to the <strong><em>Auto-Scaling Group</em></strong> window and select the <strong><em>Template</em></strong> we just created and click <strong><em>Next</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1l5MT8U1hDqBxOcTALRVhQ.jpeg" /></figure><p>Under the <strong><em>Network</em></strong> section, select your <strong><em>VPC</em></strong> and select the <strong><em>two Public Subnets</em></strong> you created earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VT7BXRtUmS20ZxQFrbmfwg.png" /></figure><p>Now, in order to boost availability, we will need to set up a load balancer to distribute incoming Web Tier Traffic across our EC2 Instances. To do that select <strong><em>Attached to a new load balancer</em></strong> and then select <strong><em>Application Load Balancer </em></strong>followed by<strong><em> Internet-facing.</em></strong></p><p>Next, make sure to select your <strong><em>VPC</em></strong> and both of the <strong><em>Public Subnets</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YWtrC4GJkeC0kbEoF29YCw.jpeg" /></figure><p>For the <strong><em>Listeners and Routing </em></strong>section select <strong><em>Create a target group</em></strong> which will create an instance target group with default settings. Next, under the <strong><em>Additional settings,</em></strong> section select <strong><em>Enable group metrics collection within CloudWatch </em></strong>and click<strong><em> Next.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*V5It_GosnFrOckwDz5FaNA.png" /></figure><p>After you click next you will be taken to the <strong><em>Configure group size and scaling policies page</em></strong>. From there under <strong><em>Group size </em></strong>select your D<strong><em>esired, Minimum, </em></strong>and<strong><em> Maximum </em></strong>capacity<strong><em>. </em></strong>For the <strong><em>Scaling policies</em></strong> section select <strong><em>Target tracking scaling policy</em></strong> and leave the rest of the settings as default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*brQ7d3Ik5WiQ6UWbMMJaHw.jpeg" /></figure><p>Click on the <strong><em>Skip to review button</em></strong> to move to the last step and scroll all the way down and click on <strong><em>Create Autoscaling group</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*B-1y_sZYHdfj_l4J0_kWPg.png" /></figure><p>Wait for a few seconds for your two Instances to configure. Then head back to the EC2 Dashboard and you should see two new Instances running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xq56P33_AiEg8Z6OeTdVmA.png" /></figure><p>Awesome! Now for the ultimate test: To verify that the Instance is up and running, for that copy one of the IPv4 address and paste it into your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*7GWum5WSCVnSrUR_Wg1Ykw.jpeg" /></figure><p>Awesome! We have successfully created the Web Tier. Now, let’s move on to creating the Application Tier.</p><h4>Create a Bastion Host</h4><p><strong><em>What is a Bastion Host?</em></strong></p><p>A bastion host is a dedicated server that lets authorized users access a private network from an external network such as the internet.</p><p>So before we move on to the Application Tier, we need to create a bastion host first because the bastion host needs to be set up with a security group that allows SSH access from our IP. Then, we’ll use this security group to create a rule for SSH access in the application tier.</p><p>To create a Bastion Host head over to your <strong><em>EC2 Instance Dashboard</em></strong> and click on <strong><em>Launch Instance</em></strong>.</p><blockquote>Name your Instance <br>Choose your AMI (Amazon Linux 2) <br>Choose your Instance type (t2.micro)<br>Keypair: You can created a new one, but I will use an existing one</blockquote><p>Next under the <strong><em>Network Settings</em></strong> section</p><blockquote>Select the VPC that we created earlier <br>Select a Public Subnet <br>Enable Auto-assign public IP<br>Select Create security group <br>Give your Security group a name<br>Select ssh for Type<br>Select My IP for source type <br>Click on Launch Instance</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g9y0tp_xZzI3HNKeYagoJw.jpeg" /></figure><h4>Application Tier</h4><p>Now we will configure the Application Tier. In this part, we will place the EC2 Instance into the two Private Subnets using an Auto scaling group as we did in the Web Tier. Please keep in mind that this is not a real Application Tier since we don’t have a code to run on the EC2 Instance.</p><p>We need to ensure that it includes the following components:</p><blockquote>EC2 Instances<br>Auto Scaling Group<br>Security Group<br>Key Pair<br>Private Route Table association</blockquote><h4>Create an EC2 Auto-Scaling Group</h4><p>Navigate to the EC2 dashboard, scroll down to <strong><em>Auto Scaling Group =&gt; Create Auto Scaling Group. </em></strong>Give your Auto Scaling group a name and click on<strong><em> Create a launch template.</em></strong></p><blockquote>Give the Template a name (App-template)<br>Check the box for Auto Scaling Guidance <br>Choose your AMI (Amazon Linux 2)<br>Choose your Instance type (t2.micro)<br>Keypair: I created a new one, but you can use an existing one</blockquote><p>Because these are Private Subnets, we will only allow access through our Web Tier security group and SSH, as indicated below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35WwBKhawncKqzcDjsCbbQ.jpeg" /></figure><p>Leave the rest of the settings as default and click on <strong><em>Create launch Template</em></strong>. After the Launch Template has been successfully created head back to the <strong><em>Auto-Scaling Group</em></strong> window and select the <strong><em>Template</em></strong> we just created and click <strong><em>Next</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*FO3nXo-EAc6EYE-Dd50t3Q.png" /></figure><p>Under the <strong><em>Network</em></strong> section select the <strong><em>VPC</em></strong> we created earlier and two <strong><em>Private Subnets,</em></strong> then click <strong><em>Next</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*DnDCHWGOkyZPK4N4fu34_w.png" /></figure><p>Continue to configure your Auto Scaling group using the same configurations as we did for the Web Tier ASG. After reviewing the configurations, click <strong><em>Create Auto Scaling group</em></strong>. Once done head back to the EC2 Instance Dashboard and you will see two new <strong><em>Instances Created.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aB2wIpgEzVIPqm65vPI8jA.jpeg" /></figure><h4>Database Tier</h4><p>Now we will configure the Database Tier. In this part, we will add a database to the Private Subnet for our third and final Tier.</p><p>We need to ensure that it includes the following components:</p><blockquote>MySQL RDS Database<br>Security Group<br>Key Pair<br>Private Route Table association</blockquote><p>In the AWS Dashboard, you can either choose Services and navigate to <strong><em>RDS</em></strong> or simply type <strong><em>RDS</em></strong> into the search field to get there faster. From there, click on <strong><em>Subnet Groups</em></strong> and <strong><em>Create Subnet group</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tz3nhSfC7ayOBAWMFs7mRA.png" /></figure><p>Here we will create a new Subnet Group with the following configurations.</p><blockquote>Give the subnet group a name<br>Give it a description<br>Choose the VPC<br>Choose the availability zones</blockquote><p>By selecting both Availability zones, we will create a Multi-AZ DB Instance to give higher availability and data redundancy. Make sure to select Private Subnets that you have not previously utilized and do not include any EC2 Instances. Then click on <strong><em>Create</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ufWT31c0ccv9WtAxrFBLg.jpeg" /></figure><p>Next, we want to create a <strong><em>MySQL Database</em></strong>. Navigate back to the RDS dashboard and click <strong><em>Create Database </em></strong>then select <strong><em>Standard create </em></strong>and <strong><em>MySQL</em></strong>.</p><p>This will be a standard <strong><em>MySQL Database </em></strong>creation, as indicated below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*myX93oxrzXspjTsLRyYr0g.png" /></figure><p>For the Template, we will select <strong><em>Free Tier</em></strong>. Keep the <strong><em>Settings</em></strong> section as default but don’t forget to add a <strong><em>master password</em></strong> for your <strong><em>admin</em></strong>. Save the password somewhere safe, as we will need it later. Keep the <strong><em>Instance configuration</em></strong> and <strong><em>Storage</em></strong> as default. Under <strong><em>Connectivity,</em></strong> select your VPC and the subnet group we created earlier. For <strong><em>Public Access,</em></strong> select “No” since this is a Private Database and will only be accessible from inside the VPC. Then click to create a <strong><em>Security Group.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-xQ6MXY_MTdV7xJdV5jQQA.jpeg" /></figure><p>Lastly, click on <strong><em>Create Database</em></strong>. It will take a couple of minutes for the database to be created. Click on it and scroll to <strong><em>Connectivity and Security</em></strong>. We need to edit our security group to allow inbound access. To do this, click on the D<strong><em>atabase Security Group</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WwuxW6PO3fj4JXFIcGjxSw.png" /></figure><p>From there, we will edit the Security group inbound rules by navigating to the inbound rule tab and clicking on <strong><em>edit inbound rules</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B_5wwDWj8QxTLI-mhXNNVw.jpeg" /></figure><p>We have successfully created the Database Tier.</p><h4>Verifying</h4><p>We have already verified the Web Tier, now we will verify the Application Tier by using the <strong><em>Ping</em></strong> command. We will ping our Application Tier from the Web Tier. To do this we need to SSH into one of our Web Instances.</p><p>Before we get started we need to run the following commands to SSH into one of the Public</p><p>Instances.</p><pre>chmod 400 aws-keypair.pem<br><br>ssh -i &quot;aws-keypair.pem&quot; ec2-user@ipaddress</pre><p>Now we will SSH into one of the Web Tier Instances and from there we will check the status between the Web Tier and the Application Tier using the ping command.</p><pre>ping Private_IP_Address </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1wWxq8i3DW_UGwv8oAiuXw.png" /></figure><p>Awesome! We have finished all our objectives successfully.</p><p><strong>When you are finished using the instructions in this tutorial, don’t forget to delete all resources that you created and configured. There is a minor fee for NAT Gateways, Elastic IPs, and ALBs. So make sure to remove them if you followed these instructions.</strong></p><p>Thank you for reading my post!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*scVzV-Ky6qcl9iHK.png" /></figure><h4>👋 If you find this helpful, please click the clap 👏 button below a few times to show your support for the author 👇</h4><h4>🚀<a href="http://from.faun.to/r/8zxxd">Join FAUN Developer Community &amp; Get Similar Stories in your Inbox Each Week</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29a7a69c0ac" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/building-and-implementing-a-3-tier-architecture-with-aws-29a7a69c0ac">Building and implementing a 3-Tier Architecture with AWS</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>