<?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 Aaron Clegg on Medium]]></title>
        <description><![CDATA[Stories by Aaron Clegg on Medium]]></description>
        <link>https://medium.com/@aaronclegg?source=rss-b6aee1ad8f5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*s2vP5sh4iHZ_xxh-1D2LKg.jpeg</url>
            <title>Stories by Aaron Clegg on Medium</title>
            <link>https://medium.com/@aaronclegg?source=rss-b6aee1ad8f5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 12:26:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aaronclegg/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[Our First CI/CD Pipeline in AWS!]]></title>
            <link>https://medium.com/@aaronclegg/our-first-ci-cd-pipeline-in-aws-d0cb5c7657cf?source=rss-b6aee1ad8f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0cb5c7657cf</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[level-up]]></category>
            <category><![CDATA[s3]]></category>
            <dc:creator><![CDATA[Aaron Clegg]]></dc:creator>
            <pubDate>Thu, 21 Jul 2022 14:03:51 GMT</pubDate>
            <atom:updated>2022-07-21T14:03:51.537Z</atom:updated>
            <content:encoded><![CDATA[<p>Small project on how to build a pipeline for CI/CD (continuous integration/continuous deployment) using AWS services. Let’s dig in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*CQe8Zg9mnb6vh0sWJZ6cEQ.png" /></figure><p>CI/CD can be pictured as a pipeline, where new code is submitted on one end, tested over a series of stages (source, build, test, staging, and production), and then published as production-ready code. This is a way to improve the quality of your project and the changes you make will happen a lot faster.</p><p>To get going on this, you will need an AWS account with the correct permissions to use the S3 and CodePipeline services. You will also need a GitHub account for the repo and for commits.</p><p>Step #1</p><p>To kick things off, we will need to fork this repository to our own. It includes all the files we will need to get our pipeline up and running. Here is the link-<a href="https://github.com/LevelUpInTech/LUIT-angular-app">https://github.com/LevelUpInTech/LUIT-angular-app</a></p><p>You can use this repo or your own.</p><p>Step #2</p><p>We are going to head over to the AWS console and create a quick S3 bucket to store the data for our project.</p><p>Search S3 at the top and when we get to the dashboard, we are going to click on <strong>Create bucket</strong>. We will need to check the box <strong>ACL’s enabled</strong>, name our bucket, and uncheck the box for <strong>Block all public access</strong>. Make sure you check the box for acknowledgement that you are turning off the block for public access. We will leave all other settings on default and click <strong>Create bucket</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cJtBXTTc_plwbIqX7jCSTQ.png" /></figure><p>This is a quick way to set up a bucket and the basics we will need for our project. Soon we will be deleting everything. If this is something other than a project, make sure you are placing the proper security measures in place.</p><p>After we have created our bucket, go back to the dashboard and select the bucket. Go to the <strong>Properties</strong> tab and at the bottom, we will edit for <strong>Static website hosting </strong>and change the radio dial to <strong>Enable</strong>. Under the <strong>Index document </strong>add a default page of “index.html”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f5NV744RThVOVnHEhjjqxA.png" /></figure><p>Make sure to save those changes and then go to the <strong>Permissions </strong>tab of your bucket. We will now edit the <strong>Bucket policy</strong>. You can use a policy example from AWS that will give public read permission to your bucket. Make sure to replace your bucket name in the resource section along with <strong>/*</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFoIpNCu-AagGI4mkCwYuw.png" /></figure><p>Step #3</p><p>Now is the time to go to <strong>CodePipeline</strong> and get all the stages of our pipeline built. Starting with Source, then Build, and last but not least, Deploy.</p><p>After we find the CodePipeline service dashboard, we can select <strong>Create pipeline</strong>. On the next screen, we will need to name our pipeline, leave everything on default and then click <strong>Next</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cEJWPhvG4zF88O2UKBdvdA.png" /></figure><p>Step #4</p><p>On the next screen we will choose our Source provider. Since I have some experience with Github, that is what I chose and chose version 2. Since we don’t have a connection yet, we will want to choose <strong>Connect to Github</strong> and go through the steps. If this is your first time like it was for me, you will need to <strong>Install a new app</strong> and sign into your GitHub account. It will ask you what repo you want to use and the branch name as well. Leave everything else alone and click on <strong>Next</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iBzdZxfH9Bq_cxFl2uswLA.png" /><figcaption>This is what it should look like after everything is configured</figcaption></figure><p>Now we are moving to the Build stage!</p><p>Step #5</p><p>Let’s go choose the Build settings! In the <strong>Add build stage</strong> page, we will need to select a Build provider. In this example we are going to go with <strong>AWS CodeBuild</strong>. We will then add a new project by selecting <strong>Create project</strong>. We will add a name and then give it a description if we feel it is necessary. There are a few things we need to watch out for and select. They are:</p><ul><li>Environment image = Managed image</li><li>Operating system = Ubuntu</li><li>Runtime(s) = Standard</li><li>Image = aws/codebuild/standard:5.0</li><li>Image version = “Always use the latest image…”</li><li>Environment type = Linux</li></ul><p>Leave the rest of the settings on default and select <strong>Continue to CodePipeline</strong> at the bottom of the page.</p><p>Click on Next and let’s go to the next steps!</p><p>Step #6</p><p>In the <strong>Add deploy stage</strong>, we will select <strong>Amazon S3</strong>. Under the bucket option, you’ll select the bucket that we created earlier for this project. We will also need to select the <strong>Extract file before deploy </strong>box and select <strong>Next</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yMAs-TqC_RxpDAwMX6syQ.png" /></figure><p>After reviewing the pipeline and being satisfied with it, we can click on <strong>Create pipeline</strong>. If you see a green bar with the success message, you know your pipeline is working!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oo9loVzSTD2MWqb-TvCkKg.png" /></figure><p>It will take several minutes for the pipeline to go through all the stages. As you can see, mine had only just completed the first stage and still has a little bit to go.</p><p>Step #7</p><p>Let’s go and verify that everything is working! We can do this by checking our static site to see if it’s working and making a small change to our code to see if our pipeline is triggered by the change. Let’s go back to our S3 bucket that we created for this project and then the file, or object, that is inside that bucket. Click on the index.html object and stay in the <strong>Properties</strong> tab and look for the <strong>Object URL</strong>. We will want to copy and paste the <strong>Object URL </strong>into our browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_w0TBgZOSi_l4nb3la3vwA.png" /></figure><p>Looks like we were able to access the pretty basic website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*LEBsdWMpzvtAR0LC0ubSBw.png" /></figure><p>I am going to go and make a change in the repo in GitHub to see if the change triggers the pipeline. I am going to add some text to the readme file.</p><p>Once these changes are made we will want to head back to the AWS CodePipeline and select our pipeline. We will be able to see that our pipeline was triggered and is relaunching because of the change that was made to the readme file in GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*71KDe5uai0hgYr8uOlB6bQ.png" /></figure><p>If you want to see the history of your changes, you can click on <strong>history</strong> on the left-hand side of the page to see what has been done previously.</p><p>But that is the project! We did it! We created our first CI/CD pipeline and it wasn’t too bad! This makes it smooth and easy to make changes and to push them out quickly. This is just the beginning and there is so much more to do and learn but we accomplished our goal of getting a pipeline put together and launching a static site. Thanks for following along!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0cb5c7657cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Python and Lambda to Stop EC2 on a Schedule]]></title>
            <link>https://medium.com/@aaronclegg/using-python-and-lambda-to-stop-ec2-on-a-schedule-978faa097e7d?source=rss-b6aee1ad8f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/978faa097e7d</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[level-up]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[lambda]]></category>
            <dc:creator><![CDATA[Aaron Clegg]]></dc:creator>
            <pubDate>Wed, 20 Jul 2022 15:02:58 GMT</pubDate>
            <atom:updated>2022-07-20T15:02:58.302Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LdEXiLD6HHgsUuqZNGN_0g.png" /></figure><p><strong>The situation:</strong></p><p><em>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.</em></p><p><em>Use your script in a Lambda function using Python 3.9 runtime. Make sure the lambda runs on a set schedule daily. No one should be working in the Dev environment past 9pm.</em></p><p>Here we go!</p><p>Step #1</p><p>To get things started, we will launch three EC2 instances with this python code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KtjRHDCYcEnKkjJj4O9dOQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qbv4bKay0sj7BIeS_gnGUw.png" /></figure><p>As you can see, we have successfully launched three EC2 instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1DsiAfzVCJNUvGV7AglKwA.png" /></figure><p>Step #2</p><p>Create New IAM Policy and Attach to Role for the Lambda Function</p><p>We are now going to navigate to IAM and create this new role for our lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*tMfJB9NTslmDHItf-p8bHw.png" /></figure><p>When you go to the IAM dashboard, you will want to click on <strong>Policies</strong> and then <strong>Create policy</strong>. From there you will add this code in the <strong>JSON </strong>tab, click next, tag it if you’d like, give it a name you can find, give it a description, and then click on <strong>Review</strong>. From there you will click on <strong>Create Policy</strong>. You will then attach the policy we just created to your new <strong>Role</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WKiYjiAVsOHA_nv02EOuKg.png" /></figure><p>Alright, now that our policy and roles have been created and added, we can go on to our next step!</p><p>Step #3</p><p>This next step in our tutorial is to create our Lambda function. We will also assign the role we created in our previous step so that our function will be able to start and stop our instances as we want them to. First we are going to navigate to the Lambda by searching for it in the console. Once we arrive we are going to click <strong>Create function</strong>. We are going to <strong>Author from scratch</strong>, give it a name, choose <strong>Python 3.9</strong> as the <strong>Runtime</strong>, use x86_64 as the <strong>Architecture</strong>, <strong>Use an existing role </strong>for the <strong>Execution role</strong> and find our role we just created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SZEkyirN_TWRv88J48iVBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o9Hx2-feb-Yh-_A4oVSGWQ.png" /></figure><p>We will need to write in this code in the Lambda Code Editor:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PAlJ71-9uBN73MC-VJTu_A.png" /></figure><p>After that is written in, make sure you click on the deploy button to save the changes.</p><p>Step #4</p><p>For our final step, we will be creating an EventBridge Rule that triggers our EC2 instances to stop based on the time of day we specify. So we will need to search Amazon EventBridge in the search bar and create a new rule. Make sure you click on <strong>Schedule </strong>for the <strong>Rule type</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KcRHMSQEgMZeWoWZWPpAWw.png" /></figure><p>Remember, for our project, no one should be working in the Dev environment past 9pm and all instances should be stopped at 9pm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DVKANGxPqV62LaH7P6MxUA.png" /></figure><p>You may have to play around with the “Hours” box when you change the time zone to your local time zone.</p><p>Click on Next at the bottom and on the Target page we will want to make sure <strong>AWS service </strong>is selected for the Target types, select <strong>Lambda function</strong> under <strong>Select a target</strong>, choose the Lambda function we created earlier to stop the EC2 instance and click on <strong>Create.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wnslJUFTB9JWLaQ2e7yLJw.png" /></figure><p>Everything looks to be in order and now we will have to wait until 9pm to see if the instances stop when we set the trigger!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j0tlxb-As1ihvUBBAafL8Q.png" /></figure><p>Thanks for following along!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=978faa097e7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Trigger Lambda to Send Messages to SQS]]></title>
            <link>https://medium.com/@aaronclegg/how-to-trigger-lambda-to-send-messages-to-sqs-b4b0873bf334?source=rss-b6aee1ad8f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4b0873bf334</guid>
            <dc:creator><![CDATA[Aaron Clegg]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 15:32:18 GMT</pubDate>
            <atom:updated>2022-07-19T15:32:18.907Z</atom:updated>
            <content:encoded><![CDATA[<p>In just a few steps we are going to create a sqs queue using python and cloud9. We will then create a lambda function that will send a message to our sqs queue showing the current date and time when triggered by an API gateway. Let’s do this thing!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b986vGwuadFXeMsiVInBOg.png" /></figure><p>Let’s dive into the background of the services we will be using so that we can understand them a little more and know why we are using them. First off, what is AWS lambda? “Lambda is a compute service that lets you run code without provisioning or managing servers. Lambda runs your code on a high-availability compute infrastructure and performs all of the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, code monitoring and logging. With Lambda, you can run code for virtually any type of application or backend service.” — AWS docs.</p><p>Our next question is — what is Amazon’s SQS? “Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications. SQS eliminates the complexity and overhead associated with managing and operating message-oriented middleware, and empowers developers to focus on differentiating work. Using SQS, you can send, store, and receive messages between software components at any volume, without losing messages or requiring other services to be available.” — aws.amazon.com</p><p>Our final question we want answered is, what is an API gateway? “Amazon API (Application Programming Interface) Gateway is an AWS service for creating, publishing, maintaining, monitoring, and securing REST, HTTP, and WebSocket APIs at any scale. API developers can create APIs that access AWS or other web services, as well as data stored in the <a href="https://aws.amazon.com/what-is-cloud-computing/">AWS Cloud</a>.” — AWS docs.</p><p>We will be using all three of these services in this tutorial to send a message to our queue that will show us the current date and time.</p><p><strong>Pre-reqs</strong></p><p>To be able to be successful in this walk-through, you will need to have an AWS account with the appropriate permissions. We will be using Cloud9, Lambda, IAM, SQS, and API. The nice thing about using Cloud9 is that it comes with python and the AWS CLI pre-installed. It does not, however, come with boto3 so you will want to install that ahead of time. Since I am using ubuntu, the code I used to get it installed was:</p><pre>pip3 install boto3</pre><p><strong>Step #1</strong></p><p>For our first step we are going to create an SQS queue. We will do that in Cloud9 using a python script. I have also decided to add a 5-second delay to the queue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hmK8yECy-vEKP-b-WDKSkw.png" /></figure><p>This is the code and we will see the results after you click on the “Run” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WK72zo5KyKxVhmXEcFjEvg.png" /></figure><p>At the bottom of this picture you will see the URL showing us that the run was successful. If you find that you get an error mentioning a module couldn’t be found, make sure you have boto3 properly installed.</p><p>Let’s go to the console and see our queue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*GaeOEuSR9QYlgp3OTuRG3A.png" /></figure><p>Beautiful! If you pay close attention to the code up above, you will see that we named our queue, MySQSQueue, so we know that this is correct. The time stamp also confirms it as well.</p><p><strong>Step #2</strong></p><p>Our second step of this journey is to navigate over to Lambda and click on the <em>Create function</em> button. We will go ahead and leave the radio dial button on <em>Author from scratch</em> and we will give our function a name, making sure we add <em>Python</em> as the Runtime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FSmmwNngPN6F5JwZpteWfA.png" /></figure><p>After clicking on the <em>Create function</em> button, we will be brought to the dashboard for our Lambda function.</p><p><strong>Step #3</strong></p><p>Next, we will add an API Gateway trigger. This is easily done by clicking the <em>Add trigger</em> button, towards the top of the screen. We will then select <em>API Gateway</em> as our trigger, using the <em>Create an API</em> option under API, selecting <em>HTTP API</em> for API type, and selecting <em>Open</em> for security.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d9dHIVfm9cZMgCYlkKiI-g.png" /></figure><p><strong>Step #4</strong></p><p>After we get our trigger set, we will want to configure our function with the right permissions. We can do that by selecting the Configuration tab. We will then navigate to the Permissions on the left-hand side of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WYVr-7tQFyMyQ_nhO3nXeQ.png" /></figure><p>We will click on our role and then click on the plus button to view the policy for our role. We will click <em>Edit</em> to modify the permissions of our role. We will make sure to stay in our <em>Visual editor</em> and select <em>Add additional permissions</em>. We will <em>Select a service</em> and find <em>SQS</em>. We will select <em>Read and Write Access</em> levels and we will also select <em>Resources </em>and and put in the <em>ARN for our SQS queue</em>. You can get the ARN by going back to SQS, selecting your queue, and then copying the ARN to paste in the space where it asks for the ARN. Once those changes have been made, click on <em>Review Policy</em> and select <em>Save changes.</em></p><p><strong>Step #5</strong></p><p>Going back to Lambda, we will enter a script, that once invoked, will send a message to SQS with our current date and time. This is the script, but you will want to add your own http queue URL that will include your own account number. I <strong>will not</strong> be giving you mine ;) You can find that by going back to your SQS dashboard and clicking on your queue to see more details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-QEI-1x2S2FyVBwJTR7gLw.png" /></figure><p><strong>Step #6</strong></p><p>Now we are at the best part. Test time! First let’s click on the <em>Deploy</em> button to save our code. Next we will create a test. We will click on the <em>Test</em> tab and leave the dial on <em>Create new event</em>. We will give our event a name, leave the setting for event sharing on <em>Private,</em> and under <em>Template</em> we will select <em>apigateway-aws-proxy</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UJkMmGf1Os_vO7m9NC9H5Q.png" /></figure><p>After the test is set up and saved, we can go back and hit the <em>Test</em> button to see what happens. If everything was successful, you will see the <em>“statusCode”: 200</em> and then the message body consisting of the current date and time under <em>Response.</em> We can then navigate back to SQS and see if we have a message. If we go to <em>SQS</em> and then <em>Queues</em> we can find our queue and then select <em>Send and receive messages</em>. We will scroll down and select <em>Poll for messages.</em> We can click on the message and then the <em>Body</em> tab. This is where we will see that it is working and gives us the date and time! Yes!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_3Hb5BJPwkNDiXz-ipbU5Q.png" /></figure><p>Going back to Lambda and selecting the API trigger we will see the API endpoint. If we click on it we can see that our API is working as it should.</p><p>Thanks for following along! This is a great project to see how these services can connect with each other!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4b0873bf334" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[EC2 Instance Using Terraform]]></title>
            <link>https://awstip.com/ec2-instance-using-terraform-710e24241f64?source=rss-b6aee1ad8f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/710e24241f64</guid>
            <category><![CDATA[level-up-in-tech]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ec2-instance]]></category>
            <dc:creator><![CDATA[Aaron Clegg]]></dc:creator>
            <pubDate>Thu, 14 Jul 2022 05:52:13 GMT</pubDate>
            <atom:updated>2022-07-18T09:19:14.813Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*qsrz6Ct-gmLgEjLpyyj2hw.png" /></figure><p>In this article I am going to explain how we use modules in terraform to create an EC2 instance. We will be using a file created for us in Github and bringing it over to our IDE (I will be using Cloud9).</p><p><strong>Objective:</strong></p><p>Your team needs you to create a custom module for ec2 instance with a amazon linux 2 ami ID</p><p>1. Fork and clone this repo locally with the ec2.tf template as a starting point to create the ec2 : <a href="https://github.com/LevelUpInTech/terraformec2.git">https://github.com/LevelUpInTech/terraformec2.git</a></p><p>2. Create a custom module for ec2 out of the resource block that you can use as repeatable infrastructure</p><p>3. Push the new created module and the ec2.tf file to your repo!</p><p>First things first. We are going to go and fork the repository from the Github account and clone it so that we have something to work with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*vgTj51PFyHVT9myI0byQKg.png" /></figure><p>Forking the repo will bring it to our account and from there we can copy the HTTPS URL and paste it into cloud9 with this command</p><pre>git clone <a href="https://github.com/aclegg21/terraformec2.git">https://github.com/aclegg21/terraformec2.git</a></pre><p>You will see it show up as a new folder in your cloud9 name terraformec2. If you open the file you will see a .git folder and an ec2.tf file. We now have something to work with! As you can see, this file takes the monolith approach and to make it reusable for future projects, we will need to break it down and use some modules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*C_CqHqfv6dK14lEpVOw-5w.png" /></figure><p>You will also want to make sure you are on a branch in your cloud9 and not just on the main. Being on a branch is best practice and helps you get into good habits for the real world prod environment.</p><p><strong>Converting this to a module:</strong></p><p>First we will start by making a new folder inside of terraformec2 and I called mine ec2mod to keep it short and sweet. You can name it whatever you want. Inside that folder I added four files. Main.tf, provider.tf, outputs.tf, and variables.tf. These files are all necessary and required for this project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*9LsJ5NPCLfB-mMXe7bZ6nQ.png" /></figure><p>This is what your layout should look like at the moment. Fairly simple and straight forward.</p><p>Our first piece of business is to cut and paste the provider information from the original monolith file to our provider.tf file. We are going to change some of the code from being “hard-coded” to variables so that going forward we only have one place to go to and change the code instead of scrolling very carefully up and down the code making sure we got every last spot. I know that this project uses less than 30 lines of code but for more complex projects and terraform that you deal with in the future, it is best practice to learn how to use variables and code them well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*8tNgFemJLUD5uh83W_yYMA.png" /></figure><p>We are going to cut the rest of what is left from the original ec2.tf file and paste that into our main.tf file. Notice that I changed the ami id and instance type from their hard-coded values into variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*fTfqL7OVqA4m4AfdRAXawg.png" /></figure><p>Alright, with our three basic variables created let’s go back and fill in some information in the variables.tf file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*_gSUSu-nU6R0QuG_K8EcdQ.png" /></figure><p>As you can see I have listed each variable name as referenced in the previous files, the type of input it will be, and the default (which is the actual value).</p><p>Now we want our script to output the public ip address and also the name of the instance. We can do that by entering information into our outputs.tf file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FBPMPWiaNvN5gqD2AUTBXA.png" /><figcaption>outputs.tf</figcaption></figure><p>After having worked and touched all of the files in our ec2mod folder, we now will want to go back to our root ec2.tf file and make sure it knows where to get the information from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*Ia4DDnri7GYTV4ctImcPaQ.png" /></figure><p>We are going to point it to our ec2mod module, have it reference the files in that module, and have that be all we need to worry about right now.</p><p>Next, since we will be running the module from our root directory, we will need to create an output.tf file in our root directory to print the stuff we created in our ec2mod directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*TNwq_nK_2SwrXJP3uKTQkA.png" /><figcaption>root/outputs.tf</figcaption></figure><p><strong>Terraform Commands:</strong></p><p>We are now going to run some commands to see how we did and if everything is valid and works! The terraform init command is used to initialize a working directory containing Terraform configuration files. This is the first command that should be run after writing a new Terraform configuration or cloning an existing one from version control. It is safe to run this command multiple times.</p><pre>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oFVgUr20AWEBgsB6ndGgCQ.png" /></figure><p>Our next command will check to make sure everything we typed in during this project is valid.</p><pre>terraform validate</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lSG6LrFyZR6sX48RCW-rog.png" /></figure><p>That is a great sign!</p><p>Now, the moment of truth, we will plan, apply and then go and check our work in the console.</p><pre>terraform plan</pre><pre>terraform apply</pre><p>*I did just run into a small error — I had recently updated my aws access key and aws secret access key and hadn’t updated it in my cloud9 yet. It gave me a token/permission error and it was easily fixed by doing a aws configure command and changing the keys in that.</p><p>After fixing that small error I was able to successfully run a terraform plan and see that one resource was going to be created.</p><p>*To make your code look more uniform and easy to read, I would suggest running a terraform fmt command to line everything up.</p><p>Alright, as we can see, our apply ran successfully and we now have an ec2 instance up and running! Congrats!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wvVditzvVhfyy1z4roJQ1w.png" /></figure><p><strong>Destroy Resources:</strong></p><p>Now it is time to go and destroy. We do not want to rack up any charges or have time go wasted so let’s “clean up, everybody!” as my daughter would say. This is done with a simple command:</p><pre>terraform destroy</pre><p>This will show you what is about to be destroyed and cannot be undone once you type in “yes”. So make sure you give it a good look over and know what is going to be gone forever.</p><p>Thanks for following along! I hope you enjoyed learning about this as much as I did!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=710e24241f64" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/ec2-instance-using-terraform-710e24241f64">EC2 Instance 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[Creating that 3-Tier Architecture in AWS]]></title>
            <link>https://medium.com/@aaronclegg/creating-that-3-tier-architecture-in-aws-1a8b1f8249f8?source=rss-b6aee1ad8f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a8b1f8249f8</guid>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Aaron Clegg]]></dc:creator>
            <pubDate>Mon, 27 Jun 2022 01:03:42 GMT</pubDate>
            <atom:updated>2022-06-27T01:03:42.086Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*CNr6c6APhqx8LSMhtUX64g.png" /></figure><p>Today we take a dive into the world of AWS and create an AWS 3-tier architecture. This is a great project that exposes us to many different things! We get to create our own VPC, a presentation tier, an application tier, and a database tier. We are also going to test to make sure things are up and running correctly as well. This is a great way to build out an application and store data.</p><ul><li><strong>Web Tier</strong> — A presentation or web tier is the user interface and communication layer of an application. This is where the end-user will interact with the application. It will display information and collect information.</li><li><strong>Application Tier</strong> — The logic or application tier is the heart of the architecture. It’s where information is processed. This tier contains all the business logic used to process inputs. It can direct queries, use API calls, process information and commands, make logical decisions, and perform calculations. It moves and processes information to the other layers.</li><li><strong>Database Tier</strong> — And lastly, we have the data or database tier. This is where information will be stored and managed.</li></ul><p>Pre-requisistes</p><ul><li>An AWS account with the appropriate permissions</li><li>Excitement to get this project done and add more knowledge to your brain!</li><li>Access to a terminal. I am a mac user so I will be using the terminal but you can also use the command line for Windows users.</li></ul><p>STEP 1: Build the VPC (Virtual Private Cloud)</p><p>First things first, let’s go and search for the VPC in the console. Go to the search bar and type in VPC. We will be creating a new VPC that will hold all of our infrastructure for this project.</p><p>When you get to the main VPC dashboard, click on <strong>Create VPC</strong>. We will be selecting <strong>VPC Only</strong> and will give our VPC a name. I like to keep mine short and to the point. I will name mine 3TierVPCProject just so I remember exactly what this is for. We will leave the IPv4 CIDR block radio on manual input and will assign 10.0.0.0/16 to the IPv4 CIDR. We’ll leave the rest as is and hit the<strong> Create VPC </strong>button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LTUBfYUPYa7vhbhOfjvIPw.png" /></figure><p>STEP 2: Create Subnets</p><p>A <em>subnet</em> is a range of IP addresses in your VPC. You can launch AWS resources into a specified subnet. Use a public subnet for resources that must be connected to the internet, and a private subnet for resources that won’t be connected to the internet.</p><p>For this project, we will need 6, yes, 6 subnets. We will have two public subnets in our web tier, two private subnets in our application tier, and two private subnets in our database tier.</p><p>On the left-hand side of the console, we will see<strong> Subnets</strong> in the navigation bar. Go ahead and click on it and then on <strong>Create subnet</strong>. On the next screen, we select the VPC that we just created, give our subnet a name, choose an Availability Zone, and assign it an IPv4 CIDR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*brxqMddRE4wDhibRtN5KBQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Krl7_CGYAHXH-frRZ5cwDA.png" /></figure><p>Disregard that cloud9 subnet. That is for something else I am working on.</p><p>STEP 3: Setting up the Internet Gateway</p><p>Now it is time to set up our internet gateway! An internet gateway enables communication between your VPC and the internet. We will choose <strong>Internet Gateway </strong>on the left-hand side of the console. At this spot, select <strong>Create internet gateway</strong>. Then we will name our gateway and select <strong>Create internet gateway</strong>. Once created will need to attach our internet gateway to our VPC by choosing <strong>Actions </strong>and then<strong> Attach to VPC</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-oKcd_hYLj9ZaqOX2yBZxA.png" /></figure><p>We will now attach it. You can do this by going back to the internet gateway screen and selecting <strong>Actions </strong>and then choosing <strong>Attach to VPC</strong>. You will then attach it to the VPC you previously made. After it is attached, you will see confirmation in the Details section under State.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cyXrr-DWGftkjykH8MccSw.png" /></figure><p>STEP 4: Create the NAT Gateway</p><p>A NAT Gateway is a Network Address Translation service. We need a NAT Gateway in order to have public access that will allow instances in private subnets to connect to the internet but will also not allow any unwanted inbound connections.</p><p>Locate the <strong>NAT Gateway</strong> on the navigation bar and click on <strong>Create Nat Gateway</strong>. This is where we will name our gateway, choose a public subnet in your web tier, I chose #2, select Public for Connectivity type, and select <strong>Create NAT Gateway</strong>. We will also <strong>Allocate Elastic IP</strong>. By using an Elastic IP address, you are able to mask the failure of an instance by quickly remapping the address to another instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*euWF3KEuzF9cV_T9nWUwKw.png" /></figure><p>STEP 5: Add Route Tables</p><p>Moving onto creating the route tables. Our route tables will contain a set of rules, called routes that will determine where network traffic from your subnet or gateway is directed. I created two route tables, a public and private and associated the appropriate subnets with their respective tables.</p><p>On the left-hand side of the console choose <strong>Route Tables</strong> and <strong>Create Route Table</strong>. We will then name our table. I named mine PublicRouteTable just to help me remember which subnets I will be choosing for the association. I then chose the VPC for this project, and then select <strong>Create route table</strong>.</p><p>After you create your public route table, click on it to be able to view the <strong>Subnet associations</strong> tab and click the <strong>Edit subnet associations</strong> button. We will select the two subnets we’d like to be associated with our route table and choose <strong>Save associations</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ct6GMb4qOzfMScNfztz0sg.png" /></figure><p>Once back on the screen that shows information about our route table we will also want to go to the <strong>Routes tab</strong> and then select <strong>Edit routes</strong>. We need to make sure the table is set up to reach our Internet Gateway. That is done by editing route, adding a new route and for the destination you are going to put in 0.0.0.0/0 so that this is accessible by anything. Your target will then autofill with your vpc after you have selected Internet Gateway. Fill in that information and click on <strong>Save changes</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yTWV8PcGxDoEAwES_p5AWA.png" /></figure><p>You will then repeat the process with the private route table. Except for the private table, we will want to edit the route and make our Target the <strong>Nat Gateway</strong>. Select <strong>Save changes</strong>.</p><p>STEP 6: Configure the Launch Templates</p><p>Now we are going to set up an Auto Scaling Group for our web tier. The Auto Scaling Group will contain our EC2 Instances and will help us to maintain optimal performance and availability. It will monitor and scale based on our desired performance levels.</p><p>Before we can set up our Auto Scaling Group we will need to create a Launch Template. Go over to the EC2 dashboard and from the menu on the left select <strong>Launch Templates</strong> under Instances and then hit <strong>Create launch template</strong>. We will give our template a name and a description and then scroll down to complete the template. Make sure you check off the box that says <em>Provide guidance to help me set up a template that I can use with EC2 Auto Scaling.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rd4kN2VEd516PWCgtrG_aQ.png" /></figure><p>For the template contents</p><ul><li>I chose Amazon Linux 2 AMI because it is apart of the free-tier and I do not need more that this time.</li></ul><p>For the instance type</p><ul><li>I chose the t2.micro because again it is free.</li></ul><p>For the key pair</p><ul><li>I had already created one but feel free to create one as you will need one.</li></ul><p>Next up we will create a Security Group, name it, give it a description, and select our VPC. Then we will use the drop-down option on the Security Group rule to set up inbound permissions from the internet. We want two Types; ssh and HTTP with a Source type of Anywhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XK-Y5Ht6yuLYWtPTFpt-pg.png" /></figure><p>We will also configure the network interface and the only thing we will touch in that is to Enable the auto-assign IP address — Whether a public IP address is automatically assigned to the primary network interface of the instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MBnPMKuY1UND3ElKq5IFsA.png" /></figure><p>Lastly, we will scroll all the way to the bottom and find the <strong>Advanced details</strong> section where we will add some <strong>User data</strong>. We will create a bootstrap script that will launch an Apache web server.</p><p>#!/bin/bash<br>yum update -y<br>yum install -y httpd<br>systemctl start httpd<br>systemctl enable httpd</p><p>Once we select <strong>Create launch template</strong> we will get a Success message. We will want to do this process again for our application tier. For the application tier launch template, however, we will give it a different name and different security settings. For this security group we’ll allow Custom TCP with 0.0.0.0/0 and ssh with a custom security group. We also do not need to add any information in the User data field.</p><p>STEP 7: Auto Scaling Groups</p><p>Let’s go and make some auto scaling groups! On the navigation menu at the very bottom you will find Auto Scaling Groups.</p><p>We will name our Auto Scaling Group and select the template that we just created for that group and click <strong>Next</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GoTeesiKY5YI3bFNXqHmZg.png" /></figure><p>On the next screen you will see the options to pick the vpc and the subnets for the webtier subnets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sZ_EfKf38VRbyCYgabQiWw.png" /></figure><p>Hit that <strong>Next </strong>button and on the next screen, we will leave the defaults and hit <strong>Next </strong>again. We’ll be brought to a spot where we can configure our Group size. For this project, we will use the desired capacity of 2, a minimum of 2, and a maximum of 3. Leaving the rest of the settings on default we will hit <strong>Next </strong>on each screen until we get to the Review page, or click <strong>Skip to review</strong>. If everything looks good, we’ll finish by selecting <strong>Create Auto Scaling group</strong>. Complete these steps again for the application tier. You’ll want to be sure to use the correct template and subnets that are specific to the application tier.</p><p>Let’s check to see if the web tier is working. To do that, simply go to your EC2 instances and copy and paste the Public IPv4 address into a browser.</p><p>We are almost there!</p><p>STEP 8: Database Tier</p><p>Now we will design the database tier. This is the tier where the information processes by our application will be stored and managed. For this project, we will select RDS (Relational Database Service). RDS is a collection of managed services that make it simple to set up, operate, and scale.</p><p>To begin to build this tier we will locate the <strong>RDS </strong>dashboard<strong> </strong>from the search bar. On the left-hand side, select <strong>Subnet groups </strong>and <strong>Create subnet groups</strong>. We will name our database, give it a description, select our custom VPC, choose our availability zones, add our database subnets, and hit <strong>Create</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Anad2kBhYxlk6zY3sJjg4A.png" /></figure><p>Your details should look something like this.</p><p>After our database has been set up we can go to the RDS dashboard and select <strong>Standard Create </strong>and <strong>MySQL</strong> with a Free tier option.</p><p>Then we give our Database a DB Instance identifier, set up a Master username and Master password.</p><p>We’ll choose our VPC and Subnet group, create a new security group, and leave all other options set to default. Then click the Create database.</p><p>Now we just need to edit our security group so that we can allow inbound access from the application tier. To do this select your database, <strong>Connectivity and security</strong>, and then select your <strong>VPC security groups</strong>. Here you can <strong>Edit inbound rules</strong>. Change the inbound rules to include the security group from your application. You will need to delete the current rule and add 3306 and then add your database security group.</p><p>STEP 9: Testing the set up</p><p>We need to ssh into our ec2 instance and can do so with this command:</p><pre>ssh -i &lt;keypair.pem&gt; ec2-user@&lt;publicipaddress&gt;</pre><p>You also need to make sure you are in the directory that has your keypair file.</p><p>Let’s ping the ip address and make sure we can reach it. I realized that I did not add the ICMP-IPv4 to the inbound rules for our public IP addresses. You can do that by going to the ec2 instances, selecting the web tier instances, going to security groups, and adding an inbound rule. You will then add 0.0.0.0/0 to have it open to everyone and everything.</p><p>Thanks for following along!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a8b1f8249f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Docker Image with NGINX and saving it to AWS ECR]]></title>
            <link>https://medium.com/@aaronclegg/creating-a-docker-image-with-nginx-and-saving-it-to-aws-ecr-a38bddfb747?source=rss-b6aee1ad8f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a38bddfb747</guid>
            <dc:creator><![CDATA[Aaron Clegg]]></dc:creator>
            <pubDate>Mon, 06 Jun 2022 22:31:50 GMT</pubDate>
            <atom:updated>2022-06-06T22:31:50.069Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lx17MG3s40URL7KuywkB_w.jpeg" /></figure><p>In this walkthrough we are going to be creating our own Docker image using NGINX, adding a file that tells us the time of day the container has been deployed, deploy the container with port 8080 open, and then saving it to AWS Elastic Container Registry. Let’s dive in!</p><p>Docker is <em>an open source containerization platform that enables developers to package applications into containers — standardized executable components combining application source code with the operating system (OS) libraries and dependencies required to run that code in any environment (</em><a href="https://www.ibm.com/ae-en/cloud/learn/docker">IBM</a><em>).</em></p><p>Prerequisites</p><ul><li>AWS Account</li><li>Cloud9 set up using Ubuntu along with inbound rules set up to allow all traffic to your ip address. This can be a security concern so make sure it is for testing only and that the rule is removed after you are done.</li><li>If you are doing this project on your CLI, make sure you have AWS CLI installed</li><li>Docker installed</li></ul><p>Step 1</p><p>I will be doing this project out of my Cloud9 setup in AWS. We are going to make a directory we will be working out of</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*uMIIFHkhz4xLMRzrvYpTFw.png" /></figure><p>And now we are going to CD into this directory to start working on our Dockerfile and index.html file that will store the code for our website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*uFIWXElBSItvdGxBTqYSog.png" /></figure><p>With Cloud9 you can either create a file by using the touch index.html command or you can right click on the name of your newly created folder and create a file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*fEshsuMGqce7QzJOLtS7Rw.png" /></figure><p>We are now going to use vim, a text editor, to add code to our index.html file. This code inside the file will serve us a website within our container that will display the date and time the container was deployed. We are going to use the code from this link and insert it into our index.html file. <a href="https://github.com/tonibtech/nginx-docker/blob/main/index.html">https://github.com/tonibtech/nginx-docker/blob/main/index.html</a></p><pre>vim index.html</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bde4-UxniDqgQ_w_WiERiw.png" /></figure><p>After you have copied the code into the file, go ahead and hit ESC and then !wq to write and quit out of it.</p><p>We still have one more file to create and that is our Dockerfile. We are going to repeat the steps of creating a file, open vim, add the content, save it, close it, and confirm we have text in the file by using the cat command. You are going to find the file at this github link — <a href="https://github.com/tonibtech/nginx-docker/blob/main/Dockerfile">https://github.com/tonibtech/nginx-docker/blob/main/Dockerfile</a></p><p>Just wanted to shout out to bmwitcher for the original code to help us avoid errors and get our container rocking and rolling. You can find his github at this link — <a href="https://bmwitcher.medium.com/">https://bmwitcher.medium.com/</a></p><p>The code I’m using in particular is specifically for Ubuntu Linux distributions which is what I’m using and it does a bunch of things for you. This code will run updates, install NGINX, copy your index.html file from your local environment into the Dockerfile you’re creating and it will open port 8080.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*942OTjTMPIm15rKcpwmNpA.png" /></figure><p>Step 2</p><p>Now we are going to build our docker container!</p><pre>docker build -t &lt;nameofyourcontainer&gt; .</pre><p>Make sure you include the “.” at the end! If you don’t, you will run into errors.</p><p>Alright, now we will see the build take place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*ZCQAM-HAhENdjN-Bqji-3A.png" /></figure><p>Now we are going to run our container and connect it to port 8080:80</p><pre>docker container run -d -p 8080:80 &lt;nameofcontainer&gt;:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R7dX5jtbddzXx4ITWpa7AA.png" /></figure><p>And we can also run a command to make sure it is up and running</p><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CirNVE9vADGfWJ82bYSHvQ.png" /></figure><p>Awesome! Now to confirm that our ip address will run our website, we need to grab the ip address from Cloud9 and plug it into the search bar at the top. If you are working in Cloud9 then you will need to go to the “Share” button at the top right of the screen, click on it, and inside you will find an IP address right next to where it says “Application” at the top. Plug that into the search bar followed by :8080. For example 123.12.12.0:8080 and you will get this website:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*06MF3WXFkOErxyli4dGEpw.png" /></figure><p>Step 3</p><p>Alright, we are almost done! Now we are going to upload our container to AWS ECR. If you don’t have the AWS CLI installed on your Cloud9 IDE, you can do so very easily with this command:</p><pre>sudo apt install awscli -y</pre><p>Next we are going to make sure our configurations are good and complete. If we need to add them or change them we can do so with this command:</p><pre>aws configure</pre><p>It will ask you for your access key, secret access key, region, and output format.</p><p>Now we are going to head back to the console and search for ECR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vyQ7Qafe3rvM9aJ8RqT1wg.png" /></figure><p>Name your repository and keep all the settings in the default mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S-zyzigCdVe04X42TKM7oA.png" /></figure><p>Scroll down and hit Create Repository</p><p>Once your repository has been created, select it and hit View push commands</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V5jSrNuQBi8ks97l-SEp4Q.png" /></figure><p>When the window has opened, copy step 1 into the terminal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UY72yBwpOsB3sBJhdbP-0w.png" /></figure><p>Go ahead and skip step 2 andcopy step 3. But for Step 3, you’ll need to replace the name of the repository that was inserted into the command at the beginning and replace it with the Image name. To access the image name of the container you want pushed, input docker ps and navigate to where you see IMAGE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KARsZd67Xl_sejANmJTPow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ykCVjKlk2xhkJH_4sATfxA.png" /></figure><p>For this project example they look to be the same name so we are good there. But if for some reason they are different for you, you will need to take the name your image uses and plug it into the command on step three at the beginning after “tag”.</p><p>After you have run step 3, run step 4 with no changes being made. Once everything is done, you’ll received this notification that your local container’s contents has been pushed up to the AWS repo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2EkQZwZVKXuh0H9Qriba0w.png" /></figure><p>Congratulations and thanks for following along!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a38bddfb747" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a VPC with an Autoscaling Group]]></title>
            <link>https://medium.com/@aaronclegg/create-a-vpc-with-an-autoscaling-group-4fb0f6533ac9?source=rss-b6aee1ad8f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fb0f6533ac9</guid>
            <category><![CDATA[vpc]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[level-up-in-tech]]></category>
            <category><![CDATA[aws-auto-scaling]]></category>
            <dc:creator><![CDATA[Aaron Clegg]]></dc:creator>
            <pubDate>Sat, 16 Apr 2022 01:43:45 GMT</pubDate>
            <atom:updated>2022-04-16T01:43:45.553Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/473/0*l8QEAyzFLqkO9zSG.png" /></figure><p>For the project this week we have a few steps to do!</p><p><em>Create a VPC with cidr 10.10.0.0/16 with an autoscaling group using t2.micro instances. All instances should have apache installed on each instance with the ability to check any random IP address and be able to produce a test page.</em></p><p><em>The instance min and max should be 2 and 5 and should have a scaling policy with cloudwatch to scale after cpu utilization is above 80%</em></p><p><em>After the autoscaling group has been created, find a stress tool to be able to stress an instance above 80% to see if your scaling policy works!</em></p><p>Let’s get started!</p><p><strong>1|</strong> First things first, we are going to create our VPC. We do this by searching for VPC in the console and click on Create VPC in the top right corner. For this project we are going to use the VPC wizard that sets up most everything for us. We do that by clicking on the VPC, Settings, etc under VPC Settings. The only things we need to tweak are the name-tag and the cidr. You can name it what you would like and for the cidr we need to change it to 10.10.0.0/16 as requested. Scroll down and click Create VPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zZwWA95x9it7UwvA5CnQsA.png" /></figure><p><strong>2|</strong> Our next step is to go and create a launch template for our ec2 instance. Search ec2 and on the left side find “launch templates”. Go ahead and name your launch template and give it a description of your choice so you remember what is going on. Beneath that check off the box that says “<em>Provide guidance to help me set up a template that I can use with EC2 Auto Scaling”.</em> After that under the <strong>Application and OS Images (Amazon Machine Image) — required</strong> we will change Amazon Machine Image (ami) to Amazon Linux 2 with the instance type being t2.micro.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IkbS9uyyrjd6hI-rpyPn9w.png" /></figure><p>Keep scrolling down and we will need to either create or choose a key pair that is available to use. After that we will create a specific security group and include some rules that will allow us to access the web page. These rules will also allow us to ssh into the instance and test some things later on. Name your security group, give it a description, and attach the VPC that we created earlier. We will give it two security group rules — the first one being ssh. For both rules we want the source type to be from anywhere. This will leave you wide open and vulnerable so make sure to change your settings when you do this on a real project. Under Advanced Network Configuration we will add a network interface and enable Auto-Assign public IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lKJQZLJiB1wDK8z13f_HtA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S-GY8LBebLAC4Pf7HcZ47w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dy1fKsAIYrUCgHzqkHUejw.png" /></figure><p>One of our last steps is to go under Advanced details and enable <strong>Detailed CloudWatch monitoring.</strong> Keep scrolling down we find the User data. This is where we will attach our bootstrap script. And this is what we will enter:</p><pre>#!/bin/bash<br>yum update -y<br>yum install httpd -y<br>systemctl start httpd<br>systemctl enable httpd<br>amazon-linux-extras install epel -y<br>yum install stress -y</pre><p>Click on Create launch template. Your launch template has been successfully created!</p><p><strong>3|</strong> Our next step is to create an auto-scaling group from the launch template we just created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sf3APHyZ6EU1acPTmOTsrQ.png" /></figure><p>Name your launch template and scroll down and click next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PPMaPFlLT1j5j6XlPcz0Iw.png" /></figure><p>For our network we are going to change the VPC to the one we created and with the availability zones and subnets we are going to choose the two public options to give us more availability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t-0C6iN7ePJ_SccR9gPDrQ.png" /></figure><p>Click on next at the bottom. On the next page the only setting we are going to change is the Additional Settings. We are going to check off the box that says <strong>Enable group metrics collection within CloudWatch.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vsqQKmsT_-Hb5m2ghiG9KA.png" /></figure><p>On the Configure group size and scaling policies page we are going to change a few settings. Under group size we change the Desired Capacity to 2, the Minimum Capacity to 2, and the Maximum Capacity to 5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xCV_9vPBfTqwVrNfGmrw3Q.png" /></figure><p>Under Scaling policies we want to click on the box that says Target tracking scaling policy. You can name it what you would like. The metric type we need is Average CPU utilization with the Target value at 80 and Instances need at 30 seconds. At the bottom, click Next!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Plk6jVd2Duguo4i4yWNx0w.png" /></figure><p>We will not be adding notifications or tags to this project so keep clicking next. At the bottom of the review page, click on Create Auto Scaling Group.</p><p><strong>4|</strong> Search ec2 in the search bar at the top to go back and see your instances. You will see two instances that are starting up. We can check to make sure they are functioning properly by getting the public IPv4 address from them and typing it in the browser search bar. You will notice that just putting in the IPv4 address by itself won’t work. You will need to put in a http://&lt;IPv4 address&gt; to access the website. If you were successful, you will see this page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HH33iB1ouB2mJeUrCdohHg.png" /></figure><p><strong>5| </strong>Now we need to do our stress test. We are going to ssh into our instance with this command:</p><pre>ssh -i &lt;keypairfromyourlaunchtemplate&gt;.pem ec2-user@&lt;ipaddressfromyourinstance&gt;</pre><p>After we are in our instance, we will use this command to start the stress test.</p><pre>sudo stress --cpu 1 --timeout 600</pre><p>As you can see, our instances were stressed out when we look at the monitoring tab in one of our instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oRjTJw5IXmguDsjkAR3b6g.png" /></figure><p>*I will say that I was not able to get the instance stressed out enough to get it to scale up and generate a new instance. I did go back and create a new Target level of 40% and re-tested it. After running the stress test, I was able to have it scale out and get more instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kS79vxVRNiF-DKRfsz-jFA.png" /></figure><p>Thanks for following along!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fb0f6533ac9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a DynamoDB table and load data from the console]]></title>
            <link>https://medium.com/@aaronclegg/how-to-create-a-dynamodb-table-and-load-data-from-the-console-55bdd42600aa?source=rss-b6aee1ad8f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/55bdd42600aa</guid>
            <dc:creator><![CDATA[Aaron Clegg]]></dc:creator>
            <pubDate>Thu, 07 Apr 2022 21:09:49 GMT</pubDate>
            <atom:updated>2022-04-07T21:09:49.073Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*ZUIUMbn32ojciY3bhq8jgQ.png" /></figure><p>Alright we have a new project on our hands. The majority of it is going to be done through the console but it can also be done entirely through the AWS CLI as well. I am going to show you the first option of it being done through the console.</p><p>Knowing how to create a DynamoDB table is a great skill to have! You may ask, what is DynamoDB? Solid question! Here is a definition from Wikipedia that sums it up very well.</p><p><strong>DynamoDB</strong> — Amazon DynamoDB is a fully managed proprietary NoSQL database service that supports key–value and document data structures and is offered by Amazon.com as part of the Amazon Web Services portfolio. DynamoDB exposes a similar data model to and derives its name from Dynamo, but has a different underlying implementation.</p><p>Getting back to the project for this week we have six steps that we need to accomplish and I will walk you through what I did so that we are successful and stress-free at the end of it. Let’s do this thing!</p><p>1.Create a DynamoDB table for something of your choosing (e.g. movies, food, games)<br>2. Add 10 or more items to the table<br>3. Create a t.2micro Ec2 instance<br>4. Using an IAM role and the principle of least privilege, grant the EC2 instance read access to DynamoDB.<br>5. Use the AWS CLI in the EC2 instance to scan the DynamoDB table<br>6. Use the AWS CLI in the EC2 instance to validate you cannot write an item to the DynamoDB table. You should receive an AccessDeniedException error</p><p>My first step is to create the table. This is fairly simple but vital in our journey in this project. I searched for DynamoDB in the search bar and arrived at the DynamoDB dashboard. I clicked on “Create table” and named my table. I named it MLS_Club_Teams and added a partition key (Team Names) and a sort key (Mascot).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IfYdmfRIVDtduM3AbGzN3Q.png" /></figure><p>With that out of the way, I went and created an ec2 instance. During the process of creating this specific ec2 instance, we had to take a small detour and create an IAM role that gave our users read only access to our DynamoDB table. In step three of launching the instance, we see a place to create an IAM role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MS2WKqRo8XJd5a4eFKPtQg.png" /><figcaption>Create new IAM role</figcaption></figure><p>Which then gives us this page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FdPWU-OX5EbMWNnVU2cA3A.png" /></figure><p>We will want to click on the blue “Create role” so that we can create a specific role that will dictate what our users do and do not have access to for this instance. We will want to choose AWS service and choose EC2 for the common use cases and click Next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5jdaku70z9qlN2jGIbmAog.png" /></figure><p>At this next page we will search for the policy we want. In this case it is AmazonDynamoDBReadOnlyAccess.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xXn4BqQIrUu-yWZgfUE5Og.png" /><figcaption>AmazonDynamoDBReadOnlyAccess</figcaption></figure><p>We will then name it and create it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PHDHTEze_5yPn4CDmiK3XQ.png" /></figure><p>Going back to our ec2 instance that we are in the middle of launching, we will go back to that IAM role and find our newly created role. You might have to refresh your page to have it show up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hbyROve9-ENnejXwiRHc0Q.png" /><figcaption>ReadAccessOnly</figcaption></figure><p>We do not need to worry about adding storage or tags with this project so click Next on those pages. With the Security Group we will leave it open to the world for this project but as your specific needs change with work or anything else, feel free to change the addresses and cidr.</p><p>Our last step we need to do is modify the IAM role inside the created instance. Go to actions, click on security, and then Modify IAM role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lS1NjxuShrY4BRVgV6hz9Q.png" /></figure><p>Choose the role that you just created for the read access only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hnczrGJ1vAqJXJRjgJloWA.png" /><figcaption>ReadAccessOnly</figcaption></figure><p>Now we are onto the fun part of testing our work so far! We get to get our hands dirty in the AWS CLI and do some scans and try to write to our table! This is done by going to the instance connect inside the console. You do this by going to your ec2 instance that you created and click on the connect button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KDmV7jwjtpEtDR_GS24IRA.png" /></figure><p>Which will bring you to this page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cOn84AVN_MUX7gNV1cPqcQ.png" /></figure><p>Go ahead and click the orange Connect button which will launch the aws cli from the browser. And let’s try some commands. First we are going to scan our table and see the results.</p><pre>aws dynamodb scan --table-name MLS_Club_Teams --region us-east-1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZT0jRPi0VELYdXHb7xMNhA.png" /></figure><p>We see the items that we added to our table in the console. Next we will attempt to write to the table.</p><pre>aws dynamodb put-item --table-name MLS_Club_Teams --item \ &#39;{&quot;Title&quot;: {&quot;S&quot;: &quot;Name of team&quot;}}&#39; --region us-east-1</pre><p>We should be getting an error saying we do not have the permission to write to the table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VGBV0RAKtALuaq3fGyMIdw.png" /><figcaption>Error</figcaption></figure><p>As we see, we got the AccessDeniedException error trying to add something to the table. If you got this, good job!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55bdd42600aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Launching an EC2 instance with an apache web server]]></title>
            <link>https://medium.com/@aaronclegg/launching-an-ec2-instance-with-an-apache-web-server-3a441520c2a9?source=rss-b6aee1ad8f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a441520c2a9</guid>
            <dc:creator><![CDATA[Aaron Clegg]]></dc:creator>
            <pubDate>Sat, 26 Mar 2022 18:59:25 GMT</pubDate>
            <atom:updated>2022-03-26T18:59:25.076Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q_CId89DEkT4wYpsCW51Ag.png" /></figure><p>Well I can’t get more specific then what my title says we will be doing with this project. I will be telling you what I did and some prerequisites you will need to have a grasp of before you attempt to understand what is going on in this article.</p><p><strong>Prerequisites:</strong></p><ol><li>Understand what an aws ec2 instance is and how to launch one in the console and also in the command line. <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/LaunchingAndUsingInstances.html">https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/LaunchingAndUsingInstances.html</a></li><li>What a security group is and how to create one in the console along with in the command line. You will also need to understand what rules might need to change to get the instance to function. <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-services-ec2-sg.html">https://docs.aws.amazon.com/cli/latest/userguide/cli-services-ec2-sg.html</a></li><li>What bootstrapping is, how to create a file using vim, and what script to use.</li><li>Know which instance you want to use and which distribution suites your needs best.</li></ol><p>Alright, assuming you have your IAM user set up, aws cli installed on your command line, and the excitement to do this project, let’s do this thing!</p><p>The first thing I did was I went and set up my security group through the command line interface (cli). This is an important first step and something we will need to reference later in the project. If you already have a security group set up, you can bypass this step. After I ran this command to create a new group, it gave me a group ID number that I will need to save and reference in a future command.</p><pre>aws ec2 create-security-group --group-name <strong><em>&lt;Insert name here&gt;</em></strong> --description<strong><em> &lt;Insert description here&gt;</em></strong></pre><p>The next step I did was I added inbound rules to my security group. I know from previous experience that I will need the HTTP port open which is TCP port 80. I also know that for this project I will need it open and available to anyone and everyone and I can do that with 0.0.0.0/0.</p><pre>aws ec2 authorize-security-group-ingress --group-id <strong><em>&lt;security group ID&gt; </em></strong>--protocol tcp --port <strong><em>&lt;Port you want to change&gt;</em></strong> --cidr <strong><em>x.x.x.x</em></strong></pre><p>Anytime you want to go and double check to make sure these changes happened, you can log in to the console, search ec2 at the top and find security groups on the left hand side and dig into that to see the changes being made.</p><p>With our security group created, the next step I did was I created a key pair that is vital with this project. <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-services-ec2-keypairs.html">https://docs.aws.amazon.com/cli/latest/userguide/cli-services-ec2-keypairs.html</a></p><p>We have to use the key pairs to connect us to the instances and authenticate us as well. Without key pairs, it will reject us and nothing will be able to happen.</p><p>For this step, I changed directories into my Desktop directory so I know where to find the key pair. I would recommend putting it in a more secure place so it’s not right there and accessible to anyone looking at your computer.</p><pre>aws ec2 create-key-pair --key-name <strong><em>&lt;Name of key-name&gt;</em></strong> --query &#39;KeyMaterial&#39; --output text &gt; <strong><em>FileName</em></strong>.pem</pre><p>From this step on I will be working in my Desktop directory because that is where the key-pair is located.</p><p>Our next step is to open a vim file and write a script inside of it. This will be vital to the bootstrapping part of our project. I opened a vim file and put this inside of it. I also named the file Projectfile.txt. <em>*The script below is written for ubuntu. If you are running a linux distribution, this script will not work.*</em></p><pre>#!/bin/bash<br>apt-get update<br>apt-get  install -y apache2<br>systemctl start apache2<br>systemctl enable apache2</pre><p>After saving the file with :wq!, it is ready to go! I am nearly ready to piece all of this together and run the command to get the web server up and running with apache.</p><p>One of the last steps is to go to the console and find the ami id. I searched for ec2 in the search bar and after getting into ec2, found the instances on the left side. I went to go and launch an instance as if I was going to start the process from the console. I scrolled down to find the free-tier ubuntu version and right after the SSD Volume Type is the ami id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J1zNn2Nl3EmbfANyqWW5Fg.png" /></figure><p>I copied this number down and it was the last piece to the puzzle to launch my instance through the cli. I also need to know what instance type this instance is going to be. For this project I chose a t2.nano.</p><p>In review, the information I created and needed for this project:</p><p>Image id: ami-04505e74c0741db8d</p><p>Instance type: t2.nano</p><p>key-name: SolidKeyPair</p><p>Security-group-ids: sg-011ab5ae47d266e44</p><p>User-data: file://Projectfile.txt</p><p>We are going to use these five bits of information and piece them all together to launch our ec2 instance with an apache web server! We do that by using this command:</p><pre>aws ec2 run-instances --image-id <strong><em>&lt;instance ami id&gt;</em></strong> --count 1 --instance-type <strong><em>&lt;instance type&gt;</em></strong> \<br>--key-name <strong><em>&lt;name of your key pair&gt;</em></strong> --security-group-ids <strong><em>&lt;group id of the security group you chose&gt;</em></strong> \ --user-data file://<strong><em>&lt;Name of your script&gt;</em></strong></pre><p>This is the page that will show up for you if done correctly!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0gQ4Kn49Qcqxbpg1eK7yPQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a441520c2a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Notifications From S3 Bucket]]></title>
            <link>https://medium.com/@aaronclegg/notifications-from-s3-bucket-48e4bd693973?source=rss-b6aee1ad8f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/48e4bd693973</guid>
            <dc:creator><![CDATA[Aaron Clegg]]></dc:creator>
            <pubDate>Sun, 13 Mar 2022 21:28:36 GMT</pubDate>
            <atom:updated>2022-03-14T02:12:46.630Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*cDHe5Q_RDkNt_g-KKxZVcw.png" /></figure><p>This week I learned something new in AWS. I took my original project and decided I wanted more. I wanted to challenge myself. Being new to AWS, that is not a hard thing to do since I am so brand new. My original project was to create a user in IAM and while logged in with that user, create a bucket. I will explain those steps and more as I then show you how to create a topic, subscribe to that topic and attach it to our bucket to get notifications. Let’s talk about a few basic things to get a base understanding for this project. The first two being the root user and IAM user accounts.</p><p><strong>Root users </strong>have the ability to have complete access to all the AWS services and resources in the account. You can create IAM users with less privilege but that can still do a lot.</p><p><strong>IAM (Identity and Access Management) </strong>allows you to create users, groups, add policies, create policies and much more. There is a difference between the root user and an IAM user with admin permissions.</p><p>Now that we have talked about the basics, let’s dig into the project. As more information comes across that we aren’t familiar with, we will talk about it from a high level view so that there is a good understanding of why we are doing what we are doing.</p><p>Step #1</p><p>Our first step is to create a root user if you are brand new with using AWS. You do this by going to the Amazon AWS website at <a href="https://aws.amazon.com/console/">https://aws.amazon.com</a> and click on “Sign In To The Console” at the top right of the screen. This will bring you to the login screen and you will want to click on “Create a new AWS account” to set up your root user. It will ask for your email address and a name for your root user. You will then have to verify that the email address exists. Once you are logged in and set up as a root user, I highly recommend going to your Security Credentials by clicking on your user name at the top right and going down to where it says Security Credentials and clicking on it. Inside Security Credentials you will find different ways to secure your account. The two that I recommend setting up are the Multi-Factor Authentication (MFA) and the Access Keys. You can use the app “Google Authenticator” with the MFA to get the constantly rotating numbers to authenticate the login process to help let AWS know it is you logging in.</p><p>Step #2</p><p>Our second step is to create a IAM user account. While logged in as our root user, we need to search for one of the many AWS services. This particular service is named IAM. At the top search bar we type in IAM and click on it when it shows up under Services. To create a new user, we must click on Users on the far left side. If you have never created a user before, you won’t see any users show up. To create one, we will need to click on Add users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NIPGVRzrNbw_SJvXJ5M2rA.png" /></figure><p>We will then give the user a name and select the credential type. You can give them an access key and a password for maximum security if you would like. This is recommended but for now we will just create a strong password for our new user. After that we can add them to a group, copy permissions or attach existing policies directly to the new user. For this project, we will go ahead and attach the existing policies because they have what we need already. I have chosen the Administrator Access, AmazonS3FullAccess, AmazonSNSFullAccess, and AmazonSNSReadOnlyAccess for this user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NuL03c5n0dNeuPW0nZEWIg.png" /></figure><p>The next step is to apply a tag if you would like. I am not going to for this user. You will then review everything you have done and if you are content with what you have done then go ahead click on Create user at the bottom.</p><p>Step #3</p><p>Our third step is to create the S3 bucket with our new user. To do this, we will need to log out of our root user account and log back in with our newly created user. To log back in, we will need the 12 digit account number of our root account. If you didn’t write this down or put it somewhere to easily find it, don’t worry, just log back in and click on your account name at the top right corner. Once you have clicked on it, you will see your 12 digit number. It is important to note that when you are logging in with your IAM user, you will need to put in the numbers without the dashes. You can also create an account alias or a different name to type in when you log in with the IAM user instead of having to type in 12 digits.</p><p>Now that we are logged in with our new user, we will now go and create the S3 bucket. Search for S3 at the search bar above and click on S3 under services. You will then click on Create bucket and start the process. You will need to name the bucket and choose a region.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cL97C-yczQXsafiY6t31Ig.png" /></figure><p>When you name the bucket, you will need to choose a name that is unique and hasn’t been chosen before. As for the region, I chose us-east 1 for mine which is based out of N. Virginia. I didn’t touch any of the other settings because I don’t feel like I needed to for this project but there is a lot you can customize and change as you see fit. The only item I did change was the default encryption. This goes back to the best practices of having good security measures. I chose the managed key as I am comfortable with Amazon managing that for me. At the bottom click on create bucket and it will create one for you that you will see in your bucket list.</p><p>Step #4</p><p>Now that we have our bucket created, lets go and create a topic. This is done through the Simple Notification Service (SNS). To create the topic, we need to click on Create topic. It will ask you what type you want to do and for this project I chose Standard because we will be getting notifications sent to our email. Remember the name you gave your topic because it will come in handy in later steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jydG_pXH1Dg_DAZz_vJ0bA.png" /></figure><p>We will not encrypt the topic right now. For the next step you will then want to choose the Basic Access Policy and for me and this project I chose that only the Topic Owner can publish and subscribe to this topic. Everything else is optional so we will not mess with those at this time. Go ahead and click Create topic and it will be created for you! You will see the name, ARN, type and other details about your topic.</p><p>Step #5</p><p>This quick step is about subscribing to the topic. On the left hand side you will see Subscriptions. Click on that and inside this tab we will click on Create Subscription on the right side. The first thing we are going to do is link the subscription to the topic we just created. Underneath Topic ARN we are going to click on the magnifying glass and it will bring up our topic we just created. If you have multiple topics, the way to find yours is finding the name of the topic at the end of the ARN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y_yo-79fixqbg16W2Y6N9g.png" /></figure><p>Next you will select the protocol. For this project we are going to select email. The endpoint is where we will type in the email that we want to receive the notifications. We will have to confirm the email exists so once we have clicked on Create subscription, go to your email and find the verification email from Amazon. Until you verify the email, the status of the subscription will be “Pending”.</p><p>Step #6</p><p>We are almost done! Let’s go back to the s3 bucket we created and create the notification alerts for when objects are added or removed from the bucket. While inside our new bucket, we will want to click on the “Properties” tab and scroll down to where it says Event notifications. You will see that we have no current notifications. Click on Create event notification to get the process started. You are welcome to name it whatever you like to help you remember why you are getting the notifications. Under Event types we are going to check the boxes with Object creation and Object removal. You can get notifications for other events if you’d like but for now we are going to stick with the two I chose. Scrolling down further we are going to choose the Destination and save our changes. The destination we want is the SNS Topic because we created one and for the SNS Topic we are going to choose the topic we created. Click on Save changes. If you got the error, don’t worry, we will go back and figure out why.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GqV_-8thU9ZKEnaQmcuccA.png" /></figure><p>After doing some research to find out why we are getting this error, we are directed back to our access policy with our topic. Let’s go edit that. After getting into the Access policy and seeing that we are going to edit the JSON editor, we have some things we will need to change. I have found at this website exactly what we need to do. <a href="https://twwip.com/2019/12/17/how-to-fix-the-issue-to-allow-s3-to-publish-message-to-an-sns-topic-explained/">https://twwip.com/2019/12/17/how-to-fix-the-issue-to-allow-s3-to-publish-message-to-an-sns-topic-explained/</a> . We are going to completely erase our access policy and replace it with step #4 from the website from the link above. You will need your topic ARN and your bucket ARN for this to work. For the ID and the SID lines you will want to name them the name of your topic and bucket. You will then plug in your topic ARN and bucket ARN in their appropriate lines. Once you have made these four changes, click the save changes and go back to your bucket and repeat the first half of step #6 from this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CercYi-EDBLsIwJ8YcUYnw.png" /></figure><p>After clicking on Save changes you will see a green box that says you successfully created an event notification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HJqfw6NOWhNFOeE2pg1A-A.png" /></figure><p>You can test that you are getting notification emails by adding something to your bucket and deleting from your bucket and you should be getting emails for both events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jpMvNFoeKyo9kLG1QyGOxw.png" /><figcaption>Email letting me know something has been added to my bucket</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48e4bd693973" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>