<?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 Revathijoshi on Medium]]></title>
        <description><![CDATA[Stories by Revathijoshi on Medium]]></description>
        <link>https://medium.com/@revathijoshi70?source=rss-5a084796b90f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XAwsiN1aoMXOrLwEES1VMw.jpeg</url>
            <title>Stories by Revathijoshi on Medium</title>
            <link>https://medium.com/@revathijoshi70?source=rss-5a084796b90f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 09:21:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@revathijoshi70/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[Create an inventory of AWS Services using Python]]></title>
            <link>https://towardsaws.com/create-an-inventory-of-aws-services-using-python-e5c28c4e5e9?source=rss-5a084796b90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5c28c4e5e9</guid>
            <dc:creator><![CDATA[Revathijoshi]]></dc:creator>
            <pubDate>Thu, 29 Sep 2022 13:11:10 GMT</pubDate>
            <atom:updated>2022-09-30T13:52:50.851Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A1UYP2Om5UbueAE_07sfMg.png" /></figure><p>Welcome to my Python project!</p><p>I am learning Python and adding this to my learning experience in AWS! Writing a simple Python program, a combination of Python lists by name/index and functions like print, append, insert, and remove the variables.</p><h3>Objectives</h3><ul><li>Create a list of AWS services using Python script — <strong>project_14.py</strong></li><li>The list should be empty initially.</li><li>Populate the list using append and/or insert.</li><li>Print the list and the length of the list.</li><li>Remove two specific services from the list by name or by index.</li><li>Print the new list and the new length of the list.</li></ul><h3>Pre-requisites</h3><ul><li><strong>AWS user</strong> account with admin access, not a root account.</li><li><strong>Cloud9 IDE</strong> comes with Python installed.</li></ul><h3>Resources Used:</h3><p><a href="https://learn.acloud.guru/course/33a5a87a-2b2c-4e51-b00f-8f2e2a15ab30/dashboard"><strong>Certified Entry-Level Python Programmer Certification by ACloudGuru</strong></a></p><p>I have also found these sites to be very helpful in understanding the basics of Python.</p><p>For number conversion tools to convert binary, decimal, hexadecimal and octal numbers to each other, used <a href="https://www.binaryhexconverter.com/"><strong>binaryhexconverter</strong></a><strong>.</strong></p><p>For Python Tutorials on Bitwise Operators (AND | OR | XOR | Complement/NOT | Left Shift | Right Shift), used YouTube Videos of <a href="https://www.youtube.com/c/AmulsAcademy"><strong>Amulya’s Academy</strong></a><strong>.</strong></p><p><strong><em>Let’s get started!</em></strong></p><p>You can find the complete code on my <a href="https://github.com/awsmine/Python_LUIT/blob/main/project_14.py"><strong>GitHub Repository</strong></a>.</p><p>I have used Cloud9 as IDE to write, run, and debug the Python code with just a browser. While working on this project, I stored the files generated in my Cloud9 IDE to GitHub repository outside of this EC2 VM, so that I would not loose my code if anything happens to this VM on AWS.</p><h3>Steps of Implementing the Objectives</h3><h4>Create a list of AWS services using Python script — project_14.py</h4><p>The list should be empty initially.</p><pre><strong>#!/usr/bin/env python3.7<br># create a variable to hold a place in memory for the list of AWS services<br>aws_services = []</strong></pre><h4><strong>Populate the list using append and/or insert.</strong></h4><ol><li>Using an <strong>‘append’</strong> method, I have used the following AWS services to create a list for demonstration purposes.</li></ol><ul><li>AWS Batch</li><li>Amazon CloudWatch</li><li>Amazon DynamoDB</li><li>Amazon Elastic Compute Cloud (EC2)</li><li>AWS Lambda</li><li>Amazon Simple Storage Service (S3)</li></ul><pre><strong># using &#39;append&#39; method, add an object to the list<br>aws_services.append(&#39;Batch&#39;)<br>aws_services.append(&#39;CloudWatch&#39;)<br>aws_services.append(&#39;DynamoDB&#39;)<br>aws_services.append(&#39;EC2&#39;)<br>aws_services.append(&#39;Lambda&#39;)<br>aws_services.append(&#39;S3&#39;)</strong></pre><p>2. Using an <strong>‘insert’ </strong>method, I have used the following AWS services to create a list <strong>by index</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_h9zV5ceYixeruxCrhbK7g.png" /></figure><pre><strong># using &#39;insert&#39; method, add an object to the list by index<br>aws_services.insert(0, &#39;Athena&#39;)<br>aws_services.insert(1, &#39;Aurora&#39;)<br>aws_services.insert(5, &#39;FSx&#39;)</strong></pre><h4><strong>Print the list and the length of the list.</strong></h4><pre><strong># print the list and the length of the list<br>length = len(aws_services)<br>print(&quot;This is the list of AWS services:&quot;, aws_services, &quot; and the length of the list is: &quot;, length)</strong></pre><h4>Remove two specific services from the list by name and/or by index.</h4><pre><strong># remove 2 services from the list by name<br>aws_services.remove(&#39;Athena&#39;)<br>aws_services.remove(&#39;S3&#39;) </strong></pre><pre><strong># remove 2 services from the list by index<br>del aws_services[3]<br>del aws_services[4]</strong></pre><h4><strong>Print the new list and the new length of the list.</strong></h4><pre><strong># create variables to hold a place in memory for the list and new length of AWS services<br>new_list = list(aws_services)<br>new_length = len(new_list) </strong></pre><pre><strong># print the new list and new length of the list<br>print(&quot;This is the new list of AWS services: &quot;, new_list, &quot; and new length of the list: &quot;, new_length)</strong></pre><h3>What we have done so far</h3><p>Created a python script for a list of AWS Services by first populating it by append/insert methods, printing the list and the length of the list, removing specific services by name/index, and lastly printing the new list and the length of the new list.</p><p>It was fun working with Python and doing this project. I will post more articles as I learn to code my projects with Python.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5c28c4e5e9" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/create-an-inventory-of-aws-services-using-python-e5c28c4e5e9">Create an inventory of AWS Services using Python</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[EC2 Random name Generator using Python script]]></title>
            <link>https://towardsaws.com/ec2-random-name-generator-using-python-script-eb7caf25093c?source=rss-5a084796b90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb7caf25093c</guid>
            <dc:creator><![CDATA[Revathijoshi]]></dc:creator>
            <pubDate>Wed, 28 Sep 2022 14:05:21 GMT</pubDate>
            <atom:updated>2022-09-28T14:48:46.632Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G_vm1FGxSwgivmCZTHJHnA.png" /></figure><p>Happy to show you all my latest project in python.</p><p>**<strong><em>EC2 Random Name Generato</em></strong>r**</p><p>This python project is about generating a unique name for the “x” number of EC2 instances for a department and generating random characters and numbers that will be included in the unique name. This is especially important when in an organization, there are so many users, departments sharing an AWS environment. This ensures that they are properly named and are unique so any team member can easily tell to which department he/she belongs to.</p><p>The <strong><em>ONLY</em></strong> departments that should use this Name Generator are Marketing, Accounting and FinOps. The user then lists these departments as options and if a user puts another department, the program will print a message that they should not use this Name Generator and the program should exit. Also it checks whether an input has an incorrect upper or lowercase letters for the corresponding department.</p><p>This program also checks for any negative number input for the number of EC2 Instances that they need or no input at all.</p><p>Used a combination of the Python code — a random function, generator, range functions, loops with break statement, strings, variables and inputs.</p><p>Used a variety of courses to learn python. and most of all Practice… without which I could not have completed this project.</p><p>Practiced a lot, whether to use exit() or a sys.exit() function for the wrong user input. For exit() is considered bad to use in production code because it relies on site module and sys.exit() is good to use in production code because the sys module will always be there.</p><h3>Objectives:</h3><p>Several departments share an AWS environment. You need to ensure that the EC2 instances are properly named and are unique so team members can easily tell who the EC2 instances belong to.</p><p>Use Python to create your unique EC2 names that the users can then attach to the instances.</p><p>The Python Script should:</p><ul><li>Generate random characters and numbers that will be included in the unique name.</li><li>Allow the user to input the name of their department that is used in the unique name.</li><li>The only departments that should use this Name Generator are the Marketing, Accounting, and FinOps Departments.</li><li>List these departments as options and if a user puts another department, print a message that they should not use this Name Generator.</li><li>Be sure to account for incorrect upper or lowercase letters in the correct department. <br>Example: a user inputs accounting vs Accounting.</li><li>All the users input how many EC2 instances they want names for and output the same amount of unique names.</li><li>The number should be a positive number.</li><li>Prints the randomly generated unique EC2 names</li></ul><h3>Pre-requisites</h3><ul><li><strong>AWS user</strong> account with admin access, not a root account.</li><li><strong>Cloud9 IDE</strong> comes with Python installed.</li></ul><h3>Resources Used:</h3><p><a href="https://learn.acloud.guru/course/33a5a87a-2b2c-4e51-b00f-8f2e2a15ab30/dashboard"><strong>Certified Entry-Level Python Programmer Certification by ACloudGuru</strong></a></p><p>I have also found these sites to be very helpful in understanding the basics of Python.</p><p><a href="https://docs.python.org/3/library/random.html"><strong>Random python library</strong></a></p><p><a href="https://docs.python.org/3/library/random.html#functions-for-integers"><strong>Random python library for functions for integers</strong></a></p><p><a href="https://docs.python.org/3/library/random.html#functions-for-sequences"><strong>Random python library for functions for sequences</strong></a></p><p><strong>Dr. Angela Yu — </strong><a href="https://www.udemy.com/course/100-days-of-code/"><strong>100 Days of Code: # The Complete Python Pro Bootcamp for 2022 from Udemy</strong></a></p><p><a href="https://www.w3schools.com/python/module_random.asp#"><strong>www.w3schools.com</strong></a></p><p><a href="https://www.geeksforgeeks.org/python-programming-language/?ref=ghm#"><strong>www.geeksforgeeks.org</strong></a></p><p><a href="https://www.hackerrank.com/domains/python"><strong>www.hackerrank.com</strong></a></p><p><strong><em>Let’s get started!</em></strong></p><p>Here is a link of my python project in <a href="https://github.com/awsmine/Python_projects/blob/main/random_name_generator.py"><strong>GitHub Repository</strong></a>.</p><p>I have used Cloud9 as IDE to write, run, and debug the Python code with just a browser. While working on this project, I stored the files generated in my Cloud9 IDE to GitHub repository outside of this EC2 VM, so that I would not loose my code if anything happens to this VM on AWS.</p><h3>Steps of Implementing the Objectives</h3><h3><strong><em>random_name_generator.py — </em></strong>Generate random characters and numbers that will be included in the unique name.</h3><pre><strong>import random<br>import string<br>import sys </strong></pre><pre><strong># variables</strong></pre><pre><strong>def string_generator(size=6, string=string.ascii_letters + string.digits):    <br>    return &#39;&#39;.join(random.choice(string) for _ in range(size))</strong></pre><h4>Allow the user to input the name of their department that is used in the unique name.</h4><h4>The only departments that should use this Name Generator are the Marketing, Accounting, and FinOps Departments.</h4><h4>List these departments as options and if a user puts another department, print a message that they should not use this Name Generator.</h4><h4>Be sure to account for incorrect upper or lowercase letters in the correct department. <br>Example: a user inputs accounting vs Accounting.</h4><p><strong><em># exit() is considered bad to use in production code because it relies on site module.</em></strong></p><p><strong><em># sys.exit() good to use in production code because the sys module will always be there.</em></strong></p><p><strong><em># </em></strong><a href="https://pythonguides.com/python-exit-command/#"><strong><em>https://pythonguides.com/python-exit-command/</em></strong></a></p><p><a href="https://pythonguides.com/python-exit-command/#"><strong><em>#</em></strong></a><strong><em> </em></strong><a href="https://stackoverflow.com/questions/16656313/exit-while-loop-in-python"><strong><em>https://stackoverflow.com/questions/16656313/exit-while-loop-in-python</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R7FHPTUsxKP309h3WmE_9g.png" /></figure><h4>All the users input how many EC2 instances they want names for and output the same amount of unique names.</h4><h4>The number should be a positive number.</h4><pre><strong># number    - how many EC2 instances they want names for</strong></pre><pre><strong>number = int(input(&quot;Enter the number of EC2 instances you need: &quot;)) <br>     <br>if number &lt; 0:    <br>    print(&quot;Please enter a positive number: &quot;) <br>elif number &gt; 0:    <br>    print(&quot;Good to go&quot;)</strong></pre><h4>Prints the randomly generated unique EC2 names</h4><pre><strong>print()<br>print(&quot;--------------------------------&quot;)<br>print(&quot;EC2 Instance Names&quot;)<br>print(&quot;--------------------------------&quot;)<br>print() </strong></pre><pre><strong>for _ in range(1, number + 1):    <br>    unique_name = department    <br>    EC2_unique_name = unique_name + &quot;-&quot; + string_generator()<br>    print(&quot;Your EC2 Instance&#39;s unique name is : &quot;, EC2_unique_name)</strong></pre><h3>What we have done so far</h3><p>Created a python script to generate EC2 names with unique numbers so that the team members can easily tell who the EC2 instances belong to.</p><p>Overall, it is a FUN project!!! Fun working with Python!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb7caf25093c" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/ec2-random-name-generator-using-python-script-eb7caf25093c">EC2 Random name Generator using Python script</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[Deploying a Two-Tier Architecture in AWS Using Terraform Modules in Terraform Cloud]]></title>
            <link>https://aws.plainenglish.io/deploying-a-two-tier-architecture-in-aws-using-terraform-modules-in-terraform-cloud-44834b128042?source=rss-5a084796b90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/44834b128042</guid>
            <dc:creator><![CDATA[Revathijoshi]]></dc:creator>
            <pubDate>Sun, 04 Sep 2022 04:33:41 GMT</pubDate>
            <atom:updated>2022-09-08T09:18:26.080Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BPsj2rwQnWsWHmsl54RMCA.png" /></figure><p>This is the same continuation of my previous article on <a href="https://medium.com/@revathijoshi70/deploying-a-two-tier-architecture-in-aws-using-terraform-modules-c4cebdecfcde"><strong>Deploying a two-tier architecture in AWS using Terraform Modules</strong></a>, but in <strong><em>Terraform Cloud.</em></strong></p><p>Objectives are the same which are given below:</p><h3>Objectives:</h3><ol><li>Create a highly available two-tier AWS architecture containing the following:</li></ol><ul><li>3 Public Subnets</li><li>3 Private Subnets</li><li>Auto Scaling Group for Bastion Host and Web Server</li><li>Internet-facing Application Load Balancer for Web Server</li></ul><p>2. Use module blocks for ease of use and re-usability.</p><p>In this article, I am going to show only on how to deploy the same infra-structure in <strong>Terraform Cloud</strong>.</p><p>Used <a href="https://www.terraform.io/cloud-docs"><strong><em>Terraform Cloud Documentation</em></strong></a>.</p><p>What you will need in addition is a Terraform Cloud Account.</p><h3>What is Terraform Cloud?</h3><p><a href="https://www.terraform.io/intro">Terraform</a> is an infrastructure as code tool that lets you define and manage infrastructure resources through configuration files. It uses modules for readability and re-usability. It securely stores state and secret data, and can connect to version control systems so that you can develop your infrastructure. It helps you to collaborate with your teams in your organization so that all can review at the same time you plan a new change, and approve the plan before you apply it.</p><p>Click on <a href="https://github.com/awsmine/2_tier_architecture_modules_terraform_cloud.git"><strong>my repository link</strong></a> below to clone it into Cloud9 IDE.</p><p><a href="https://learn.hashicorp.com/tutorials/terraform/cloud-sign-up"><strong>Create a Terraform Cloud account</strong></a></p><ul><li>Sign into <a href="https://cloud.hashicorp.com/products/terraform"><strong>Terraform Cloud</strong></a></li><li>In your Terraform Cloud dashboard, navigate to <strong><em>Settings</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KSpZ9KvNJkKbkDO2bOok9A.png" /></figure><ul><li>On the left hand, scroll down to <strong><em>Providers</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jIgfZa8jetKTN718ySb6Gg.png" /></figure><ul><li>Click <strong><em>Add a VCS provider </em></strong>at the top right of screen</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LpLIbpaLXWUMj7Rwjv17BA.png" /></figure><ul><li>Click <strong><em>GitHub</em></strong> and select <strong><em>GitHub.com (Custom)</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RLPbEPkYegkPgT0FL_2h7Q.png" /></figure><ul><li>After making sure you are signed into your GitHub account, in the Terraform Cloud web page, click on the link <strong><em>register a new OAuth Application.</em></strong></li><li>Use the information given to fill out the fields in your GitHub account.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UYWfJnwhBDCarh_2m45_Ag.png" /></figure><ul><li><strong><em>Register application</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9HadOyB5pf2qFjipg82etw.png" /></figure><ul><li>Finish <strong><em>without creating a SSH key pair.</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hkgf7Cbili0OPQZR9qo1Eg.png" /></figure><ul><li>In Terraform Cloud dashboard, click to create a <strong><em>New Workspace</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*avnZl8a1qrUysTd9PxvZWQ.png" /></figure><ul><li>Click <strong><em>Version control workflow</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uzbBEGK71GBTq_7uncdRNQ.png" /></figure><ul><li>click the <strong><em>GitHub custom</em></strong> you just created</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7CfIZ3fx71_F7qfEL0mh6Q.png" /></figure><ul><li>Select repository for this project, <strong><em>awsmine/2_tier_architecture_modules_terraform_cloud</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tm8mGgaQ5JlTOXb8NXNyug.png" /></figure><ul><li>Create a name for this workspace and select <strong><em>Create workspace</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VbEvqrJUtFsd7zCE7dYK9w.png" /></figure><ul><li>Click <strong><em>Go to workspace overview </em></strong>to add variables</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGfQNSNIcgZJ2btUg87mkg.png" /></figure><ul><li>Click <strong>Configure variables</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rcEhLbCmx6fvioU6TUacZg.png" /></figure><ul><li>Click <strong>Add variable </strong>in the<strong> Environment Variable </strong>section.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lN-5FT55NrbSPiUeuji9Xg.png" /></figure><ul><li>First add your <strong><em>1st environment variable — AWS_ACCESS_KEY_ID</em></strong> for your IAM user with admin permissions.</li><li>Ensure that you click <strong><em>Sensitive</em></strong> for these variable. This will prevent your variable value from being displayed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FcSCn6XgR3-kDcQQ57MvOg.png" /></figure><ul><li>Then add your <strong><em>2nd environment variable — AWS_SECRET_ACCESS_KEY</em></strong> for your IAM user with admin permissions.</li><li>Ensure that you click <strong><em>Sensitive</em></strong> for these variable. This will prevent your variable value from being displayed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jwxqi8VoLqVrXrKhmyoxrQ.png" /></figure><ul><li>Then add your <strong><em>3rd environment variable — </em></strong>for <strong><em>AWS_DEFAULT_REGION</em></strong> set to <strong><em>us-east-1</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vL1La1WIAwVKRpeCBRTRsg.png" /></figure><ul><li>Then add your <strong><em>4th environment variable — </em></strong>create a <strong><em>CONFIRM_DESTROY</em></strong> variable set to <strong>1</strong>. This is needed to destroy our infrastructure later.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fwivLIlc4DwJN45sZKTsGg.png" /></figure><ul><li>Instead of using a .tfvars file in the GitHub repo, we are adding our <strong>access_ip</strong> variable to the <strong>Terraform Variables</strong>. In our root <strong>main.tf</strong>, the <strong><em>access_ip</em></strong> is set up which determines the CIDR block that can SSH into our Bastion Host. Use <strong><em>0.0.0.0/0</em></strong>, but you can also use your personal IP address.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b8UOrJN4CRMtF2jiJiuzHw.png" /></figure><ul><li>See the <strong><em>list of Environment and Terraform variables added</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pD_vJmyVSz9dUHCKGn5kXA.png" /></figure><ul><li>Now click the <strong><em>Actions</em></strong> link at the top right and select <strong><em>Start new run</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LdCCCN7SqGyaAXWWJOF1Hw.png" /></figure><ul><li>Write <strong><em>test</em></strong> for Reason for starting run, Choose run type <strong><em>Plan and apply (standard)</em></strong> and click <strong><em>Start run</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bGV2G5sohTfh8q8tBZZ6rA.png" /></figure><ul><li><strong><em>Plan running</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*56v_0l7ToqrUDt67KIY8rA.png" /></figure><ul><li>Once <strong><em>Plan finished</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sNkY_ygLk-655r4txTiUkA.png" /></figure><ul><li>go all the way down , click <strong><em>Confirm &amp; apply</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QEPA0-jk_-IjySUKeFx43A.png" /></figure><ul><li>write <strong><em>test apply</em></strong> and click <strong><em>Confirm Plan</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WBCV13d08PL6vkG5SUm78w.png" /></figure><ul><li>you will see <strong><em>Apply running</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XD4fa8VuPNlEbN3J_mWm-Q.png" /></figure><ul><li><strong><em>Apply errored</em></strong></li><li><strong><em>Error</em></strong>: with the retirement of EC2-Classic no new non-VPC EIPs can be created</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7F9OuklQQegVpVM3ZEnx_g.png" /></figure><ul><li>But our infrastructure is completed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gMKUoK82Yw579xV3WW94YA.png" /></figure><h3><strong><em>VERIFY</em></strong></h3><ul><li><strong><em>DNS name</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1J_HStTbLPHspuCCBzd4MA.png" /></figure><ul><li><strong><em>Security group for Bastion host</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YK7f83mKL1BRExzFz1rgxQ.png" /></figure><ul><li>Copy the <strong><em>Public IP of the Bastion host</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u3o8nB-NmHLmw7ntSO1u2g.png" /></figure><ul><li>Using <strong>Putty</strong> and <strong>Putty Agent forwarding </strong>(use Pageant — Putty authentication agent), log into the putty session using the <strong>key name</strong> from the root main.tf (<strong>NVirKey</strong>) as your <strong>EC2 Key Pair name</strong> via <strong>SSH</strong> connection.</li><li>Test Internet connection by <strong><em>ping google.com</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZgYo_TlOj5UyIfab-L1Bcw.png" /></figure><ul><li><strong><em>Validate 1st webserver (named as database server)</em></strong></li><li><strong><em>Security group for webserver host</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O6d8mK5P7rMQsx00ClDvbA.png" /></figure><ul><li>copy the <strong><em>Private IP address of 1st webserver (database server)</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WCRMeRsGvTDbarSgLkIqXA.png" /></figure><ul><li><strong><em>SSH from the bastion host</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YGHt-UmNND5SmCJG8lKKNg.png" /></figure><ul><li>verify internet connection — <strong><em>ping google.com</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mMhTjWTpmNATBFK3laLvEw.png" /></figure><ul><li><strong><em>Validate 2nd webserver (named as database server)</em></strong></li><li><strong><em>Security group for webserver host</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kMMZO9QfVY1m6JSkbw97YA.png" /></figure><ul><li>copy the <strong><em>Private IP address of 2nd webserver (database server)</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvnlZg1BtI-KwncufmXZzQ.png" /></figure><ul><li><strong><em>SSH from the bastion host</em></strong></li><li>verify internet connection — <strong><em>ping google.com</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P2R3bqqmVYsmFzDxTk8B-g.png" /></figure><h3>Clean up</h3><ul><li>Navigate to your Workspace and click <strong>Settings/Destruction and Deletion</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*UYT92b-R1K6ETS7NfIxFaQ.png" /></figure><ul><li>First click <strong><em>Queue destroy plan </em></strong>and follow the below prompts</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJJUnllPwfJ0S9Y3no-OXg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*glrVpkc5VfZqRHCPpQWe2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lz4imKdZB__quE828kWIQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XvcXSNNvGQzX0G0pGIPNKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pyyNFwC8TnZ-dK3cThVFyQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gpbG4JUFoqvRVh_Haf30Yg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ydzIDADRS0uc0mwS9qS8Lg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BnmRMIYWwNGJGRL5-NUWgA.png" /></figure><ul><li>Now <strong><em>Delete workspace from Terraform Cloud</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ep5V7HC8aTYbL5OEzmf3Kw.png" /></figure><ul><li><strong><em>Delete workspace</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K0Ud5ERxelB5pwPXvBG3Cw.png" /></figure><ul><li><em>check to see that everything is cleaned up</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0u5XNDJqSux4UIO_Nho9Q.png" /></figure><p><strong>What we have done so far</strong></p><p><em>In </em><strong>Terraform Cloud</strong><em>, we created two Web servers placed in Private Subnets which has access to the internet through a Bastion host placed in Public Subnets with High availability and Load Balancing features.</em></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><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44834b128042" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/deploying-a-two-tier-architecture-in-aws-using-terraform-modules-in-terraform-cloud-44834b128042">Deploying a Two-Tier Architecture in AWS Using Terraform Modules in Terraform Cloud</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[Deploying a Two-Tier Architecture in AWS Using Terraform Modules]]></title>
            <link>https://aws.plainenglish.io/deploying-a-two-tier-architecture-in-aws-using-terraform-modules-c4cebdecfcde?source=rss-5a084796b90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4cebdecfcde</guid>
            <dc:creator><![CDATA[Revathijoshi]]></dc:creator>
            <pubDate>Sun, 04 Sep 2022 02:01:18 GMT</pubDate>
            <atom:updated>2022-09-08T09:19:52.321Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L52rxeKhi-OG2xWkBBNBag.png" /></figure><p>In this article, I am going to show you on how to create and deploy a two-tier architecture with <strong>highly available Web servers</strong> placed in <strong>Private Subnets</strong> which has access to the internet through <strong>Bastion host</strong> placed in <strong>Public Subnets</strong> using <strong>Terraform modules.</strong></p><h3>Objectives:</h3><ol><li>Create a highly available two-tier AWS architecture containing the following:</li></ol><ul><li>3 Public Subnets</li><li>3 Private Subnets</li><li>Auto Scaling Group for Bastion Host and Web Server</li><li>Internet-facing Application Load Balancer for Web Server</li></ul><p>2. Use module blocks for ease of use and re-usability.</p><p>In my next article, I am going to show you how to Deploy this using Terraform Cloud as a CI/CD tool.</p><h3>Pre-requisites:</h3><ul><li>AWS user account with admin access, not a root account.</li><li>Cloud9 IDE, comes with Terraform installed.</li><li><a href="https://github.com/">GitHub</a> Account</li></ul><h3><strong>Resources Used:</strong></h3><p>For this article, I used <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs"><strong>Terraform Documentation</strong></a><strong> </strong>(use the navigation to the left to read about the available resources) and <a href="https://learn.hashicorp.com/tutorials/terraform/infrastructure-as-code?in=terraform/aws-get-started"><strong>Derek Morgan’s course</strong></a></p><h3>How I will accomplish the Objectives:</h3><p><strong>Public subnets</strong> will have a</p><ul><li><strong>Bastion host</strong> for having SSH connectivity for the EC2 instances placed in Private Subnets</li><li><strong>An Auto scaling group</strong> with the desired capacity of 1 for high availability</li><li><strong>Nat Gateway</strong> for getting updates from the internet with <strong>Elastic IP address</strong>.</li></ul><p><strong>Private subnets</strong> will have</p><ul><li>EC2 Instances serving as <strong>Web servers (named as database servers</strong>), which access the internet thru Bastion host</li><li>An Internet facing <strong>Application Load Balancer</strong> which directs the traffic to our web servers (named as database servers)</li><li>An <strong>Autoscaling group</strong> with the desired capacity of 2 for high availability</li></ul><p>For my understanding on how to get this setup working correctly, I used this <a href="https://aws.amazon.com/premiumsupport/knowledge-center/public-load-balancer-private-ec2/"><strong>article</strong></a> as a reference.</p><p><em>Let’s get started!</em></p><p>In my previous article I have created a <a href="https://medium.com/@revathijoshi70/terraform-with-ec2-instances-a7e31571a058"><strong>2-tier architecture in AWS using Terraform </strong></a>consisting of all the code in ONLY one <strong>parent main.tf</strong> file.</p><p>This article uses Terraform modules for readability and re-usability.</p><p>This infrastructure has a</p><ul><li>parent <strong>main.tf</strong> file (root module)</li><li>child modules for each of the AWS components — <strong>compute</strong>, <strong>load-balancing</strong>, and <strong>networking.</strong></li><li>The root main.tf file will call these child modules to create our infrastructure.</li></ul><p>For this project, in Cloud9 environment, we will create a directory structure like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*aAeoGWAl90iUDJXhopnbuw.png" /></figure><p>You can see my complete code for this project in my <a href="https://github.com/awsmine/2_tier_architecture_Terraform_modules"><strong>GitHub Repository</strong></a>.</p><p>Copy and paste the code into the corresponding files for all the modules.</p><h4><strong>Note:</strong></h4><ul><li>Be sure to update the <strong>key_name</strong> (<strong>NVirKey</strong>) in the root main.tf as your EC2 Key Pair name, without which you cannot test the SSH connectivity to your EC2 instance.</li><li>Create a <strong>.gitignore</strong> file. As the name indicates, it will ignore all the default files created automatically when running and testing the code, like <strong>terraform.tfstate, tettaform.tfstate.backup </strong>files, while pushing your code to Github.</li><li>Create <strong>terraform.tfvars</strong> file to include variables for <strong>access_ip</strong> (your IP address) which is set in your root main.tf which determines the CIDR block that can SSH into our Bastion Host. Ensure that you include <strong>Sensitive</strong> to be <strong>true</strong> for these variables.</li></ul><p>I am not going to explain the functionality of what each <strong>.tf</strong> file does. For that, please check out my article on how to <strong>c</strong><a href="https://medium.com/towards-aws/creating-a-repeatable-infrastructure-with-a-very-basic-ec2-module-using-aws-ami-data-source-8eaff66f470f"><strong>reate a basic EC2 Terraform module.</strong></a></p><p>I have separated small snippets of code for all the root and child modules into <strong><em>gist files</em> </strong>in the Github directory only for the sake of reading and understandng it clearly. I am posting here the same…</p><h3><strong>Root (Parent) module files</strong>:</h3><ul><li><strong>main.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5709b00f3b1ac40b59f8793ffac9ff9/href">https://medium.com/media/a5709b00f3b1ac40b59f8793ffac9ff9/href</a></iframe><ul><li><strong>variables.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d81702f4ce52b06b0f18fff04140b53a/href">https://medium.com/media/d81702f4ce52b06b0f18fff04140b53a/href</a></iframe><ul><li><strong>outputs.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cc975c765aed8308e8bc4776fe14d1f/href">https://medium.com/media/3cc975c765aed8308e8bc4776fe14d1f/href</a></iframe><ul><li><strong>install_apache.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8cd8c719ed42d867722de4484ef2e28/href">https://medium.com/media/c8cd8c719ed42d867722de4484ef2e28/href</a></iframe><ul><li><strong>terraform.tfvars</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69c8aba45c96161a7d114a5883115b51/href">https://medium.com/media/69c8aba45c96161a7d114a5883115b51/href</a></iframe><ul><li><strong>.gitignore</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74dfe09e912c76f4e87c4f2b16b88498/href">https://medium.com/media/74dfe09e912c76f4e87c4f2b16b88498/href</a></iframe><h3>compute module</h3><ul><li><strong>main.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9aff1d4b976a32e3293b97df25b76040/href">https://medium.com/media/9aff1d4b976a32e3293b97df25b76040/href</a></iframe><ul><li><strong>outputs.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be4ab71052067212c0844a953c02ad9b/href">https://medium.com/media/be4ab71052067212c0844a953c02ad9b/href</a></iframe><ul><li><strong>variables.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f29685b8a7d22f55c8441d40f90eef14/href">https://medium.com/media/f29685b8a7d22f55c8441d40f90eef14/href</a></iframe><h3>loadbalancing module</h3><ul><li><strong>main.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1adae9de613d357a6612d4c12ae73dc9/href">https://medium.com/media/1adae9de613d357a6612d4c12ae73dc9/href</a></iframe><ul><li><strong>outputs.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3d784e6a6a974e15f7b06c355082448/href">https://medium.com/media/d3d784e6a6a974e15f7b06c355082448/href</a></iframe><ul><li><strong>variables.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/651befe9d88548e70c5036905c80527c/href">https://medium.com/media/651befe9d88548e70c5036905c80527c/href</a></iframe><h3>networking module</h3><ul><li><strong>main.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf1f46f8b30dfeb341c863b4cc54bc61/href">https://medium.com/media/cf1f46f8b30dfeb341c863b4cc54bc61/href</a></iframe><ul><li><strong>outputs.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4da5eee3e9a2cd3764c6b6c13db03edc/href">https://medium.com/media/4da5eee3e9a2cd3764c6b6c13db03edc/href</a></iframe><ul><li><strong>variables.tf</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2150add27de82ec34696856c5777a3f9/href">https://medium.com/media/2150add27de82ec34696856c5777a3f9/href</a></iframe><p><strong>Now run these Terraform commands in the following order:</strong></p><ul><li>Run terraform init to initialize Terraform.</li><li>Run terraform fmt to format the code.</li><li>Run terraform validate to check for any syntax errors.</li><li>Run terraform plan to see what resources will be created.</li><li>Run terraform apply and type yes when prompted.</li></ul><p>At the end, got this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pNRR12h3pzKD6Dy4OrG56Q.png" /></figure><p>but our infrastructure is completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_FPCponzhJJy5_un6GBWHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xfn6xm8_sz0CcyI5z8mR_A.png" /></figure><p>You have to go manually and copy the <strong><em>dns name</em></strong> from Load balancing section</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xB9O1vX3rJJsnAqKh4Qs0A.png" /></figure><h4>verify</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PbOZ-4oR9iVhx1UiAAi0Iw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_aOufDWZjNd0p17pIdsNzA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eizod7LBiJMNm332-bMKaA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WvBDbi3plvDNQOClkS4KHg.png" /></figure><p>No Elastic IP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nHXlNuSQz-4iJaTHEo-KkQ.png" /></figure><p>No NAT Gateway</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c6DW9K5BCO8IAVgshAjxEA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xB9O1vX3rJJsnAqKh4Qs0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zqQEaJFZHYfJGatR1DlWQw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UOMjW74f53lbscL39uuS8Q.png" /></figure><h3>Test ALB</h3><ul><li>Copy the <strong>alb_dns</strong> output and paste it on to a new Interner browser to test. It will display “Hello World” text with the <strong>Private IP of one of the Web (named it as database) servers</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ovn-8xI6vCGLsOoMOn8aFw.png" /></figure><ul><li>Now refresh the page and now it displays the <strong>Private IP address of the 2nd Web (named it as database) server</strong>. If you continue to refresh, you will see it switch back and forth.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1j5b6WfaNSvDvHOyFnMo_Q.png" /></figure><h3>Bastion Host &amp; Web (named them as database) servers</h3><p>showing 1 Bastion host and 2 Web (named them as database) servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RbNLfVR2OIUsynb8H2Gxhw.png" /></figure><h3>Test Bastion host</h3><p>I cannot see the names of the instances under <strong>Name</strong> section.</p><ul><li>Click the box under Name section and look at the security group — <strong>my_bastion_sg</strong> associated with the instance.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DCfAEMWlnWlULcgyKO4MoQ.png" /></figure><ul><li>Then click on the box to find out the Public IP of our bastion host</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*apScostbsVlTbrUBhXFdIw.png" /></figure><p>Using <strong>Putty</strong> and <strong>Putty Agent forwarding </strong>(use Pageant — Putty authentication agent), log into the putty session using the <strong>key name</strong> from the root main.tf (<strong>NVirKey</strong>) as your <strong>EC2 Key Pair name</strong> via <strong>SSH</strong> connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qvp8F2htNOEB-ns6BrV7gQ.png" /></figure><ul><li><strong>ping google.com</strong> to test the connection to the internet.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GN6psr9d3olG_vgdqApmJA.png" /></figure><h3>Test 1st Web (named as database) server</h3><ul><li>Click the box under Name section and look at the security group — <strong>my_database_sg</strong> associated with the 1st Web instance.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IKb3cRVFXisnrtJdHlDlRw.png" /></figure><ul><li>Then click on the box to find out the Private IP of our Web (database) server</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_EDOTbzltQ7zP9P0DrLQQ.png" /></figure><ul><li>Use the private IP from our web (database) servers to SSH into from our Bastion Host.</li><li><strong>ping google.com</strong> to test the connection to the internet.</li></ul><pre><strong>$ ssh ec2-user@&lt;private ip&gt;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AwgE_O9v8I6nVAyS0hgrWg.png" /></figure><ul><li>You can also verify <strong>cat /var/www/html/index.html</strong> to see the contents of our web page.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4WWXeD7D8HYaDZ6-kwNh0Q.png" /></figure><h3>Test 2nd Web (named as database) server</h3><ul><li>Click the box under Name section and look at the security group — <strong>my_database_sg</strong> associated with the 2nd Web instance.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4mJcnE7GAa77X4w1_j8m8g.png" /></figure><ul><li>Then click on the box to find out the Private IP of our 2nd Web (database) server</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dcIbHXkpnr_c0VwHTkP8_Q.png" /></figure><ul><li>Use the private IP from our 2nd Web (database) server to SSH into from our Bastion Host.</li></ul><pre><strong>$ ssh ec2-user@&lt;private ip&gt;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3zjcpO5TqjFY0o4EyN7PYw.png" /></figure><ul><li><strong>ping google.com</strong> to test the connection to the internet.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3zjcpO5TqjFY0o4EyN7PYw.png" /></figure><ul><li>You can also verify <strong>cat /var/www/html/index.html</strong> to see the contents of our web page.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DopmBjd5OvIKiFlxZ41DnA.png" /></figure><h3>Cleanup</h3><p>Run a <strong>terraform destroy</strong> from the Cloud9 IDE terminal to remove our infrastructure. Type <strong>yes</strong> when prompted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XXB5DnLGpvhiOqZ2C0lnKA.png" /></figure><p><strong>What we have done so far</strong></p><p><em>In Cloud9 environment, we created two Web servers placed in Private Subnets which has access to the internet through a Bastion host placed in Public Subnets with High availability and Load Balancing features.</em></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><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4cebdecfcde" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/deploying-a-two-tier-architecture-in-aws-using-terraform-modules-c4cebdecfcde">Deploying a Two-Tier Architecture in AWS Using Terraform Modules</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[How to stop Three specific EC2 Instances with Python script using boto3]]></title>
            <link>https://towardsaws.com/how-to-stop-three-specific-ec2-instances-with-python-script-using-boto3-8ca5abe5d8d7?source=rss-5a084796b90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ca5abe5d8d7</guid>
            <category><![CDATA[boto3]]></category>
            <category><![CDATA[scripting]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ec2]]></category>
            <dc:creator><![CDATA[Revathijoshi]]></dc:creator>
            <pubDate>Sun, 21 Aug 2022 04:36:30 GMT</pubDate>
            <atom:updated>2022-08-21T04:36:30.223Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*guhs31Gj-PL3ADLymCCsjw.png" /><figcaption><strong>EC2 — — — Python — — — boto3</strong></figcaption></figure><p><strong>Boto3</strong> is the Amazon Web Services (AWS) Software Development Kit (SDK) for <strong>Python</strong>. It supports all current AWS cloud services, including <strong>Elastic Compute Cloud (EC2)</strong>, DynamoDB, AWS Config, Cloud Watch, and Simple Storage Service. It allows you to directly create, update, and delete AWS resources from your Python scripts.</p><p>In this article, I am going to show you how to stop <strong>three EC2 instances</strong> with <strong>DEV tag </strong>using Python script with boto3.</p><h3>Objectives:</h3><ul><li>Our DevOps engineering team often uses a development lab to test releases of our application.</li><li>The Managers are complaining about the rising cost of our development lab and need to save money by stopping our (for this example) 3 EC2 instances after all engineers are clocked out.</li><li>We want to ensure that only our <strong>Development instances</strong> are stopped to make sure nothing in Production is accidentally stopped.</li><li>Add logic to our python script that stops only **running** instances that have the **Environment: Dev** tag.</li></ul><h4>Note:</h4><p>Added a logic not to stop our Cloud9 EC2 instance</p><h3>Pre-requisites:</h3><ul><li>AWS user account with admin access, not a root account.</li><li>Cloud9 IDE comes with Python and boto3 installed.</li></ul><h3>Resources Used:</h3><ul><li><a href="https://learn-to-code.workshop.aws/">learn-to-code.workshop.aws</a></li><li><a href="https://boto3.amazonaws.com/v1/documentation/api/latest/guide/ec2-example-managing-instances.html">Boto3 documentation — Boto3 Docs 1.24.56 documentation</a></li></ul><p><em>Let’s get started!</em></p><p>Create a new directory called — <strong>boto3_multiple_ec2 </strong>on the cloud9 environment.</p><pre><strong>mkdir &lt;directory name&gt;<br>cd boto3_multiple_ec2</strong></pre><p>I was very careful in working with small chunks of code when working with this script, to print out the ONLY three EC2 instances with the “DEV” tag, and not to knock off the EC2 instance of my Cloud9 environment.</p><p>Once Python script is working, I copy and pasted the code into a script — <strong>boto3_multiple_ec2.py</strong></p><p>Here is the<strong> gist</strong> of the python script.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47a5001dafa0ed506db34f3a99036724/href">https://medium.com/media/47a5001dafa0ed506db34f3a99036724/href</a></iframe><p>You can also see the same code in my <a href="https://github.com/awsmine/boto3_python_projects/blob/main/boto3_multiple_ec2.py">GitHub repository</a></p><h4><strong>What we have done so far</strong></h4><p>Created a python script with boto3 to stop three specific EC2 instances with “DEV” tags and to keep my Cloud9 EC2 instance alive!!!</p><p>Though it seems like a simple and straightforward script, I encountered many errors just to get the logic working. I like python and is fun to do projects with it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ca5abe5d8d7" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/how-to-stop-three-specific-ec2-instances-with-python-script-using-boto3-8ca5abe5d8d7">How to stop Three specific EC2 Instances with Python script using boto3</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[Create an ECS Cluster with Docker image using Terraform]]></title>
            <link>https://towardsaws.com/create-an-ecs-cluster-with-docker-image-using-terraform-595fabbd9a65?source=rss-5a084796b90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/595fabbd9a65</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[aws-fargate]]></category>
            <category><![CDATA[amazon-ecs]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Revathijoshi]]></dc:creator>
            <pubDate>Sat, 20 Aug 2022 04:33:52 GMT</pubDate>
            <atom:updated>2022-08-20T04:33:52.020Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SZV54LETpahtJfu5mLkueQ.png" /></figure><p>In this article, I am going to show you how to deploy a Docker (centos) image from an ECS cluster with Terraform.</p><h4>What is ECS?</h4><p><strong>Amazon Elastic Container Service (Amazon ECS)</strong> is a highly scalable and fast container management service. You can use it to run, stop, and manage containers on a cluster.</p><p>Here, We are going to focus only on <strong>four main components of ECS.</strong></p><ul><li><strong>ECS Cluster:</strong> An Amazon ECS <em>cluster</em> is a logical grouping of tasks or services.</li><li><strong>Task:</strong> A <em>task</em> is the instantiation of a task definition within a cluster.</li><li><strong>Task Definition:</strong> A <em>task definition</em> is a JSON format text file that describes one or more containers that form your application. Maximum ten containers. The task definition functions as a blueprint for your application.</li><li><strong>ECS Service:</strong> An Amazon ECS <em>service</em> runs and maintains your desired number of tasks simultaneously in an Amazon ECS cluster.</li></ul><h4>What is Fargate?</h4><p>AWS Fargate is a serverless technology that you can use with Amazon ECS to run <a href="https://aws.amazon.com/what-are-containers">containers</a> without having to manage servers or clusters of Amazon EC2 instances. With AWS Fargate, you no longer have to provision, configure, or scale clusters of virtual machines to run containers.</p><h4>What is Terraform?</h4><p>HashiCorp Terraform is an infrastructure as code (IaC) tool that lets you define both cloud and on-prem resources in human-readable configuration files that you can version, reuse, and share.</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.</p><p><strong><em>Here is the link to my github code for this article: </em></strong><a href="https://github.com/awsmine/Terraform_projects/tree/main/ECS_Dockerimage_Terraform"><strong><em>ECS_Dockerimage_Terraform</em></strong></a></p><p><em>Let’s get started!</em></p><h3>Objectives</h3><p>Your team needs you to deploy a Docker container with a CentOS image-</p><ul><li>Pull a CentOS image from the Docker registry.</li><li>Create an ECS cluster using the docker image with Terraform.</li></ul><h3>Pre-requisites:</h3><ul><li>AWS user account with admin access, not a root account.</li><li>Cloud9 IDE, comes with Terraform and Docker installed.</li><li>An account with <a href="https://www.docker.com/"><strong>Docker</strong></a><strong> </strong>and<strong> </strong><a href="https://hub.docker.com/"><strong>Docker Hub</strong></a><strong>.</strong></li></ul><p>For this article, I referred to<strong> </strong><a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html"><strong>ECS documentation</strong></a> and <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster"><strong>ECS (Elastic Container)</strong></a><strong> </strong>section from Terraform AWS documentation.</p><h3>Create a directory for this project</h3><pre><strong>mkdir ECS_Dockerimage_Terraform<br>cd ECS_Dockerimage_Terraform</strong></pre><p>Create these following files into your project directory — <strong><em>ECS_Dockerimage_Terraform</em></strong></p><h3><strong>main.tf</strong></h3><p>This file contains resources for creating AWS ECS cluster and its components.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c1fab56f618d15fb5b6101614258cd2/href">https://medium.com/media/4c1fab56f618d15fb5b6101614258cd2/href</a></iframe><h3>variables.tf</h3><p>This file contains variables.</p><p><strong>Note:</strong> Here we have declared variables for our access key and secret access key.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f88214b853a25409683a5d8acae21c0b/href">https://medium.com/media/f88214b853a25409683a5d8acae21c0b/href</a></iframe><p>Setting the<strong>sensitive = true</strong> means that these variables are not displayed as plain text in the CLI or state File. We also do not pass our actual values for keys in this file, which are stored in another file <strong>terraform.tvars</strong>.</p><h3>terraform.tfvars</h3><p>Here we provided values for our access key and secret access key. This file is automatically ignored by your <strong>.gitignore</strong> file and will not be published to your repo.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2af4359554d5f7721c1b312c4397e52e/href">https://medium.com/media/2af4359554d5f7721c1b312c4397e52e/href</a></iframe><h3>providers.tf</h3><p>This file contains two providers</p><ul><li>Docker for pulling the centos image</li><li>AWS for creating ECS</li></ul><p><strong>Note:</strong> Here in our aws provider block we set our <strong>access_key</strong> and <strong>secret_access_key</strong> variables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b73676a119f07b28b7adde5633fbaef/href">https://medium.com/media/3b73676a119f07b28b7adde5633fbaef/href</a></iframe><h3>.gitignore</h3><p>This file will ensure that our sensitive information is <strong>ignored by git</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1307c869b667b43a4ad631b407f7849/href">https://medium.com/media/a1307c869b667b43a4ad631b407f7849/href</a></iframe><h3><strong>vpc.tf</strong></h3><p>This file has our vpc and subnets information.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edb04fb10cbfc831a2f7d253fc241807/href">https://medium.com/media/edb04fb10cbfc831a2f7d253fc241807/href</a></iframe><h3><strong>outputs.tf</strong></h3><p>This file is used to extract the value of an output variable from the state file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8508c736a2058f593725aeff653a32f2/href">https://medium.com/media/8508c736a2058f593725aeff653a32f2/href</a></iframe><h3>Provision Infrastructure</h3><ul><li>Run <strong>terraform init -&gt;</strong> initialize directory, pull down providers and modules from the registry to allow your configuration to work properly.</li><li>Run <strong>terraform fmt -&gt;</strong> reformats your configuration in the standard style, so it’ll make sure that the spacing and everything else is formatted correctly.</li><li>Run <strong>terraform validate -&gt;</strong> catch syntax errors, version errors, and other issues.</li><li>Run <strong>terraform plan -&gt;</strong> do a dry run of your plan to see what it’s actually going to do and what resources will be created.</li><li>Run <strong>terraform apply -&gt;</strong> applies your configuration to a provider to create your infrastructure. Type <strong>Yes </strong>when prompted.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nfDUtb4Wg7GSgwq3oFtwAw.png" /></figure><ul><li>Lists all the outputs from outputs.tf file for the root module, as stated in the code.</li><li>Run <strong>terraform state list -&gt;</strong> shows 7 resources are added</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UuXF3DvbTaANQJUEF449BQ.png" /></figure><h3>Verify Resources created from AWS Console</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iTT0Rn_sssi5dqJy_eW0Eg.png" /><figcaption><strong>centos-cluster</strong></figcaption></figure><ul><li>Click<strong> centos-cluster</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vuWj7f-OwgkS7mY-iM2T-A.png" /></figure><ul><li>On the Services tab</li><li>Click Service</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ePPaiVggtb_rAwYB5VXacA.png" /><figcaption><strong>ECS Service — project-service</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kg_pTc6JNUbTEIq7ry7B4A.png" /><figcaption><strong>ECS-Fargate</strong></figcaption></figure><ul><li>On the Tasks tab</li><li>Click the Task</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*59grTFwB5BAZ6wsrdMvtxA.png" /><figcaption><strong>Task</strong></figcaption></figure><ul><li>In the Task Details tab</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x6ukwOCWMhUL-uNGbqU1Cw.png" /><figcaption>Task</figcaption></figure><ul><li>We will see our Pending Containers. Notice our pending container’s Image is centos.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vutZFh594ushJnKlxgKwrQ.png" /><figcaption><strong>centos container with centos-7 image</strong></figcaption></figure><ul><li>From the left panel click TaskDefinitions</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DqQS5QXddVV2JW6CpIzPBg.png" /><figcaption><strong>Task Definition</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h75XkIU1eKfiQrRBQdazEw.png" /><figcaption><strong>Subnets</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7n8OqLMARmoA8UE667bIoA.png" /><figcaption><strong>VPC</strong></figcaption></figure><h3>Clean up</h3><ul><li>Run <strong>terraform destroy --auto-approve</strong></li><li>Will destroy your infrastructure</li><li>Destroy without being prompted to enter ”yes”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3kAj7lo5vc4bYxCGEyJJYw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=595fabbd9a65" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/create-an-ecs-cluster-with-docker-image-using-terraform-595fabbd9a65">Create an ECS Cluster with Docker image using Terraform</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[Docker: Network Bridge with Mount Points pointing to a Common Directory]]></title>
            <link>https://towardsaws.com/docker-network-bridge-with-mount-points-pointing-to-a-common-directory-a814fd56ad77?source=rss-5a084796b90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a814fd56ad77</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Revathijoshi]]></dc:creator>
            <pubDate>Fri, 19 Aug 2022 09:18:53 GMT</pubDate>
            <atom:updated>2022-08-19T09:18:53.468Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q47vnvjdxzcIgJ4yaYbyPw.png" /><figcaption>Image Source: Docker logos</figcaption></figure><p>In this article, I am going to show you how to create 2 separate containers, <br>connected to a Docker network bridge<strong><em>,</em></strong> both using a centos image and having mount points pointing to the same local directory and its files.</p><p><em>Let’s get started!</em></p><h3>Objectives</h3><ul><li>Ensure Docker is installed, and the Docker daemon is running.</li><li>Create a new <strong><em>local directory</em></strong> called <strong><em>“webfiles”</em></strong>.</li><li>Create two files named <strong><em>“infofile.txt”</em></strong> and <strong><em>“exportfile.txt”</em></strong> in that directory.</li><li>Create a docker network called <strong><em>“webnet”</em></strong>.</li><li>Start two containers using the <strong><em>centos image</em></strong>, and assign both to the “<strong>webnet</strong>” network.</li><li>Create <strong><em>mount points</em></strong> to the local “<strong>webfiles</strong>” directory in both containers</li><li>Verify both containers can see the file created in Step #3.</li></ul><h3>Pre-requisites:</h3><ul><li>AWS user account with admin access, not a root account.</li><li>Cloud9 IDE, comes with Docker installed.</li><li>An account with <a href="https://www.docker.com/"><strong>Docker</strong></a><strong> </strong>and<strong> </strong><a href="https://hub.docker.com/"><strong>Docker Hub</strong></a><strong>.</strong></li></ul><p>For this article, I used <a href="https://docs.docker.com/network/"><strong>Configure Networking</strong></a><strong> </strong>and <a href="https://docs.docker.com/engine/reference/run/"><strong>Command Line Reference</strong></a> Sections from the Docker documentation</p><h3>Ensure Docker is installed, and the Docker daemon is running.</h3><ul><li>Run this command to check whether Docker is installed</li></ul><p><strong>docker version</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8BWJxpL1xFizVkzCGIJYXA.png" /></figure><ul><li>Run this command to check whether Docker Daemon is running</li></ul><p><strong>systemctl status docker</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ahrd-s9vVlf8QNjIPFatlw.png" /></figure><h3>Create a new local directory called “webfiles”.</h3><ul><li>This is the same directory to which we will mount both of our containers</li><li>Can do it two ways</li><li><strong>One way —</strong> Right click and select new folder on Cloud9 environment</li><li>Name it as<strong>webfiles</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*UVu_k7DMfNJuRYXWX17khw.png" /></figure><ul><li><strong>Second way —</strong>From the command-line interface on Cloud9 IDE, run this command</li></ul><p><strong>makdir &lt;directory name&gt;</strong></p><p><strong>mkdir webfiles</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GMbcO2eecktQ5-3frOVGaA.png" /></figure><h3>Create two files named “infofile.txt” and “exportfile.txt” in that directory.</h3><ul><li>Create 2 files, <strong>infofile.txt</strong> and <strong>exportfile.txt</strong></li><li>Can do it two ways to add these 2 files</li><li><strong>One way — </strong>Right click and select new file from the directory that you just created on Cloud9 environment</li><li>Name it as<strong>infofile.txt</strong></li><li>Name it as<strong>exportfile.txt</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*pa2qv4MkF4-TwKJpgPmj_g.png" /></figure><ul><li><strong>Second way — </strong>From the command-line interface on Cloud9 IDE, run this command</li></ul><pre><strong>touch &lt;directory name&gt;/&lt;file name&gt;<br></strong><strong>touch webfiles/infofile.txt</strong></pre><pre><strong>touch &lt;directory name&gt;/&lt;file name&gt;<br>touch webfiles/exportfile.txt</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OsqO49LUxkUyEiQK8_5cHA.png" /></figure><ul><li>Run this command to verify <strong>ls -lt webfiles/</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F-o6xT3L9yys3PKUB5ZjUA.png" /></figure><h3>Create a docker network called “webnet”.</h3><p><strong>docker network create -d bridge &lt;network name&gt;</strong></p><p><strong>docker network create -d bridge webnet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tl4zdAnVPuJM1N4k3gM_Aw.png" /></figure><h3>To verify if a Docker bridge network has been successfully created, type the following command:</h3><p><strong>docker network ls</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yKx7UWKktHdRTCwVi7fIAg.png" /></figure><ul><li>This will list all the Docker networks.</li><li>The first three are created by default.</li><li>default bridge network is listed, along with host and none.</li><li>The latter two <strong>host</strong> and <strong>none</strong>are not fully-fledged networks, but are used to start a container connected directly to the Docker daemon host’s networking stack, or to start a container with no network devices.</li></ul><h3>Start two containers using the centos image, and assign both to the “webnet” network. Create mount points to the local “webfiles” directory in both containers</h3><ul><li>Repeat the same command with a different container name to create 2 containers</li></ul><p><strong>docker run -dit --name &lt;container name&gt; --network &lt;network name&gt; --mount</strong> <strong>type=bind,source=&quot;$PWD&quot;/webfiles,target=/webfiles centos:latest</strong></p><p><strong>docker run -dit --name </strong><strong><em>web01</em></strong><strong> --network=webnet --mount</strong> <strong>type=bind,source=&quot;/home/ec2-user/environment&quot;/webfiles,target=/webfiles centos:latest</strong></p><p><strong>docker run -dit --name </strong><strong><em>web02</em></strong><strong> --network=webnet --mount</strong> <strong>type=bind,source=&quot;/home/ec2-user/environment&quot;/webfiles,target=/webfiles centos:latest</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eQWQmxoNgTLGAZD1fgp_uA.png" /></figure><ul><li>The network was created by the first command, but when used to run the second container, it acts as a reference to the already-established network.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rK8XGUPfX11bVwLpVnPo6w.png" /></figure><p><strong><em>what this command means</em></strong></p><p><strong>docker run -&gt;</strong>is the base command to start the container.</p><p><strong>-dit -&gt;</strong> combining three flags -d, -i, and -t means to detach the container from the host and setup an interactive session.</p><p><strong>--name &lt;container name&gt; -&gt;</strong> creates container name</p><p><strong>--network &lt;network name&gt; -&gt;</strong>this will create and reference the new network bridge</p><p><strong>--mount</strong> <strong>type=bind, -&gt; </strong>create a mount point</p><p><strong>source=&lt;&quot;/absolute path from host&quot;/webfiles&gt;,</strong></p><p><strong>source=&quot;/home/ec2-user/environment&quot;/webfiles, -&gt;</strong>this is the local host directory</p><p><strong>target=&lt;/path in container&gt;</strong></p><p><strong>target=/webfiles -&gt;</strong> location of mount point within the container where you want to store the files. If it does not exist, it will be created.</p><p><strong>centos:latest -&gt;</strong> latest image that docker will use to build our container.</p><ul><li>To see the containers that we created just now</li></ul><p><strong>docker ps -a</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CI1dqWhRvC5jGj72UPE2cw.png" /></figure><p>Container status is <strong>“<em>UP</em>”</strong></p><h3>Verify both containers are attached to the network bridge</h3><p><strong>docker network inspect &lt;network name&gt;</strong></p><p><strong>docker network inspect webnet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2eEOgtfTTJd-1KUzvpZGKg.png" /></figure><h3>Verify both containers can see the files created in the local directory from Step #3.</h3><ul><li>First, find the Mount point</li><li>The output is big, have to scroll down to find <strong>“Mounts”</strong> section</li><li>It will give the same Mount Type and Mount Path for both the containers</li></ul><p><strong>web01 OR web02</strong></p><p><strong>docker inspect &lt;container name&gt;</strong></p><p><strong>docker inspect web01</strong></p><p><strong>docker inspect web02</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0CzrE7Hg76rNeGd-f-26rw.png" /></figure><ul><li>Let’s verify if the files are accessible from the first container or not.</li><li>Run this command to open up a bash terminal:</li></ul><p><strong>docker exec -it &lt;container name&gt; bash</strong></p><p><strong>docker exec -it web01 bash</strong></p><ul><li>List the directories inside the container using this command.</li></ul><p><strong>ls</strong></p><ul><li>Now, change the directory to the target directory</li></ul><p><strong>cd /webfiles</strong></p><ul><li>You can see the <strong>exportfile.txt </strong>and <strong>infofile.txt</strong>files with this command</li></ul><p><strong>ls</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5BcujEGJ1x5iM5OZ-J0PBQ.png" /></figure><ul><li>Exit out of the container with the exit command</li><li>Repeat the same steps to verify if the files are accessible from the second container or not.</li></ul><h3>Clean up the Docker Containers, Images, and Network Bridge</h3><ul><li>Run the following commands <strong>to clean up your containers and images</strong></li></ul><pre><strong># for removing containers<br>docker rm -f $(docker ps -a -q)</strong></pre><pre><strong># for removing images<br>docker rmi -f $(docker images -a -q)</strong></pre><ul><li>Run the following commands to <a href="https://docs.docker.com/engine/reference/commandline/network_rm/"><strong>remove the Docker Network Bridge</strong></a></li></ul><pre><strong># for removing Docker Network Bridge<br>docker network rm &lt;network name&gt;<br>docker network rm webnet</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xmTAI_4shCNBopgTNBaYVA.png" /></figure><p><strong>What we have done so far</strong></p><p><em>In Cloud9 environment, we created two separate containers. Both the containers use a centos image, are assigned to the same Docker network bridge, have mount points pointing to the same local directory, and can see the files inside that directory.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a814fd56ad77" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/docker-network-bridge-with-mount-points-pointing-to-a-common-directory-a814fd56ad77">Docker: Network Bridge with Mount Points pointing to a Common Directory</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 Docker Image with Nginx and Save it to AWS ECR]]></title>
            <link>https://towardsaws.com/deploy-a-custom-docker-image-with-nginx-and-save-it-to-aws-ecr-3276013fb09b?source=rss-5a084796b90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3276013fb09b</guid>
            <dc:creator><![CDATA[Revathijoshi]]></dc:creator>
            <pubDate>Tue, 16 Aug 2022 20:01:52 GMT</pubDate>
            <atom:updated>2022-08-19T09:17:56.204Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sTYJS43d6idlSBJv2-_unw.png" /></figure><p>In this article, I am going to show you how to create a <strong>Custom Docker image</strong> with a <strong>Docker file</strong> that will tell you the date and time the container has been deployed using <strong>Nginx</strong> and save that data to the AWS’s <strong>ECR </strong>(Elastic Container Registry).</p><h4>What is Docker?</h4><p><strong>Docker</strong> is an open platform for developing, shipping, and running applications in a container.<strong> Containers</strong> don’t use any of the host resources like hardware or CPU. An <strong>image</strong> is a read-only template with instructions for creating a Docker container. You might create your own images or you might only use those created by others and published in a registry. To build your own image, you create a <strong>Dockerfile</strong> with a simple syntax for defining the steps needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the image. When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt. This is part of what makes images so lightweight, small, and fast, when compared to other virtualization technologies.</p><p>When we use <strong><em>Docker</em></strong><em> </em>we will use images, such as an <strong><em>NGINX image</em></strong> and spin up a <strong><em>container</em></strong> with it.</p><p>This is my <a href="https://github.com/awsmine/Docker_projects/tree/main/Docker_Nginx_Image_ECR">GitHub Link for this project</a>.</p><p><em>Let’s get started!</em></p><h4>Objectives</h4><ul><li>Create your own image using Nginx and add a file that will tell you the date the container has been deployed</li><li>Deploy your container with port 8080 open</li><li>Save your container data to the AWS Elastic Container Registry (ECR)</li></ul><h4>Pre-requisites:</h4><ul><li>AWS user account with admin access, not a root account.</li><li>Cloud9 IDE, comes with Docker installed.</li><li>Allow the EC2 instance to be accessible by our IP (<a href="https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html#app-preview-share-security-group">Add an inbound rule to the EC2 Security Group to allow the instance to access port 8080</a>).</li><li>An account with <a href="https://www.docker.com/"><strong>Docker</strong></a><strong> </strong>and<strong> </strong><a href="https://hub.docker.com/"><strong>Docker Hub</strong></a></li></ul><p>For this article, I used <a href="https://docs.docker.com/get-started/overview/"><strong>Docker documentation</strong></a>.</p><h3>Create a Directory</h3><p>In the Cloud9 IDE, create a directory to save your HTML &amp; Dockerfile. <br>Then cd into that directory</p><p><strong>mkdir &lt;Directory name&gt;</strong> <br><strong>mkdir docker_work</strong></p><p><strong>cd &lt;Directory name&gt;</strong><br><strong>cd docker_work</strong></p><h3>Pull Latest Nginx Image from Docker Hub</h3><p>We have to use Nginx to deploy our custom website, so pull the <a href="https://hub.docker.com/_/nginx"><strong>latest version of the Nginx image</strong></a> from Docker Hub.</p><p><strong>docker pull nginx:latest</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wG6BQUf57dnyVSJzr3p8pQ.png" /></figure><p>This will bring the image on to your local computer. verify that we pulled the latest image.</p><p><strong>docker images</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IwWTdxEa8Ws0Q64hQvrC-Q.png" /></figure><h3>Create Dockerfile and index.html</h3><p><strong>Create Dockerfile</strong></p><ul><li>Modify the<strong><em> Dockerfile </em></strong>to make it run our script on start-up!</li></ul><p><strong>Note:</strong> make sure the D is capitalized or it will not be recognized by docker.</p><p><strong>docker_work $ vi Dockerfile</strong></p><p>Add the following code to the <a href="https://github.com/awsmine/Docker_projects/blob/main/Docker_Nginx_Image_ECR/Dockerfile"><strong><em>Dockerfile</em></strong></a> and save it</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e80070fc60b16d979c3385c74bbed2c/href">https://medium.com/media/4e80070fc60b16d979c3385c74bbed2c/href</a></iframe><ul><li>Create a new <a href="https://github.com/awsmine/Docker_projects/blob/main/Docker_Nginx_Image_ECR/index.html"><strong><em>index.html</em></strong></a> file in the same directory by typing the following command:</li></ul><p><strong>docker_work $ vi index.html</strong></p><p>Add the following html code to the file and save it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b8b63d2e0fa30e35314cd5487703e0d/href">https://medium.com/media/6b8b63d2e0fa30e35314cd5487703e0d/href</a></iframe><h3><strong>Build your Custom Image from a Dockerfile</strong></h3><ul><li>To start building the <strong>docker container</strong>, we will run the following command:</li></ul><p><strong>docker build -t &lt;name of the image — create your own&gt;</strong><br><strong>docker build -t nginxrev .</strong></p><p><strong><em>Note: the “.” period after your container name is very important. </em></strong><br>This will ensure that we look for files in the current working directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mqAjoxJBOFEGaEsMgFbyIg.png" /></figure><ul><li>Verify the image from Dockerfile, by running the following command</li></ul><p><strong>docker images</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NZ0pA0yJqut6Hgs0e05wBQ.png" /></figure><h3>Create and Deploy Docker Container</h3><ul><li>Run the command to create the container from your new image<br>and to deploy your newly built container:</li></ul><pre><strong>docker run -d — name &lt;container-name, you name it&gt; -p 8080:80 &lt;image-name&gt;</strong></pre><pre><strong>docker run -d --name my-container -p 8080:80 nginxrev</strong></pre><p><strong>-d </strong>#Run container in background and print container ID<br><strong>-p </strong>#Publish a containers port(s) to the host</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LENVWD7wY2ei0K9Odq0_5Q.png" /></figure><ul><li>Run the command to see that your new container has been created and deployed</li></ul><pre><strong>docker ps -a</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zg1-PVmG_IC3A85YUCVMWw.png" /></figure><h3>Deploy your container with port 8080 open</h3><p>Now it is time to test the code.</p><ul><li>First, Run the command to check your container has Internet access:</li></ul><p><strong>curl localhost:8080</strong></p><p>It prints out the index.html</p><ul><li>Now click on the <strong><em>Share</em></strong> button on the extreme <strong><em>right of Cloud9 IDE</em></strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b7o_iZQ6_r3S537s2VKnqA.png" /></figure><ul><li>Note the <strong><em>Cloud9-IPAddress</em></strong></li><li>Open up a browser and enter the <strong><em>&lt;cloud9-IPAddress&gt;</em></strong> followed by a <strong><em>colon : </em></strong>and <strong><em>8080</em></strong> for the port</li></ul><p><strong><em>&lt;cloud9 IP Address&gt;:8080</em></strong></p><p><strong><em>SUCCESSFUL!!!</em></strong></p><p>You see this on your web browser</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_iFimJJNIW1bsLPNcjGrWQ.png" /></figure><h3>Create New Modified Image from Container</h3><ul><li>Run the following to copy the <strong><em>index.html</em></strong> file to the Container volume.</li></ul><pre><strong>docker cp index.html &lt;container_name&gt;:/usr/share/nginx/html/index.html</strong></pre><pre><strong>docker cp index.html my-container:/usr/share/nginx/html/index.html</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*295kVjxZT1WdO5fcVCHfiw.png" /></figure><ul><li>Commit the changes</li></ul><p><strong>docker commit &lt;container_name&gt;</strong></p><p><strong>docker commit my-container</strong></p><ul><li>View the new image created using the following command</li></ul><p><strong>docker images</strong></p><ul><li>Now tag this image with an appropriate name using the following command:</li></ul><p><strong>docker tag &lt;image ID&gt; &lt;image name&gt;</strong></p><p><strong>docker tag b0cc8fa4d652 nginx_modified</strong></p><ul><li>Now run docker images. You should see the new modified image created with the appropriate tag and image id.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j0N795pPYZbN1zu6F-gqYQ.png" /></figure><h3>Save your Container data (modified Nginx image) to the AWS Elastic Container Registry (ECR)</h3><ul><li>Over to <strong><em>AWS management console</em></strong>/<strong><em>Elastic Container Registry</em></strong>/<strong><em>Get Started</em></strong></li><li><strong><em>Repository name</em></strong> — give a name — <strong><em>docker_nginx_project</em></strong></li><li>Take default settings</li><li>Click on <strong><em>Create Repository</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CLn4am95EI4sa0-Ot0qGaw.png" /></figure><ul><li>Click <strong><em>View push commands</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CPF6WHDlImg5XH1CqD34gA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MXmsX0dplS0OUgsNiArXmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*niDT6YOVYA2OqaugqgRGCw.png" /></figure><ol><li>Run<strong><em> command #1</em></strong> to login</li><li>Do not need to run command #2, since we have created the image already</li><li>Modify the <strong><em>command #3</em></strong> by removing the name of the repository <br>that you made earlier in the AWS console and inserting the image id <br>that you retrieved from the docker images command.</li><li>Run the <strong><em>command #4</em> </strong>to push this image to your newly created repository.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OBomGKJT7HHSnphyc70dFA.png" /><figcaption><strong>Command #1 and #3</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ok2F2MTazNY-nqNHAVjXWw.png" /><figcaption><strong>Command #4</strong></figcaption></figure><ul><li>Over to <strong><em>AWS Console/Elastic Container Registry</em></strong></li><li>Click Repository <strong><em>docker_nginx_project</em></strong></li><li>Under <strong><em>Images</em></strong> section, you will be able to see the latest image</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DMwWTAqFM1oRXXcn2G9rNw.png" /></figure><h3>Clean up the Docker Container and images</h3><p>Run the following commands to clean up:</p><pre><strong># for removing containers<br>docker rm -f $(docker ps -a -q)</strong></pre><pre><strong># for removing images<br>docker rmi -f $(docker images -a -q)</strong></pre><pre><strong>From AWS Console/ECR, delete the repository</strong> <strong><em>docker_nginx_project</em></strong></pre><p><strong>What we have done so far</strong></p><p><em>In Cloud9 environment, we created a custom Docker image with NGINX. We have completed this project by modifying a Dockerfile, that will display the date and time the container is deployed and pushing our container to ECR.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3276013fb09b" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/deploy-a-custom-docker-image-with-nginx-and-save-it-to-aws-ecr-3276013fb09b">Deploy a Custom Docker Image with Nginx and Save it to AWS ECR</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[Working with API Gateway HTTP API type, Lambda Function, and SQS Queue]]></title>
            <link>https://towardsaws.com/working-with-api-gateway-http-api-type-lambda-function-and-sqs-queue-ceb34703645?source=rss-5a084796b90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ceb34703645</guid>
            <dc:creator><![CDATA[Revathijoshi]]></dc:creator>
            <pubDate>Sat, 13 Aug 2022 13:08:21 GMT</pubDate>
            <atom:updated>2022-08-19T09:17:03.216Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dFMQoT9GPZ-oNgRW0066Rg.png" /></figure><p>In this article, I will show you on how the <strong>API Gateway HTTP API type</strong>, triggers a <strong>Lambda function</strong> to send a message with the current time to the <strong>SQS queue </strong>created <strong>with Python and boto3.</strong></p><p>This function then returns that message back to API Gateway so we can see it.</p><p><strong>AWS Lambda </strong>is a serverless, event-driven compute service that lets you run code for virtually any type of application or back-end service without provisioning or managing servers. You can trigger Lambda from over 200 AWS services and only pay for what you use.</p><p>Let’s get started!</p><h3>Objectives:</h3><ul><li>Create a Standard SQS Queue using Python.</li><li>Create a Lambda function in the console with a Python 3.7 or <br> higher runtime.</li><li>Modify the Lambda to send a message to the SQS queue and yo test the function.</li></ul><p>The message should contain the current time. Use the built-in test function for testing.</p><ul><li>Create an API Gateway HTTP API type trigger for the lambda.</li><li>Test the trigger to verify the message was sent.</li><li>Finally, we will check out the SQS queue to see that it is receiving messages from Lambda.</li><li>Check out your Logs in CloudWatch.</li></ul><h3><strong>Pre-requisites:</strong></h3><ul><li>AWS user account with admin access, not a root account.</li><li>IDE of your liking with AWS CLI, Python, and boto3 installed.</li></ul><p>I am using <strong>Cloud9</strong>, had to install <strong>boto3</strong> on Cloud9 because it did not have it.</p><p><strong>pip3 install boto3</strong></p><p>For this article, I used <a href="https://boto3.amazonaws.com/v1/documentation/api/latest/guide/sqs.html"><strong>boto3 documentation</strong></a><strong>.</strong></p><h3>Create a standard queue in AWS SQS using Python</h3><p>Here is the python and boto3 script with a (.py extension) to create <br>AWS Standard SQS Queue on Cloud9.</p><p><strong>python create_sqs_queue.py</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3wdV_T7AcV2WWAtm91dgGw.png" /></figure><p>The output will give you a URL.</p><p>Here is the link to my code for <a href="https://github.com/awsmine/boto3_python_projects/blob/main/Trigger_API_Lambda_SQS/create_sqs_queue.py"><strong>create_sqs_queue.py</strong></a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e8f1fac22a7eb0f75c7b484f0a17152/href">https://medium.com/media/5e8f1fac22a7eb0f75c7b484f0a17152/href</a></iframe><p>Check<strong> Amazon SQS on AWS Console </strong>to see that the Queue was created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yOtWGwkJz3baU3yQ5GiEOg.png" /></figure><ul><li>Click on the queue —<strong> time_queue</strong></li><li>Note down<strong> SQS ARN </strong>and<strong> SQS URL</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P0DTH7JkLmzFTGLUTZagtQ.png" /></figure><h3><strong>Create a Lambda Function with Python</strong></h3><p>Now I will create a Lambda function that will send a message to the SQS queue I just created.</p><p>In the <strong>AWS console</strong>, navigate to <strong>Lambda</strong>.</p><ul><li>Click<strong> Create function.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T-tB97VNDKUhzbjhXbNpyw.png" /></figure><ul><li>Select<strong> Author from scratch</strong></li><li>Name your function<strong> — <em>lambda_sqs</em></strong></li><li>Select<strong> Python 3.9 </strong>from Runtime from drop-down</li><li>Click<strong> change default execution role </strong>to see -<strong> <em>create a new role with basic lambda permissions</em></strong></li><li>Click<strong> Create function.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*50sDkBAC52jlFH3KXmpdLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GkPHgZHYkUS42TOOOuhT-g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dMRvG0H9AN5_J8n5Qzh7yg.png" /></figure><blockquote><strong><em>Configuring the Role with proper policies/permissions is the key issue here adhering to </em>the principle of least privilege, <em>just so that it can access proper AWS resources for sending out the message.</em></strong></blockquote><p>Once the<strong> Lambda function</strong> has been successfully created, navigate to the <strong>Lambda function</strong></p><ul><li>Click on the function — <strong>lambda_sqs</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yy4TNBnporFVWrqNlVYWhg.png" /></figure><p>On the<strong> Function overview</strong></p><ul><li>Click<strong> Configuration/Permissions</strong></li><li>Click the newly created IAM role<strong> </strong>-&gt; <strong>lambda_sqs-role-</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wu5WTShrb-Hqfk_2YuPXmg.png" /></figure><p>You will now come to<strong> IAM Console.</strong></p><ul><li>Click<strong> Add Permissions</strong></li><li>Click<strong> Attach policies </strong>to add additional permissions</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NdPytjPvPyYhRCtWrffWZQ.png" /></figure><p>You will now come to the screen as shown below:</p><ul><li>Click in the<strong> Current permission policies</strong></li><li>Click on the<strong> + </strong>sign of the<strong> AWSLambdaBasicExecutionRole- </strong>to see the current permissions</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*52q9QG9fA_fWPnC26_8bjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fUk9VptKwLmez1Xc9PdiFw.png" /></figure><ul><li>Click<strong> Edit </strong>to add the following permissions</li><li>Click on the<strong> JSON </strong>tab to view</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M6tTkSFagUFzo6-vf03vbA.png" /></figure><ul><li>Add<strong> “sqs:SendMessage”</strong> to send message to SQS in the <strong>Action</strong> element.</li><li>Add the<strong> ARN of the SQS queue </strong>in the<strong> Resource </strong>element.</li></ul><p>This is what it looks like in the end after adding permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9XZLcvr63XAlzGFKi1x-Vg.png" /></figure><ul><li><strong>Review policy</strong></li><li><strong>Save changes</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DBcGwyrQext-9M4_GnFU3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yGlNzlRz0NJkn5BPZlKHzg.png" /></figure><p>Here is the link to my code for <a href="https://github.com/awsmine/boto3_python_projects/blob/main/Trigger_API_Lambda_SQS/AWSLambdaBasicExecutionRole.json"><strong>AWSLambdaBasicExecutionRole.json</strong></a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/697ab23fca92ba08838dc150637825d6/href">https://medium.com/media/697ab23fca92ba08838dc150637825d6/href</a></iframe><h3>Modify lambda to send a message to SQS queue and to test the function</h3><p>Navigate back to <strong><em>Lambda</em></strong></p><ul><li>Click<strong> <em>Code</em></strong></li><li>Add the following code to<strong> <em>Code source</em> </strong>of your Lambda function.</li><li>Change the<strong> <em>QueueURL</em> to the URL for your SQS queue </strong>that you created in the firtst step.</li></ul><p>This will send a message to SQS that contains the current time — <strong>time_date</strong></p><p>Here is the link to my code for <a href="https://github.com/awsmine/boto3_python_projects/blob/main/Trigger_API_Lambda_SQS/lambda_sendmsg_sqs.py"><strong>lambda_sendmsg_sqs.py</strong></a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c481826952aa2df849a667db5cc6985f/href">https://medium.com/media/c481826952aa2df849a667db5cc6985f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yThHNCTvhdpXeiRzOD5NVw.png" /></figure><p>Once you have copy and paste the code</p><ul><li>Click on<strong> Deploy </strong>to save the changes</li><li>Click on<strong> Test </strong>to configure a test event</li></ul><p>You will be brought to a <strong>Configure test event</strong> screen.</p><ul><li><strong>Create new event, </strong>name it<strong>, <em>lambdaevent.</em></strong></li><li>Chose the<strong> Template &gt; <em>apigateway-aws-proxy.</em></strong></li><li>Click<strong> Save.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QGtXLwL2qAjoSSYZH8Prlw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fk9TixkWAToa8qou9OjgLA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*USJusZHqwWzt-2Sd_n-D6w.png" /></figure><ul><li>Click on<strong> Test</strong></li></ul><p>You will see the results in a <strong><em>new Execution tab</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S_06K6j0QL_fREsAtm3Q_Q.png" /></figure><h3><strong>Create an API gateway HTTP API type trigger for the lambda</strong></h3><p>Now to add the Trigger to our Lambda function.</p><ul><li>Click on<strong> Add Trigger</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Jg3Cmf41E-8vJCh0GtgqA.png" /></figure><ul><li>In the<strong> Trigger configuration </strong>settings</li><li>Select<strong> API Gateway </strong>from the<strong> drop down menu</strong></li><li>Select<strong> Create a new API</strong></li><li><strong>Security </strong>select<strong> Open </strong>from<strong> drop down menu</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*veihvSUNCoZmCdTesTPFjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*km3lS3o9n8tU1wE4kYINpA.png" /></figure><ul><li>Click<strong> Add</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-OuZCuQ_m014e_Fxr_NdOQ.png" /></figure><h3><strong>Test the trigger to verify the message was sent</strong></h3><ul><li>Navigate to the<strong> Function overview</strong></li><li>On<strong> Configuration </strong>tab</li><li>Click the<strong> API endpoint </strong>created</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LtyWzcpR142z5givjCX_5A.png" /></figure><ul><li>You should see the output of our code</li><li><strong>“Message sent successfully”</strong></li><li><strong>Click on it a few times to accumulate more messages in your queue.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7xUCi2fW917czjVgcZvArA.png" /></figure><h3><strong>Finally we will check out the SQS queue to see that it is receiving messages from Lambda</strong></h3><ul><li>Over to<strong> SQS </strong>in the<strong> AWS console.</strong></li><li>Find your<strong> Queue and it shows we have a few messages!</strong></li><li>Click<strong> Send and receive messages</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oKNYI6hHbzZEfe47EjLuAg.png" /></figure><ul><li>Click<strong> Poll for messages</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*50ZoGO4QiWiCVsAqXDlqLA.png" /></figure><ul><li>Click<strong> on one of the messages</strong></li><li>Finally,<strong> we can verify the date &amp; time the message was sent</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g4RWi_Kuc9i8WrkhND--5g.png" /></figure><h3><strong>Check out your Logs in CloudWatch</strong></h3><p>In your <strong>Lambda Function</strong></p><ul><li>Select<strong> Monitor</strong></li><li>Choose<strong> Logs</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OPtFCQ7m8U_lhRYoE8ljcw.png" /></figure><h4><strong>Conclusion</strong></h4><p>We created an SQS queue, using Python, to receive messages from a Lambda function that was triggered by an API.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ceb34703645" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/working-with-api-gateway-http-api-type-lambda-function-and-sqs-queue-ceb34703645">Working with API Gateway HTTP API type, Lambda Function, and SQS Queue</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[Terraform: Creating a very basic EC2 module using “aws_ami” data source — 1]]></title>
            <link>https://towardsaws.com/creating-a-repeatable-infrastructure-with-a-very-basic-ec2-module-using-aws-ami-data-source-8eaff66f470f?source=rss-5a084796b90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8eaff66f470f</guid>
            <dc:creator><![CDATA[Revathijoshi]]></dc:creator>
            <pubDate>Sat, 06 Aug 2022 20:05:06 GMT</pubDate>
            <atom:updated>2022-08-19T13:53:45.389Z</atom:updated>
            <content:encoded><![CDATA[<h3>Terraform: Creating a very basic EC2 module using “aws_ami” data source — 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RJ94qPBZNtlHA0cYW9dwDA.png" /></figure><p>My organization wants to use a template to create a <strong>very basic non-fuctional re-usable EC2 instance</strong> module with an amazon linux 2 ami ID. A simple file — <strong>ec2.tf</strong> has been provided to me. I need to modify this simple file into a re-usable module for the other team members.</p><p>In the my next article, I plan to modify this project making the EC2 module fully functionable by adding more resources like VPC and its networking components so that you can SSH into it.</p><h3><strong>Requirements</strong>:</h3><ol><li>Fork and locally clone a GitHub repository with an<strong> ec2.tf template</strong> as a starting point to create the EC2 module: <a href="https://github.com/LevelUpInTech/terraformec2.git">https://github.com/LevelUpInTech/terraformec2.git</a></li><li>Create a custom module for EC2 out of the resource block that you can <br>use as repeatable infrastructure.</li><li>Push the new created module and the ec2.tf file to your Github repository.</li></ol><p>For building this EC2 module, I have used a <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance"><strong>data source for pulling in an AMI ID</strong></a> instead of a hard-coded value. I have spent so much time to make this work, and after many, many attempts, I succeeded! I have also used <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami"><strong>Terraform documentation</strong></a> for this purpose.</p><h3>Modules:</h3><p>A module is nothing but a collection of Terraform files in a single folder. You can group many resources into a module to be used over and over again.</p><p>In short, modules are the key ingredient to writing reusable, maintainable, and testable Terraform code, especially complex configurations making them easier to navigate, read, understand, and make changes.</p><p>I have used <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs"><strong>Terraform documentation</strong></a><strong> </strong>(use the navigation to the left to read about the available resources), <a href="https://learn.hashicorp.com/tutorials/terraform/module"><strong>Derek Morgan’s course</strong></a> and <a href="https://courses.morethancertified.com/courses/1390185/lectures/31955645"><strong>Morethancertified course</strong></a> for this project.</p><p>Follow the basic Terraform workflow: write, plan, deploy.</p><h3>Pre-Requisites:</h3><ul><li>Access to AWS Console with an AWS Account (not root account).</li><li>Cloud9 IDE</li><li>GitHub account</li><li>Install <a href="https://learn.hashicorp.com/tutorials/terraform/install-cli"><strong>Terraform</strong></a></li></ul><p>Let’s begin!</p><h3>Fork and locally clone a GitHub repository</h3><p>Navigate to <a href="https://github.com/LevelUpInTech/terraformec2"><strong>https://github.com/LevelUpInTech/terraformec2.git</strong></a> and click the Fork button in the top right corner of the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ytWcseZhUPtMo1JLGdvaUg.png" /></figure><p>Now, you can see a new repository in your GitHub.</p><p>Next, I will clone the repository in my IDE, I am using Cloud9:</p><ul><li>Open up the cloned repository</li><li>Click on “Code” and copy the “HTTPS” URL</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9KI--zFqsT1lbI2HzcpHyQ.png" /></figure><p>Open up Cloud9 IDE terminal and clone the forked repository</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*texjH79PBM3TlR60wrrz7w.png" /></figure><p>Now you should see a new directory under your current working directory named <strong>terraformec2</strong>.</p><p>Change the name<strong> “terraformec2”</strong> to <strong>“basic_ec2_module_1”.</strong></p><p>Change your <strong>working directory to basic_ec2_module_1.</strong></p><p>cd basic_ec2_module_1</p><h3>Start working on the Module</h3><p>I am going to implement this using a modular approach with <a href="https://www.terraform.io/"><strong>Terraform</strong></a> modules.</p><p>To get started, let’s create the following organizational structure as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*c4wKALj4X0aJaWaFCvOKwA.png" /></figure><p>This infra has only 1 module <strong>“ec2_instance”</strong></p><p>In the <strong>ec2_instance</strong> directory create <strong>main.tf</strong>, <strong>outputs.tf</strong>, and <strong>variables.tf</strong> files.</p><p>The <strong>ec2.tf</strong> file has a provider and a resource section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4KIqRzi1gcDqtSWdu_-64Q.png" /></figure><ul><li><strong>main.tf :</strong></li></ul><p>Cut and paste the resource information from ec2.tf into this file. Make neccessary changes to the resources section. I have used a <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance"><strong>data source for pulling in an AMI ID</strong></a> instead of a hard-coded value. I have spent so much time to make this work, and after many, many attempts, I succeeded! I have also used <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami"><strong>Terraform documentation</strong></a> for this purpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iwpmakaaTNE_WIgTs53smw.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf1f54e18f8da2339ccd2713a3567be7/href">https://medium.com/media/bf1f54e18f8da2339ccd2713a3567be7/href</a></iframe><ul><li><strong>variables.tf:</strong></li></ul><p>create variables so that they are not hard coded in the parent module</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc5f36dd19511a748967582480aafce8/href">https://medium.com/media/dc5f36dd19511a748967582480aafce8/href</a></iframe><ul><li><strong>outputs.tf:</strong></li></ul><p>As the name indicates, after executing Terraform apply, it outputs — the public ip and ec2 name tag values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1749cb59da87e41b7fea1d1e49f6da2e/href">https://medium.com/media/1749cb59da87e41b7fea1d1e49f6da2e/href</a></iframe><ul><li><strong>providers.tf</strong> : cut and paste the Provider information from ec2.tf into this file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZyQo9V5C8YFQOmeI5SY1jA.png" /></figure><p>Make changes in the providers.tf file to get the latest version for Terraform. Get the variables from the variables.tf file so that they are not hard-coded and reference them in the main.tf.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f2b2e396121d274a0b7a64a68de6b01/href">https://medium.com/media/5f2b2e396121d274a0b7a64a68de6b01/href</a></iframe><ul><li><strong>ec2.tf:</strong></li></ul><p>Now make this file to reference <strong>instance module — ec2_instance.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3fc66e4add4a92da94dd36d4e0c0694/href">https://medium.com/media/c3fc66e4add4a92da94dd36d4e0c0694/href</a></iframe><ul><li><strong>outputs.tf:</strong> After executing Terraform apply, the values for public ip and ec2 name tag will be displayed.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/138aa773ebe79454fd3719cf320a288f/href">https://medium.com/media/138aa773ebe79454fd3719cf320a288f/href</a></iframe><p><strong>Now run these Terraform commands in the following order:</strong></p><ul><li>Run terraform init to initialize Terraform.</li><li>Run terraform fmt to format the code.</li><li>Run terraform validate to check for any syntax errors.</li><li>Run terraform plan to see what resources will be created.</li><li>Run terraform apply and type yes when prompted.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsKjbjxcxn87Rp1Q1EFPGg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XtggkL9t5IyWFvYDdtN14Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lzjtCiFRHenkYaK8Wb3Vjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Srypz3hc3sCsLRkModA6Mg.png" /></figure><h4><strong>To check ec2 instance from AWS Console</strong></h4><p>Login to your AWS account and navigate to the us-east-1 region &gt; EC2 &gt; Instances to see if our instance was created.</p><h3>Push To GitHub</h3><p>Run these Git commands in the following order from the Cloud9 IDE terminal from the directory <strong>Terraform_projects/basic_ec2_module_1</strong> — -which has all the files for this project.</p><ul><li>Run git status to verify all your files are accounted for.</li><li>Run git add ec2_instance This will add your files to a staging area.</li><li>Run git add ec2.tfThis will add your files to a staging area.</li><li>Run git add outputs.tfThis will add your files to a staging area.</li><li>Run git add providers.tfThis will add your files to a staging area.</li><li>Run git commit -m “initial commit” . This will commit your files.</li><li>run git push origin to push your code changes to your GitHub repository.</li></ul><p>Open the <a href="https://github.com/awsmine/Terraform_projects/tree/main/basic_ec2_module_1"><strong>GitHub repository</strong></a> to verify all the files that have been added.</p><ul><li>Run a terraform destroy from the Cloud9 IDE terminal to remove our instance. Type yes when prompted.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PFJMAaBRQrDM3y8wbAdQRw.png" /></figure><p>Thanks for reading ! More in my next article…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8eaff66f470f" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/creating-a-repeatable-infrastructure-with-a-very-basic-ec2-module-using-aws-ami-data-source-8eaff66f470f">Terraform: Creating a very basic EC2 module using “aws_ami” data source — 1</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>
    </channel>
</rss>