<?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 Todd Caputo on Medium]]></title>
        <description><![CDATA[Stories by Todd Caputo on Medium]]></description>
        <link>https://medium.com/@tcaputo001?source=rss-ed2546d2d001------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*__CpB_QDxxaD2GFukcmmIA.jpeg</url>
            <title>Stories by Todd Caputo on Medium</title>
            <link>https://medium.com/@tcaputo001?source=rss-ed2546d2d001------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:14:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tcaputo001/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[Creating Infrastructure using Terraform code and AWS CodePipeline]]></title>
            <link>https://awstip.com/creating-infrastructure-using-terraform-code-and-aws-codepipeline-b751cb97b2f7?source=rss-ed2546d2d001------2</link>
            <guid isPermaLink="false">https://medium.com/p/b751cb97b2f7</guid>
            <dc:creator><![CDATA[Todd Caputo]]></dc:creator>
            <pubDate>Fri, 21 Oct 2022 20:50:07 GMT</pubDate>
            <atom:updated>2022-10-27T13:34:47.499Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*WEejkGY1DnBrAHnCBMqGAQ.png" /></figure><p>This is our final project to complete our Level Up In Tech journey. For this project we will be doing the following:</p><p>Create a terraform module template that creates:</p><p>VPC with CIDR 10.0.0.0/16</p><p>2 subnets (public) with CIDR 10.0.1.0/24 and 10.0.2.0/24</p><p>An autoscaling group with Amazon Linux 2 instance (t3.micro) with a min of 2 instances and a max of 3</p><p>Create a bucket to store your terraform state</p><p>And use AWS Codepipeline to create a CI/CD pipeline that will test and deploy the infrastructure through AWS.</p><p><strong>As usual we will need a few things:</strong></p><p>· Preferred choice of IDE — Visual Studio Code, Cloud9, etc</p><p>· AWS Account</p><p>· GitHub Account</p><p>· Terraform installed</p><p>This is where Terraform is completely awesome. In our last few projects we have already created a majority of the infrastructure needed. We have created plenty of VPCs, Subnets (Public/Private), Autoscaling Groups, AMI Instances, etc. The only thing we haven’t created yet is an S3 bucket to store our Terraform State file.</p><p>So because we already have our code configured from previous projects we can simply take those resources/modules and bring them over to this one. Since the infrastructure is smaller than previous ones we can work on simplifying the Terraform code to make it cleaner.</p><p>The REPO to my code can be found <a href="https://github.com/krypt0-cappy/Final-Project-Week24.git">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*ixx-oyZIP77qhzuM.gif" /></figure><h3><strong>STEP ONE —</strong></h3><p>Let’s use our command line to create our S3 Bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*20Lw1_3_X8OTPz1_PPXiuQ.png" /></figure><p>If we are creating our bucket outside of the US-EAST-1 region we need to specify our region and it will require the appropriate “LocationConstraint” to be specified in order to create the bucket in our desired region. The screenshot below shows an example of how to do this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*dbPi7Ya5-RagCyqcN5BPTg.png" /></figure><p>If our bucket creation is successful we should get the following return:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*4M5X1A1TuRvl-bZJQ5va6Q.png" /></figure><p>Rule of thumb: make sure to use all lowercase letters when creating your bucket name.</p><p>Now that the bucket is created, make sure to update your backend section with the appropriate code as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*se9953rM9qyoYN8_azP0Ig.png" /></figure><p>Now run the command “terraform init” and watch the magic happen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*Vbzhtl0ZELOjmCibGAXtCg.png" /></figure><p>If we head over to the AWS Console and navigate to our specific region and then to S3 we will see our bucket and the Terraform State file that has been uploaded to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xCjhcAU-wTWPfythXJqmWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AazRD6gKWruA9LQ6KjeigQ.png" /></figure><h3><strong>STEP TWO —</strong></h3><p>Let’s now head on over to CodePipeline and make some more magic happen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*fpgR1VH8NHwsWe2r" /></figure><p>Once you are there click on CREATE PIPELINE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pCF7TFOeocJtrbbwAte67w.png" /></figure><p>Name your Pipeline and choose New Service Role, then click NEXT</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*9b3p5KGCgIFa947kqFgtTw.png" /></figure><p>Click on the drop-down menu and select GITHUB (VERSION 2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*LfQSQxdTXGNHiuIG11wZwg.png" /></figure><p>We need to connect to Github. Click on CONNECT TO GITHUB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*IRsXbG25BwgRWCloVwArMA.png" /></figure><p>Give it a name and then select your GitHub account. If you haven’t already connected click on INSTALL NEW APP and refer to the following link <a href="https://docs.aws.amazon.com/codepipeline/latest/userguide/connections-github.html">here </a>for instructions on how to complete this.</p><p>Scroll down and choose our repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*ZCNXwKk2BX0LEM0P1mtVOA.png" /></figure><p>Select the branch name and leave the remaining defaults selected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*jkp1u3FK4-JFPCBZhRQjpA.png" /></figure><p>Select AWS CodeBuild as your build stage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*iFZGtYIsljIw46G3rZzD-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*5Dgm0j3AWfZIawhrThWHYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*PaDA28Gd1JqPufaE3BescQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*5wcBCJIJO86wfoljdV8HJQ.png" /></figure><p><strong>Click on Additional Configuration and set your Environment Variables (think of how we did this on Terraform Cloud)</strong></p><p><strong>Leave Buildspec settings as is.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*KP2S6Kd8gHl99nOJiHOXMQ.png" /></figure><p><strong>Click CONTINUE TO CODEPIPELINE</strong></p><p><strong>Click NEXT once you get back to the ADD BUILD STAGE menu</strong></p><p><strong>Click on SKIP DEPLOYMENT STAGE</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*FdkZmPjLViIT80zPhf34sw.png" /></figure><p><strong>Review and click CREATE PIPELINE.</strong></p><p>We should see the following result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*K4J0vqtmiEkjCeyjAU5LTw.png" /></figure><p>If everything was successful you should see the following under the BUILD phase:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*Ssrz_SQO7_bQE8v96cVzVw.png" /></figure><p>You can confirm your resources have been created by heading over to the AWS Console and checking. Check out your VPC, EC2 Instances, AutoScaling Groups, etc.</p><p>When you are done don’t forget to do a “terraform destroy” so you don’t have any unwanted resources hanging around.</p><p>That will wrap up our 24 week journey. Over that last several months we have created real-world projects that have given us hands-on experience. We can use these projects to build off of and use as a baseline for other projects as we being our DevOps Engineer careers.</p><p>So hats off to you! You’ve earned it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*OhANwRoWk0lqME6E.gif" /></figure><p>Stay tuned for more articles!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b751cb97b2f7" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/creating-infrastructure-using-terraform-code-and-aws-codepipeline-b751cb97b2f7">Creating Infrastructure using Terraform code and AWS CodePipeline</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create an EKS Cluster using Terraform]]></title>
            <link>https://awstip.com/how-to-create-an-eks-cluster-using-terraform-bd730d9cf612?source=rss-ed2546d2d001------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd730d9cf612</guid>
            <dc:creator><![CDATA[Todd Caputo]]></dc:creator>
            <pubDate>Wed, 19 Oct 2022 21:30:28 GMT</pubDate>
            <atom:updated>2022-10-25T12:19:41.378Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f3etjAumLrGO5ryuaRmvKg.png" /></figure><p>Welcome to our next project in the “pipeline”. We are going to use Terraform to build out our code. Here is what we are going to be building.</p><ol><li>Create an EKS cluster with a desired capacity of 2</li><li>Create a random string that allows 5 characters to build the cluster name</li><li>We want to output the cluster name and the ip address of the containers in the cluster.</li></ol><p>We will be building the code using module blocks.</p><p>Once we are done we will use Terraform Cloud to finish the build and implement it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*cY49GisQ-sUhRiT06Gq1sA.gif" /></figure><p>As usual we will need a few things:</p><p><strong>· Preferred choice of IDE</strong> — Visual Studio Code, Cloud9, etc</p><p><strong>· AWS Account</strong></p><p><strong>· GitHub Account</strong></p><p><strong>· Terraform installed</strong></p><p><strong>· Terraform Cloud Account</strong></p><h3><strong>STEP ONE —</strong></h3><p><strong>Create your code in your preferred IDE or fork my REPO </strong><a href="https://github.com/krypt0-cappy/Week22-Terraform.git"><strong>here</strong></a><strong>.</strong></p><h3><strong>STEP TWO —</strong></h3><p>So once we have our infrastructure code built or forked, we need to “terraform” it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gqpVAtgBDfnbQnBOKnFong.png" /></figure><p>Run these commands in your working directory to make sure there are no errors.</p><p>Once you have run your Terraform Apply command you will get three different Outputs:</p><p>— — — cluster-id — — —</p><p>— — — cluster-name — — —</p><p>— — —cluster-endpoint — — —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*Wu2FS3CEa5K3Kxh_v3m0aQ.png" /></figure><p>So now let’s head on over to our AWS Console and check out a few things.</p><p>Let’s take a look at our VPC, EKS,</p><p>VPC —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*ERQB1Rh27mQSchrXIg8Xiw.png" /></figure><p>EC2 —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7bCmX8cFvU2O3hA7PAJaOg.png" /></figure><p>EKS —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*OoHkS6PxWdErIhZSfBi_Jg.png" /></figure><p>So now that we can see our resources have been created what can we do with this information?</p><p>Well first let’s try to run the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/118/1*8b6FcwK038ZfBZ_twP7Uxw.png" /></figure><p>We can see we get a message that we are not able to connect to the server. Why are not able to?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*61c5LIeHd2DHVS8hW-6-4A.png" /></figure><p>We are not able to see our pods because we haven’t configured kubectl to connect to our EKS Cluster. So lets configure it.</p><p>Run the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*8bOa7goVtUg_lwBuX9NgOQ.png" /></figure><p>We should get the following message output after the command has succeeeded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*cd4IY3gy6sP8bSwZBq6A-Q.png" /></figure><p>Now if we run “kubectl get pods” again we should see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*JU088LbsFbriYMWni-EzSQ.png" /></figure><p>So now that we have seen everything is created and working let’s head on over to Terraform Cloud and create our pipeline.</p><p>In order to create a clean run on Terraform Cloud make sure you perform a “terraform destroy” in the IDE you used earlier to create the infrastructure. If you don’t you will see a couple of errors while trying to create certain resources. We don’t want that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L-i2bM_9YsgMvZph.png" /></figure><p>Once we are there let’s click on NEW WORKSPACE at the top right</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4iIVsOoslJB4A0BsmvKYYw.png" /></figure><p>Click on VERSION CONTROL WORKFLOW</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*-KSnQaC_YoRJ-x3mdDF0Gw.png" /></figure><p>Now click on GITHUB to connect to our VCS (Version Control Provider)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*0FcXSO-x2fKIJCiMaOoPDQ.png" /></figure><p>Now let’s find our GitHub Repo for this weeks project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*jOMQ9UIuyICn6K5tItsSjA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*HlKzTPtWpniuRXUUi7yixw.png" /></figure><p>Now click CREATE WORKSPACE</p><p>As usual we need to create our variables. Let’s do that now.</p><p>Click on CONFIGURE VARIABLES</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*h2nso435cvDK0Qj09l3tqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28qjwwBBNnee1DIQxy1B3A.png" /></figure><p>Now let’s click on ACTIONS &gt; START NEW RUN</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/286/1*L5a4cGgM26EcLjO66NKFEw.png" /></figure><p>Give the run a name and click START RUN</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*26cU3m0GtIg4Pc8Fc_e20Q.png" /></figure><p>We should see our infrastructure plan being created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u4Re-n_Hx43B2D8v34mGzQ.png" /></figure><p>Click on CONFIRM AND APPLY</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*hNxQbpqEHnstxHiLUSXhZg.png" /></figure><p>Add a note and click on CONFIRM PLAN</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*qsBXRXlIJpnZu48HAYP_fQ.png" /></figure><p>Once our RUN has finished we should see something like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4bQAHS5_N0KJAm1C6fwyrw.png" /></figure><p>If we head on over to our AWS Console and check the same services we did earlier we will see our infrastructure created successfully.</p><p>Now we don’t want to leave any of this infrastructure running so we don’t rack up that AWS bill. So let’s go ahead and perform a “terraform destroy” using Terraform Cloud.</p><p>Click on Settings on the left side:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*Deor7mhefdmEiYj8FUsTsQ.png" /></figure><p>Then click on DESTRUCTION AND DELETION</p><p>Click on QUEUE DESTROY PLAN</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eo-w1io2x9318fEFI0QBPQ.png" /></figure><p>Enter the workspace name and click on the destroy plan button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*mS7PvUXzV0ysqdl4oal9-w.png" /></figure><p>You will now see your infrastructure starting a plan to get destroyed. Once it has been completed.</p><p>Now add a note and click on CONFIRM PLAN</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*GC5_5Yzdekswela6g8WPQA.png" /></figure><p>And that is all you need to do. We have just created a Kubernetes Cluster with AWS Infrastructure using Terraform code and Terraform Cloud/GitHub as a CI/CD pipeline. Congrats!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*HmaHzNSStLh8mYwp" /></figure><p>Until next time, keep practicing and keep on learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd730d9cf612" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/how-to-create-an-eks-cluster-using-terraform-bd730d9cf612">How to create an EKS Cluster using Terraform</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CI/CD Domination! Using Terraform Cloud and GitHub to create infrastructure.]]></title>
            <link>https://awstip.com/ci-cd-domination-using-terraform-cloud-and-github-to-create-infrastructure-e58ff7b27cff?source=rss-ed2546d2d001------2</link>
            <guid isPermaLink="false">https://medium.com/p/e58ff7b27cff</guid>
            <dc:creator><![CDATA[Todd Caputo]]></dc:creator>
            <pubDate>Thu, 13 Oct 2022 14:14:59 GMT</pubDate>
            <atom:updated>2022-10-19T10:46:32.226Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*IHyLSGoPMd9nyUn_clhc1Q.gif" /></figure><h3>As usual we will need a few things to help us get started.</h3><p><strong>· Preferred choice of IDE</strong> — Visual Studio Code, Cloud9, etc</p><p><strong>· AWS Account</strong></p><p><strong>· GitHub Account</strong></p><p><strong>· Terraform installed</strong></p><p><strong>· Terraform Cloud Account</strong></p><p>In Order to get going we will need to start with a our code already in GitHub. I have pushed my code to my repository and you can fork it <a href="https://github.com/krypt0-cappy/Week21-Project-Terraform">here</a> and use as a reference. Make sure to change a few things like your key pair, region, AMI’s, etc. I am using the US-WEST-2 Region for my code. You will notice in my compute section I had to comment out the Amazon Linux 2 AMI data resource because it would not find it no matter the region and AMI I used. Instead I defaulted to a previous projects AMI using Ubuntu it worked for me.</p><h3><strong>STEP ONE:</strong></h3><h4><strong>Fork the </strong><a href="https://github.com/krypt0-cappy/Week21-Project-Terraform-CICD.git"><strong>REPO </strong></a><strong>or create your own modules following along with my code and push to your own repo in your own GitHub account.</strong></h4><h3><strong>STEP TWO:</strong></h3><h4><strong>Set up your Terraform Cloud account. Use the link </strong><a href="https://app.terraform.io/session"><strong>here </strong></a><strong>to create your own Terraform Cloud account. Make sure to create an Organization and follow the guide on how to create a Workspace. We will need that next. You may also need to create and configure a GitHub Access Token found </strong><a href="https://learn.hashicorp.com/tutorials/terraform/github-oauth?in=terraform/cloud"><strong>here</strong></a><strong>.</strong></h4><h3>STEP THREE :</h3><h4><strong>Create a WORKSPACE, choose VERSION CONTROL WORKFLOW, SELECT YOUR GITHUB PROVIDER (VCS PROVIDER)</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*XJMIt9tm-Nm-_6brtjVlQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R06IJHgx0ELiC2Is2I9m3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*4qnLrIGW0DeyJD269cxmjg.png" /></figure><p><strong>Once you have selected the repo, click CREATE WORKSPACE. You should see the following:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*4P3t1eVlhX0s_ZM8NuZ6tQ.png" /></figure><p><strong>Now let’s configure some variables</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZTayNIzPRtgh7O1kVwyG2A.png" /></figure><p><strong>Now click on the ACTIONS drop-down menu and select START NEW RUN</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W4lhvnv3DVY6i0kLV98KEw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*2C97ar6jNjnZ005AuR-5Jg.png" /></figure><p><strong>Then click START RUN</strong></p><p><strong>If everything has been configured successfully we should see all of our resources that are to be created as shown below:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*61MpHmgo1uZ9t2eduAWuDg.png" /></figure><p><strong>Click on CONFIRM AND APPLY</strong></p><p><strong>Leave a comment and click CONFIRM PLAN</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*PaLuQIiCzEzUf6IO_lWHQQ.png" /></figure><p><strong>You will see your resources starting to create.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6GpRkQqQ9oObb_0X6srjmQ.png" /></figure><p><strong>We can now see that all of our resources have been created.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WNE-FqD-eTjcbN_FjEkKUA.png" /></figure><p><strong>If you head to your AWS Console you can check to see if your resources have been created.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*CHE9PhhgLi59ydAO26cdiA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y9KKUObXZ8-PCRu8-3LBzA.png" /></figure><p><strong>Now that everything has worked let’s go ahead and destroy our infrastructure so we don’t rack up a HUGE AWS bill.</strong></p><p><strong>On the left side in Terraform Cloud, click SETTINGS.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*k4G_bXsJBSTQSMC0DPZjMw.png" /></figure><p><strong>Click on DESTRUCTION AND DELETION</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/277/1*xmidNbdRyQHhTrpKq0xSQw.png" /></figure><p><strong>Click on QUEUE DESTROY PLAN</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kzTXdbtY2cuqa6w1EQGROg.png" /></figure><p><strong>Enter the name of your workspace and click the red box.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*90l2aFEQTZ8UQdLgjqQ4wA.png" /></figure><p><strong>Click on CONFIRM &amp; APPLY</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*RT5H0GxVtkzxWWFoPU_cPw.png" /></figure><p><strong>Add a note and click on purple box.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*5rgoTKkQcbt1Ui_S6lKAOQ.png" /></figure><p><strong>As you can see, our infrastructure has been deleted.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uaT_VA_PMdY94aAL0xNtkw.png" /></figure><p><strong>Finally click on DELETE FROM TERRAFORM CLOUD to delete the workspace.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*4R5rNEV-IfWMFK9PGuJWXw.png" /></figure><p><strong>And that is all folks! You should now be comfortable with creating your Terraform code, pushing the code to GitHub and then using Terraform Cloud to grab that code and build out your infrastructure.</strong></p><p><strong>If you really want to see the power of Terraform Cloud, go into your code on GitHub, find a file you can make a small change to, and then edit that file (“Say you want to change your VPC CIDR_BLOCK IP to a different schema”), and then save it. Terraform Cloud will automatically get that changed code and immediately start a Terraform Plan for you.</strong></p><p><strong>The power is now in your hands! Have fun and good luck!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/0*UR9-2A-MsjrGlTBX.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e58ff7b27cff" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/ci-cd-domination-using-terraform-cloud-and-github-to-create-infrastructure-e58ff7b27cff">CI/CD Domination! Using Terraform Cloud and GitHub to create infrastructure.</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating reusable infrastructure using Terraform Modules]]></title>
            <link>https://awstip.com/creating-reusable-infrastructure-using-terraform-modules-9f742acaabc?source=rss-ed2546d2d001------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f742acaabc</guid>
            <dc:creator><![CDATA[Todd Caputo]]></dc:creator>
            <pubDate>Thu, 29 Sep 2022 19:13:26 GMT</pubDate>
            <atom:updated>2022-10-04T12:17:45.660Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*0eW6AZIAvSPO162SYY1OpQ.png" /></figure><p>Well well well. Back at it again are we? This week we are creating reusable infrastructure using Terraform Modules. The module will be custom to create Amazon 2 Linux EC2 Instances. We will need to fork and clone a repo and use the ec2.tf template as a reference to create our custom module.</p><p>As usual we will need a few things to help us get started.</p><p><strong>· Preferred choice of IDE</strong> — Visual Studio Code, Cloud9, etc</p><p><strong>· AWS Account</strong></p><p><strong>· GitHub Account</strong></p><p><strong>· Terraform installed</strong></p><h3><strong>STEP ONE: Clone REPO</strong></h3><p>Let’s go ahead and get started. Fork and Clone the following repo:</p><p>“<a href="https://github.com/LevelUpInTech/terraformec2.git">https://github.com/LevelUpInTech/terraformec2.git</a>”</p><p>For this project I am using my Visual Studio Code editor. I have created a folder called Week20-Project and then cloned the repo above into this folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*O7CO4U2FGDkR0-pwv-0slQ.png" /></figure><p>Once the repo has been cloned we can then “cd” into the new directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*cZsBmzCO2tPD3dng7hXg6w.png" /></figure><p>The code below will be our building block to create our custom module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*To4WQ2DNxYcSX_9pK6wgdw.png" /></figure><p>Since we will be creating our own folders and files to use let’s go ahead and comment out our ec2.tf file. This will prevent it from being used in the infrastructure and will be there only to give us our baseline. See below to see the file commented out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*s6PbIF83sDOPZ-pyfzZq3g.png" /></figure><h3><strong>STEP TWO: Create files for module</strong></h3><p>In our terraformec2 folder let’s create a couple of files: main.tf, providers.tf, variables.tf</p><p>Our providers.tf file should look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*GhlZOAXv-CilbzTcmQSD7Q.png" /></figure><p>The variables.tf file should look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*vNG28u-WCZ-01Qbw1mB4-A.png" /><figcaption>I am using the us-west-2 region for this project. Make sure to adjust your region accordingly</figcaption></figure><p>Finally our main.tf file should look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*2l1hUnF364QRVGmrqOtYow.png" /></figure><h3><strong>STEP THREE: Create EC2 Infrastructure code</strong></h3><p>What I am going to do now is create a folder called “compute”. This folder will contain two files — main.tf and variables.tf</p><p>The “compute” folder will contain the variables and resource for our EC2 Instance.</p><p>The main.tf file should look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*IjArk5S9KxoogIrhO9UZDA.png" /></figure><p>The variables.tf file should look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*tvcOADEEvscXFlI55mo5vA.png" /><figcaption>The AMI ID I am using is from the us-west-2 region. Please make sure to use your correct region’s AMI IDs.</figcaption></figure><p>Now that we have completed our code let’s initialize it.</p><p>Run the following code “terraform init”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*b1cKiahL4D39VuSoSvK-lQ.png" /></figure><p>We can now run a “terraform plan” to see what our code will create for us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*_ksIGdTJ5Mj8ohrIHvEJrg.png" /></figure><p>Now we will run the following command to create our infrastructure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*GqW-Ty0QMi3KGOMj65bhCg.png" /><figcaption>In a production environment we do not want to do the auto approve argument. Because this is just an exercise only we can get away with it for now.</figcaption></figure><p>We can now go ahead and check our AWS Console to see if our EC2 Instance was created.</p><p>As we can see here it has been successfully created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3TdimRQsAZFXsphOuQVpUA.png" /></figure><p>Now let’s go ahead and run an “terraform destroy” to delete our infrastructure.</p><p>And that is all for today folks! A nice and easy project to create reusable infrastructure code. Stay tuned for next weeks project!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f742acaabc" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/creating-reusable-infrastructure-using-terraform-modules-9f742acaabc">Creating reusable infrastructure using Terraform Modules</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create an ECS Cluster using a Docker Image]]></title>
            <link>https://awstip.com/how-to-create-an-ecs-cluster-using-a-docker-image-c13aeffff66e?source=rss-ed2546d2d001------2</link>
            <guid isPermaLink="false">https://medium.com/p/c13aeffff66e</guid>
            <dc:creator><![CDATA[Todd Caputo]]></dc:creator>
            <pubDate>Wed, 21 Sep 2022 04:28:28 GMT</pubDate>
            <atom:updated>2022-09-29T17:02:45.540Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*-1sDA3Ifcqp7XNnXps4z0A.png" /><figcaption>Using Terraform to pull a Docker Image and create an AWS ECS Cluster</figcaption></figure><p>This weeks project focuses on pulling a Centos Docker Image and then creating a ECS Cluster using……***drum roll***……. TERRAFORM!!</p><p>To do this we will need to make sure we have a few things:</p><p><strong>· Preferred choice of IDE</strong> — Visual Studio Code, Cloud9, etc</p><p><strong>· AWS Account</strong></p><p><strong>· Admin Account with Access and Secret Access keys</strong></p><p><strong>· Docker installed</strong></p><p><strong>· Most importantly, the big bad Terraform!</strong></p><p>Visual Studio Code will be my choice IDE for the project. First we will need to create the 4 files we will be using: docker.tf, main.tf, providers.tf, and vpc.tf</p><p>Each file will hold specific resources we will need. As Bruce Buffer would say……….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*PH1_uqf5OZSWm7Fgd9DoFQ.gif" /></figure><h3><strong>STEP 1. Configure our providers.tf file.</strong></h3><p>If you haven’t already created your providers.tf file let’s go ahead and create it now. We will need to add our required providers such as Docker and AWS. In this file we can set our Region and the location to point to our AWS credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*uv5W3rbAHrXjcYm9uIdihQ.png" /><figcaption><a href="https://registry.terraform.io/providers/kreuzwerker/docker/2.22.0">https://registry.terraform.io/providers/kreuzwerker/docker/2.22.0</a></figcaption></figure><h3><strong>STEP 2. Configure our docker.tf file</strong></h3><p>Our docker.tf file is where we will set our resource to pull a Centos image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*5CuD0D-hmBDQHKhvJfmb0g.png" /><figcaption><a href="https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/image">https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/image</a></figcaption></figure><p>Now that we have completed our first two steps let’s go ahead and run the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*Lv4LrBD-THCUes_85L-hhQ.png" /></figure><h3><strong>STEP 3. Configure our VPC, Subnets, Internet Gateway, Routing Table, Security Group</strong></h3><p>In order to create an ECS Cluster we must configure a networking template. You can refer to the guide below for certain templates to use.</p><p><a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create_cluster.html">Amazon Elastic Container Service</a></p><p>This will give you an idea of the resources we need to create in Terraform.</p><p>First we create our VPC and 2 Public Subnets</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*yvzX7TK5OPkmgz_5yCYXrg.png" /></figure><p>Next we create our Internet Gateway and Routing Table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*zcyEjKBMe-UU9rUBcc5VpQ.png" /></figure><p>Now it’s time to create a Default Public Route and Route Table Association</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*qzcVTuPBcGll6HVvUdqYOw.png" /></figure><p>Lastly, let’s create a Security Group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*6qTDAk8Wy6YUoS8aGNdMTA.png" /></figure><h3><strong>STEP 4. Configure our main.tf file</strong></h3><p>This is where we get to throw all our ECS ingredients into our mixing bowl and see what kind of creation comes out.</p><p>First let’s create our ECS Cluster resource</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*FCFQJWu9h6otoe6mc2li3g.png" /><figcaption><a href="https://registry.terraform.io/providers/aaronfeng/aws/latest/docs/resources/ecs_cluster">https://registry.terraform.io/providers/aaronfeng/aws/latest/docs/resources/ecs_cluster</a></figcaption></figure><p>Now we can create our ECS Cluster Service resource</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*LXRWPZPvyYDaeeo8abq0Ag.png" /><figcaption><a href="https://registry.terraform.io/providers/aaronfeng/aws/latest/docs/resources/ecs_service">https://registry.terraform.io/providers/aaronfeng/aws/latest/docs/resources/ecs_service</a></figcaption></figure><p>Next we have to create an ECS Task Definition</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*byichR9N808D4_JtntpsDw.png" /><figcaption><a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition</a></figcaption></figure><p>Lastly we need to create a Policy Document, assume an IAM role, and then attach the role to our Policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*NewSF0BsrW3tMdn0b81k4Q.png" /></figure><p>Now that we have all of our files and resources configured we need to run “terraform apply”. Make sure to enter YES when prompted.</p><p>Alternatively you can run:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/221/1*LJperhipzIPATv3efyLbqQ.png" /></figure><p>As Terraform is working on creating your resources you should start to see everything coming together. The image below shows the resources Terraform is creating.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-NNZsrpkgJEGrRBFkocbRw.png" /></figure><p>Let’s take a look at our AWS Console to see what has been created for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*FMsDUvB0FWdqFqJPoC1dqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*AF_e4HCF0cwNhprx4NpXqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EtovpLYY5zqe_ACSVQbN0A.png" /></figure><p>As we can see from just these little snippets, our VPC was created as well as our ECS Cluster from our Docker Image we pulled down. We set it to create 4 containers for us and currently 2 are running with 2 more pending.</p><p>And that’s a wrap! Thank you for taking the time to read this. Hopefully you are learning as much as I am. Stay tuned. With only a few weeks left, the upcoming projects are most likely going to grow more complex. But hey, if it’s not challenging then what exactly are we learning?</p><p>Also, don’t forget to run “terraform destroy” so our resources get wiped out. Ya know, like the big purple guy did.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*9mSP0a6agb-teJfv.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c13aeffff66e" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/how-to-create-an-ecs-cluster-using-a-docker-image-c13aeffff66e">How to create an ECS Cluster using a Docker Image</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[For this weeks project we are going to use Terraform to help us create a Two-Tier Architecture.]]></title>
            <link>https://awstip.com/for-this-weeks-project-we-are-going-to-use-terraform-to-help-us-create-a-two-tier-architecture-5a7d2ac808a5?source=rss-ed2546d2d001------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a7d2ac808a5</guid>
            <dc:creator><![CDATA[Todd Caputo]]></dc:creator>
            <pubDate>Sat, 10 Sep 2022 03:37:35 GMT</pubDate>
            <atom:updated>2022-09-20T16:29:22.887Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*v8kodEyQns5C64jLdOPkcA.png" /></figure><p>For this weeks project we are going to use Terraform to help us create a Two-Tier Architecture. I am going to create my Terraform code using VSCode. Since I have already configure VSCode for AWS my credentials are stored and we do not need to make them visible in our code.</p><p>We will need a few things to help us with this weeks project:</p><p><strong>· Preferred choice of IDE</strong> — Visual Studio Code, Cloud9, etc</p><p><strong>· AWS Account</strong></p><p><strong>· Admin Account with Access and Secret Access keys</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HvvEmjpZnUlY8whn6IB6_w.png" /></figure><h3><strong>PART ONE :</strong></h3><h3><strong>Step 1. Declare your Provider, set your Region, and set your Credentials</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*wZf5eK-oKfOC4fznwn6TyQ.png" /></figure><p>Now let’s initialize our working directory using the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*pR-ChKUkONR1eu-IS6H6Sg.png" /></figure><h3><strong>Step 2. Create our VPC, Public Subnets, and Private Subnets</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*iNoL7Hfra53VyXbXN9vGFw.png" /><figcaption>Guide for Terraform Registry for VPC can be found here: <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*T-N08ABYef8qlY0nd9PSiA.png" /><figcaption>Guide for creating subnets can be found here: <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet</a></figcaption></figure><h3><strong>Step 3. Create our Routing Table, Internet Gateway, and Routing Table Associations</strong></h3><p>A while back we created a 3-Tiered Architecture Project where we needed to create our own custom VPC with Public and Private Subnets. We will essentially be doing the same thing except this time we will be using Terraform.</p><p>Let’s start with creating our Internet Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*kJ1clxxmf_E_Oq3d4WOLnA.png" /><figcaption>Guide for creating IGW can be found here: <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/internet_gateway">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/internet_gateway</a></figcaption></figure><p>Now let’s create our Main Routing Table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*_CGb958tMkEMkxvUPmEMeQ.png" /><figcaption>Guide for Terraform Registry for Main Route Table can be found here: <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table</a></figcaption></figure><p>We can now create our default public route.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*FuLxsgrEI6_BxdVGaiwxag.png" /><figcaption>Guide for Terraform Registry for default route can be found here: <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route</a></figcaption></figure><p>Now for our Routing Table Associations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*9wCi0EV2vFNhwKFNrUPOQA.png" /><figcaption>Guide for Terraform Registry for Route Table Associations can be found here: <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table_association">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table_association</a></figcaption></figure><h3><strong>PART TWO:</strong></h3><h3><strong>Step 4. Create Security Groups for both our EC2 Instances and our RDS Instance.</strong></h3><p>The code below will create our Security Group for the EC2 Instances and allow SSH from our IP only and then allow HTTP traffic in and all traffic out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*XXpmc5JJ85VX8DE97Je4vA.png" /><figcaption><a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group</a></figcaption></figure><p>Now we can create our Security Group for our RDS Instance. We will also need to create a subnet group for our RDS Instance. I will also say that the biggest hiccup while creating all of this was the creation of the database subnet for the RDS Instance. I tried using a custom name instead of “db_subnet” but kept getting a result that the subnet group name was not found. Once I destroyed everything and started over and use the subnet name below it worked without any errors. Just in case you try to give yours a unique name and keep getting an error, trust me. You are NOT alone!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*5lkPoF4tvYPceF1Wud3I5Q.png" /><figcaption><a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_subnet_group">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_subnet_group</a> <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_security_group">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_security_group</a></figcaption></figure><p>Time to create a Load Balancer to handle the traffic between our public subnets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*Nuzvp_leI8_WDf2fCserbQ.png" /><figcaption><a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb</a></figcaption></figure><p>We are almost at the finish line! We now need to launch EC2 Instances into each of our public subnets. 1 in each.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*16aN9P2ynKLlLcv7wHQ1Dg.png" /><figcaption><a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance</a></figcaption></figure><p>Finally we need to launch our RDS Instance into one of our private subnets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*IUb1se3zKQS5BALtJnwWrA.png" /><figcaption><a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance">https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance</a></figcaption></figure><p>Now that we have completed our Terraform code, let’s now running the following command: <strong><em>terraform plan</em></strong></p><p>After running this command we should get some of the below output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*_sigqNtqrbIYcSrhBxSzRw.png" /></figure><p>Now let’s run <strong><em>terraform apply — We will need to enter “yes” when prompted to continue. </em></strong>This allows to us make changes if we find an error with our code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*YqoP3tNTe2FvPxRl-hCRRw.png" /></figure><p>After entering yes we see that resources are now starting to be created. If everything is successful we should see no errors. If you want to confirm your resources were created, head over to the AWS Console and check the VPC, EC2, and RDS services pages.</p><p>And we have SUCCESS!!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*l4E5meFOqWr8bpWp7jsKOQ.png" /></figure><p>Now that you have successfully deployed your resources to AWS using Terraform, go ahead and run the following command to destroy and remove them — “terraform destroy”. Make sure to enter “yes” when prompted.</p><h3><strong>**** Don’t forget to push your code to GitHub!!****</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*Fvzy8_1uUxRJ_NiC0wfMtw.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a7d2ac808a5" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/for-this-weeks-project-we-are-going-to-use-terraform-to-help-us-create-a-two-tier-architecture-5a7d2ac808a5">For this weeks project we are going to use Terraform to help us create a Two-Tier Architecture.</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes — Creating deployments via command line and with YAML files.]]></title>
            <link>https://awstip.com/kubernetes-creating-deployments-via-command-line-and-with-yaml-files-783eaad7b3be?source=rss-ed2546d2d001------2</link>
            <guid isPermaLink="false">https://medium.com/p/783eaad7b3be</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Todd Caputo]]></dc:creator>
            <pubDate>Tue, 30 Aug 2022 01:59:51 GMT</pubDate>
            <atom:updated>2022-09-02T17:27:54.941Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes — Creating deployments via command line and with YAML files.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*oYSbJcl5r_jaAyXbpnuhHA.gif" /></figure><p>This week we are working with Kubernetes. We are going to be creating Kubernetes (also known as K8S)deployments using two way: command line &amp; YAML files.</p><h3><strong>Our Foundational project will be followed as shown:</strong></h3><p>· create a deployment that runs the nginx image.</p><p>· Display the details of this deployment</p><p>· check the event logs from the deployment</p><p>· delete the deployment</p><p>For this project I am using my Ubuntu image running on Windows Subsystem for Linux (WSL). Make sure you have enabled Kubernetes on your Docker Desktop. If you haven’t go into your settings and click on Kubernetes then check the box for Enable Kubernetes. See below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F0mAq1Qob5YBuM8e8ljgtQ.png" /></figure><p>Let’s get started.</p><h3><strong>Step 1. Create a deployment that runs the nginx image</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*FESPLlhET7FtRnxOtgB2IA.png" /><figcaption>Use this cheat sheet to get the commands needed: <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/">https://kubernetes.io/docs/reference/kubectl/cheatsheet/</a></figcaption></figure><h3><strong>Step 2. Display the status of your deployment</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*z4RcfWwJRbNGRIui-0aCGA.png" /></figure><h3><strong>Step 3. Display the details of your deployment</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Mt0QrWF1y1K7bO-o_1uI5w.png" /></figure><h3><strong>Step 4. Show the logs of your deployment</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*1u3QRSSUfUNnoeHQ1TPSqw.png" /></figure><h3><strong>Step 5. Delete the deployment</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*uQyOej8UdJu0vUded2D4eQ.png" /></figure><p>So now that we have learned how to create deployments using the command line, let’s take it a step further and create a deployment using a YAML file.</p><h3><strong>Our steps for the Advanced part of our project are below:</strong></h3><p>· Create the same deployment using a YAML file</p><p>· Display the details of this deployment via the command line</p><p>· Update the YAML file to scale the deployment to 4 nginx containers</p><p>· Verify the change via the command line</p><h3><strong>Step 1. Create our deployment using a YAML file</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*qPMfcVIFRLEIkHuelrRV2w.png" /></figure><p>Run the following command to create your deployment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*Fq7U7UB85lNKWcJZoljWrw.png" /></figure><p>Check to see if your deployment was created successfully:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*of60cDAIwbAFTCeFPGy2GA.png" /><figcaption>Checks the status of our pod</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*s-IA0p-qrbjl_TSoSORRrA.png" /><figcaption>Checks the status of our deployment</figcaption></figure><h3><strong>Step 2. Update our YAML file to add 4 Replicas</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*LRe09kPz6lr0nupZ-tig3w.png" /><figcaption>Add the “replicas: 4” code below the first ‘spec’</figcaption></figure><p>Rerun the following command to redeploy your updated YAML file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*7VkjCZ8OuRuLAkfjkPbliw.png" /></figure><p>Use the following code again to check your pods:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*lq--u5WjhGm1-D7igupSjg.png" /></figure><p>Use the following code again to check on your deployment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*gNB95ZmYYTCAOGF-H1NtcQ.png" /></figure><p>You can see that now your number of pods has been updated to 4 total. Our original pod is still there and 3 additional pods were created to give us our total of 4 pods.</p><h3><strong>Step 3. Get detailed view of our updated deployment</strong></h3><p>Using this command we can get a detailed view of our deployment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_d-RDFClIFBsThOJkVTQSg.png" /></figure><p>And that is all folks! You have now completed the Advanced section of this project! Great job!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*046vDSXkvJSsA7GtwiDFYg.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=783eaad7b3be" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/kubernetes-creating-deployments-via-command-line-and-with-yaml-files-783eaad7b3be">Kubernetes — Creating deployments via command line and with YAML files.</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Python to create an SQS queue and how to trigger with a Lambda Function & an API Trigger]]></title>
            <link>https://awstip.com/using-python-to-create-an-sqs-queue-and-how-to-trigger-with-a-lambda-function-an-api-trigger-b8083fd07ec4?source=rss-ed2546d2d001------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8083fd07ec4</guid>
            <dc:creator><![CDATA[Todd Caputo]]></dc:creator>
            <pubDate>Wed, 24 Aug 2022 14:56:33 GMT</pubDate>
            <atom:updated>2022-08-24T14:56:33.073Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*p1cpY-WGgN5XsqvEwQ4t-w.gif" /></figure><p>We are back at it again folks! In this project we are going to create a Standard SQS Queue using Python. We will then create a Lambda Function using Python to send a message to our SQS Queue. We will set our message to show the current time. We will then create an HTTP API Gateway to trigger it.</p><p>In order to do this we will need a few things first.</p><p>You will need an AWS Account with proper admin privileges, access to Cloud9 IDE configured with Python (or the IDE of your choice), SQS, IAM, Lambda, and API Gateway.</p><p>I am using Cloud9 configured with Python and Boto3.</p><h3><strong>Step 1. Launch your IDE and create a Python script to create an SQS queue.</strong></h3><p>After your create the script, save it and then run it. You should get back the URL of your SQS Queue. Copy this down for later use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*vj5gFhzLkaXen5DtZ6avWw.png" /><figcaption>Boto3 documentation can be found here: <a href="https://boto3.amazonaws.com/v1/documentation/api/latest/guide/sqs.html">https://boto3.amazonaws.com/v1/documentation/api/latest/guide/sqs.html</a></figcaption></figure><p>The screenshot below is the resulting output of running our python script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*uFbSgIHE_yhWyztEzaCdww.png" /></figure><p>To double check our SQS Queue has been created let’s head over to the SQS Service in the AWS Console. As shown below you can see it was in fact created successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0DryNM1xFqcNzJOW-ctHrQ.png" /></figure><h3><strong>Step 2. Now for the fun stuff. Lambda Function creation!!</strong></h3><p>Head over to the Lambda Function service and let’s create a function.</p><p>When you create your function, use the “Create a new role with basic Lambda permissions” setting and make a note of the role name that will be created. We will need it in the next step. Make sure to give it a few minutes for the role to be created before we edit the permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JISHjQauNMC6bRM5UGpgZw.png" /></figure><p>Now that your function is created, click on the Configuration tab</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*yu0FCKvC3SYJxxnUW0JKBg.png" /></figure><p>Then click on Permissions on the left.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*TQG7TiCyppFzoyIUPTfiOg.png" /></figure><p>Click the link for your new role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*GIOeZf5KnkheY6HYowvWwg.png" /></figure><p>Click on Add Permissions and then select the Attach Policies button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a6nMePBs-Cp3QMSWw4sGwQ.png" /></figure><p>Type SQS in the search and hit enter. You should get the results as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pob4a7lauBzNTntNXi2Cxw.png" /></figure><p>Go ahead and select the AmazonSQSFullAccess since we need to read and write permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fEl_JmRo55-XC7-69VsugA.png" /></figure><p>We can now see our new role has the proper permissions it needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jpQ7yD5gDfFWCb7K8bHGkw.png" /></figure><h3>Step 3. <strong>Let’s </strong>add an HTTP API Trigger.</h3><p>Click on the Add Trigger button for your function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*Dil8YEKmgWfTX765gGXI7Q.png" /></figure><p>Use the following settings below to create your trigger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*rWV71uy5Ud8-ljHYKl6I4w.png" /></figure><h3><strong>Step 4. Create the script for your Lambda Function</strong></h3><p>Our script will give us a message response with the current date and time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3DIzfRmQYieiwpPO5F_aiw.png" /><figcaption>Make sure to use the URL you copied down earlier when you ran your python script to print the queue’s URL.</figcaption></figure><p>Make sure to click Deploy to save your code.</p><p>Click Test to create a test event to check on our code. Change the template to API Gateway AWS Proxy. Then save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*z9X4HJJasrk4LLsUJsFgSA.png" /></figure><p>Click on Test again to test the function. You should get something similar to below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oF9E4hsdjRMuw3HtRMeQgA.png" /></figure><p>Now let’s try something fun. Click on the Configuration tab on your Lambda Function and select Trigger. Grab the API Endpoint URL for your trigger.</p><p>Copy and paste this into a browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IL-iBbheQtMZoxSy7CnhdQ.png" /></figure><p>You should get the following result in your browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*3oMW_PDOTzwPLcLtWdk2_A.png" /></figure><p>If we head over to our SQS page you can see we have messages available. The first message was our test we did. The second message is from the above API Endpoint trigger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nwe8oVOFXN3blKqlTB7-4Q.png" /></figure><p>Click into the Queue and select Send and Receive Messages and then select Poll for Messages at the bottom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*919d5WZswh7f102OiCMBoQ.png" /></figure><p>If you click on the top message and open it and choose the Body tab you will see it gives us our date and time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*-kCTPQ-gg-DCk1HmdCKKnA.png" /></figure><p>And that is how you create a simple SQS Queue using Python and Boto3. There are many detailed and interesting things you can do with Lambda Functions and SQS Queue. Maybe one day we will get to cover these. As always, be sure to commit your code to GitHub including the Lambda Function code you created. Until that time, be safe and keep on learning!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*TmJTKKGadHcqlEWd2_LvYw.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8083fd07ec4" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/using-python-to-create-an-sqs-queue-and-how-to-trigger-with-a-lambda-function-an-api-trigger-b8083fd07ec4">Using Python to create an SQS queue and how to trigger with a Lambda Function &amp; an API Trigger</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Containers! Oh my!!]]></title>
            <link>https://awstip.com/docker-containers-oh-my-12512544f1f6?source=rss-ed2546d2d001------2</link>
            <guid isPermaLink="false">https://medium.com/p/12512544f1f6</guid>
            <dc:creator><![CDATA[Todd Caputo]]></dc:creator>
            <pubDate>Tue, 23 Aug 2022 13:56:00 GMT</pubDate>
            <atom:updated>2022-08-24T14:54:47.484Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>How to create a Docker image, deploy a container, and push your data to AWS Elastic Container Registry (ECR)</strong></h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F19051933&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fhhla-container-logistik-logistikheld-logistics-gif-19051933&amp;image=https%3A%2F%2Fc.tenor.com%2Fqg4d3B4fwFIAAAAC%2Fhhla-container.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ae4bf93a25b862103a573112ad8d06c/href">https://medium.com/media/7ae4bf93a25b862103a573112ad8d06c/href</a></iframe><p>This weeks project focuses on creating Docker images and containers. We are going to create our own image using Nginx and then add a file that will tell us the date our container was deployed. We will then deploy the container to run on port 8080. Once that is said and done we will push our container data up to the AWS Elastic Container Registry (ECR). Let’s go have some fun!</p><p>We will need a few things to get us going: A Docker Hub account, Docker installed onto your system, your preferred IDE, AWS Account, and access to AWS CLI. I am going to be using Visual Studio Code for this project.</p><h3><strong>Step 1. Create our directory, dockerfile, and index.html file</strong></h3><p>In Visual Studio Code create a directory and then create two files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*nSNlC6t8hy9_jkV5BH-2Mg.png" /></figure><p>I already pulled down the docker image I wanted to work with but just in case there were any updates to the image I pulled it again. Use the command “docker pull nginx:latest” to pull down the most current image to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*gMOPv1lT7iEBSs-ajsoLcA.png" /></figure><p>Edit your Dockerfile to look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*jEL0enyyizqBsfz7xj1c3g.png" /></figure><p>Edit your index.html file to look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*9yHUMgkE14G_tYH5qLPeFw.png" /></figure><p>Now for the beautiful part. Let’s build our custom image using the following command: “ docker build -t ‘name your image’ . “</p><p>***Important to note your image name MUST be in all lower-case letters***</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*-aVnqDs7rt8aASvg1GmlHg.png" /></figure><p>To see a list of our images run the following: “docker images”. The screenshot below represents a list of images that I have either pulled or build. The top image is the one we just built.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*BirAl8fZWJ8ZFFQ1BLCtoA.png" /></figure><h3><strong>Step 2: Run the container and test</strong></h3><p>We now need to run the container and test our webpage. Use the following command to run it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*S2eu9tHNJ98DMEwCHoM9pg.png" /></figure><p>To test our build and our code, open a browser and navigate to “localhost:8080”. We should see the following result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*mrCEPzb7aSSxVVEhqOZcXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*a_DuBt-M8kx7HZ6u62boIQ.gif" /></figure><h3>Step 3. <strong>Push </strong>our container data to the AWS Elastic Container Registry</h3><p>First we need to create a repository. We will do this using the AWS CLI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*fho8as7H9YN_p3pDS6HEWw.png" /></figure><p>Run the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*T1Z9mgHQs1TWRSs2pgLoMA.png" /><figcaption>Documentation for creating ECR Repositories can be found here: <a href="https://docs.aws.amazon.com/cli/latest/reference/ecr/create-repository.html">https://docs.aws.amazon.com/cli/latest/reference/ecr/create-repository.html</a></figcaption></figure><p>If you head over to your AWS Console and look in your ECR Service you will see your new repository you just created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0TZQCW6y83qMRINUSPszog.png" /><figcaption>Make note of the URI. We will need it later on.</figcaption></figure><p>In order to get Docker to push an image to the AWS Elastic Container Registry we need to get an authentication token to pass into the docker login command. To get this token run the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*1FoKGEGovhXwF2fDmW2P2A.png" /></figure><p>You will see a nice long string get printed to your screen. This is the token. Copy it for later use. We will need it in the next command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uLlmRO55zX3jq2Ko5UY1jg.png" /></figure><p>This next command will need both the token and the ECR Repository URI from earlier. Run the following command to pass the authentication token to our repository:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TWIlz5O1xc6-YsTo3vNZKA.png" /></figure><p>If your token was authenticated successfully you will see “Login Succeeded” at the bottom of the response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uJFbFHBVqWsV9IBBOi2bog.png" /></figure><p>Next we will push the Docker image up to ECR. In order to do this we will need to tag it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*aywLj76UjZhoS8dyP8DenQ.gif" /></figure><p>Run the following command to tag your Docker Image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*x4judmdcXRRxuodicBSbEA.png" /><figcaption>Check out this documentation for any questions with ECR: <a href="https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html">https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html</a></figcaption></figure><p>Now let’s go ahead and push the image up to ECR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*rW8WvzXco4INHYcRMV1z8A.png" /></figure><p>You should start to see something similar to below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*UTVGn4YiDepgVTfHDVQGoQ.png" /></figure><p>If we head over to our ECR Service page and go into our repository we created we will see our image has been pushed. If you don’t see yours right away, give it another minute or two populate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PcpVlcJIYuy2JHuETcylGw.png" /></figure><p>We now have a copy of our custom built Docker image stored in AWS ECR. We no longer need to keep it stored locally on our host machine. You can stop and remove it if you wish.</p><p>Congratulations! You have just created our own docker image, tested it, and pushed it successfully to AWS ECR. Another project down, many more to go!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*itfifAT2jUNSYDLzMQDwwQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12512544f1f6" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/docker-containers-oh-my-12512544f1f6">Docker Containers! Oh my!!</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Python Boto3, and Lambda functions to start/stop EC2 Instances]]></title>
            <link>https://awstip.com/using-python-boto3-and-lambda-functions-to-start-stop-ec2-instances-5d3ca0ee9024?source=rss-ed2546d2d001------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d3ca0ee9024</guid>
            <category><![CDATA[python-boto-boto3]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[level-up-in-tech]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Todd Caputo]]></dc:creator>
            <pubDate>Mon, 08 Aug 2022 22:35:03 GMT</pubDate>
            <atom:updated>2022-08-12T21:15:37.202Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zNNwA9oUXYpcnoSoNfkb3A.png" /></figure><p>In our latest project we are tasked with using Python Boto3 to start/stop our EC2 Instances. For the first part of the project I have created a couple pieces of code: one to stop all running instances except for my Cloud9 IDE instance, one to start all EC2 Instances with the Environment:Dev tags, and then one to stop all EC2 Instances with the Environment:Dev tags.</p><p>The project details are as follows:</p><p>Scenario: Our DevOps engineering team often uses a development lab to test releases of our application. The Managers are complaining about the rising cost of our development lab and need to save money by stopping our 3 EC2 instances after all engineers are clocked out.</p><p>Foundation Project: create a python script that will stop all instances.</p><p>The first thing I did was create 3 EC2 Instances. I used the basic free tier Amazon AMI Linux images. I added the following tags to the instances- Environment:Dev</p><p>Now let’s go ahead and starts.</p><h3><strong>Step 1. We need to create an IAM Policy</strong></h3><p>Navigate to the IAM service and click on POLICIES. Now click on CREATE POLICY.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fduCwDlwdpehnqpUzQ-V2g.png" /></figure><p>Click on CHOOSE A SERVICE. Search for EC2 and select it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BcsCCtZNF_j0nKXQ-RWrIA.png" /></figure><p>We could go ahead and give your policy full access to all EC2 actions but we don’t need to. We can give it more granular permissions.</p><p>Click on the drop down arrow for LIST and select the following: DescribeInstances, DescribeInstanceStatus, and DescribeInstanceTypes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*A02NunQoOV2pARwXRa_ufw.png" /></figure><p>Now click on READ and select the following: DescribeTags</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*WWkLIM8h8TXZdx_WHPT7_g.png" /></figure><p>Now click on WRITE and select the following: StartInstances, StopInstances</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*bdTrRZfihuCW73py3E8G0g.png" /></figure><p>Click on RESOURCES and choose ALL RESOURCES</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*UUUMF1Sz-yl6nBuCNWnBZA.png" /></figure><p>Now click on ADD ADDITIONAL PERMISSIONS and Click on CHOOSE A SERVICE. Search for CloudWatch Logs and give it ALL CLOUDWATCH LOGS actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*WMupHcMo2qO-zO_Vw0maeQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*iKnrZ9JAiHx2sxWWEQHjYA.png" /></figure><p>Give your policy a name. For this project we will name it “stop_start_ec2instances”</p><p>Policy should look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YEAD84E1bcfSpWrVKIdrTg.png" /></figure><h3><strong>Step 2. Create a Role</strong></h3><p>Choose the default AWS Service and then under common use cases select Lambda</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*_-z2NEXL64TBDeIOEi9SUQ.png" /></figure><p>Add the permissions of the policy we created in step 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTUBROiIVrMffzOACRyxBw.png" /></figure><p>For this I am naming the role “ec2_schedule_role”.</p><h3><strong>Step 3: Create Python scripts</strong></h3><p>Now that we have created our policy and role, let’s create some python code to stop all instances. This code will stop all instances except for the Cloud9 Python IDE I am currently using.</p><p>Using Cloud9 I have created a python script as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*y9P7pGrZiFE6BY3ulEedzQ.png" /><figcaption>Github code found here: <a href="https://github.com/krypt0-cappy/Python_Projects/blob/main/stop_all_running_instances.py">https://github.com/krypt0-cappy/Python_Projects/blob/main/stop_all_running_instances.py</a></figcaption></figure><p>To test this out, if you already have some instances created, get them into running status, or you can use the 3 instances we created for this project.</p><p>This code will stop all instances that are in the “running” status. You will notice there is a single InstanceID named in the code. This is my Cloud9 IDE and we don’t want this to stop since it will kill our connection to the instance.</p><p>You can see here we have a few instances running as well as our Cloud9 IDE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*ARgQQ37F3y8CboimG0KOrw.png" /></figure><p>Now let’s head over to our Cloud 9 Python IDE and run our script.</p><p>Running the code we get the following response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*mJ5tasfAV8mFwCiG8bOfJA.png" /></figure><p>Now we can see only our Cloud9 IDE instance is still running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*Cdl70mlpURSdMgtluD_UuQ.png" /></figure><p>So now let’s create a script that will start all of our instances with the Environment:Dev tag.</p><p>Our existing code to stop the instances will be modified slightly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4H3rp4_wHNyDSDJNO3TYQ.png" /><figcaption>Github code found here: <a href="https://github.com/krypt0-cappy/Python_Projects/blob/main/starting_stopped_instances.py">https://github.com/krypt0-cappy/Python_Projects/blob/main/starting_stopped_instances.py</a></figcaption></figure><p>So since we stopped our instances earlier and left only our Cloud9 IDE running, let’s run this code if see if only our 3 instances we created earlier will be the ones that start.</p><p>We now see that 3 instances are now running in addition to our IDE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*apY9cA-skpc5aoIUFvQaxw.png" /></figure><p>Now that we have created a Python script to start instances with those tags, let’s create a script so that only these instances are stopped. We want to do this so that no other departments, for example: Production, are not accidentally stopped. Modify the code as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hEfm0KM4LxSwDtYrnG3uow.png" /><figcaption>GitHub code found here: <a href="https://github.com/krypt0-cappy/Python_Projects/blob/main/stop_environment_instances.py">https://github.com/krypt0-cappy/Python_Projects/blob/main/stop_environment_instances.py</a></figcaption></figure><p>Great work! Now let’s do something a little bit more special.</p><h3><strong>Step 4. Create a Lambda function</strong></h3><p>Now that we have created our Python code, lets go ahead and create a Lambda function. The purpose of this Lambda function is to stop all Environment:Dev instances when our Engineers are clocked out at 7:00pm. None of our Engineers should be working past 7:00pm so we are clear to put a hard stop on shutting them down at this time.</p><p>Navigate over to the Lambda service and click on CREATE FUNCTION. Use the selections shown below for your Lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UTcCS1zepz02US-v8Sa0Gg.png" /><figcaption>Choose the latest Python Runtime and use the ec2_schedule_role we created earlier.</figcaption></figure><p>Use the code below to shape your Lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3YbWH0hGhOBBelPGcoTwzQ.png" /><figcaption>This will stop all instances with the tag “Environment:Dev” and only those instances.</figcaption></figure><p>We should still have our Environment:Dev instances from earlier running.</p><p>Let’s go ahead and click on DEPLOY and then click TEST to run a test of our function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*Wxi0lB4WmEnvIVW8gkBBuQ.png" /></figure><p>Our Lambda function was successful and we are able to stop only the Environment:Dev instances.</p><h3><strong>Step 5. Create CloudWatch/EventBridge Rule</strong></h3><p>Now we are going to create a CloudWatch Event Rule that will stop our Environment:Dev instances at 7:00pm Monday through Friday.</p><p>Let’s head on over to EventBridge.</p><p>Click on CREATE RULE and set as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*SdMr081FOH5vfiBdzAaIiA.png" /></figure><p>Because we are going to use a schedule we will need to use a Cron Expression.</p><p>The expression is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*U-m71L9JSkyqu9WWilDs9A.png" /></figure><p>You can see that our Cron Expression looks like it is going to run at 23:00 (11pm), but if you click on the UTC drop down and select Local Time Zone, the time it will run locally to us is actually 7:00pm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*iT1dQTq2IXqlqbIyySKmvg.png" /></figure><p>This pattern above will run every Monday, Tuesday, Wednesday, Thursday, and Friday at 7:00pm and it has shown us our next 10 trigger dates.</p><p>Now we need to supply our target. Choose AWS Service, Select Lambda Function as the target, and then our function will be our ec2_instance_stop function we created earlier. Click through the remaining Review and create the schedule.</p><p>In order to test, I modified my schedule to stop these instances at 6:20pm local time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*g1aT9j8n3Xa57IglWeO9PA.png" /></figure><p>My screenshot below shows these instances are running as of 6:19pm local time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QaV2fCmRPEbXWcESBH8RZQ.png" /></figure><p>As you can see in the screenshot below, the local time is now 6:21pm and these Environment:Devs instances have been successfully stopped.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5n_5wvnZFKwLu9Pla4l2WA.png" /></figure><p>Congratulations! You have just successfully integrated Python Boto3, AWS EC2 Instances, Lambda Functions, and CloudWatch/EventBridge rules. As you start to get more and more comfortable with the services AWS offers, you can start to go down the rabbit hole as to how creative you can really get with things. In just 14 weeks I have gone from barely knowing anything about AWS Services, to creating EC2 Autoscaling Groups, 3-Tier Architectures, using the AWSCLI to create entire VPC environments, to now using Python Boto3 and Lambda functions. The possibilities here are endless and my thirst for knowledge is growing!</p><p>*************Reminder**************</p><p>^^^^^Push all code to GitHub^^^^^</p><p>Until next time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d3ca0ee9024" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/using-python-boto3-and-lambda-functions-to-start-stop-ec2-instances-5d3ca0ee9024">Using Python Boto3, and Lambda functions to start/stop EC2 Instances</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>