<?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 Mikayla Pham on Medium]]></title>
        <description><![CDATA[Stories by Mikayla Pham on Medium]]></description>
        <link>https://medium.com/@mikaylapham?source=rss-865021e8f9d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*58omwbvkBpubNnuo6DDLaQ.jpeg</url>
            <title>Stories by Mikayla Pham on Medium</title>
            <link>https://medium.com/@mikaylapham?source=rss-865021e8f9d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 11:55:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mikaylapham/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 a Docker Swarm on AWS]]></title>
            <link>https://medium.com/@mikaylapham/creating-a-docker-swarm-on-aws-19c11d18e701?source=rss-865021e8f9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/19c11d18e701</guid>
            <dc:creator><![CDATA[Mikayla Pham]]></dc:creator>
            <pubDate>Thu, 01 Jun 2023 01:50:33 GMT</pubDate>
            <atom:updated>2023-06-01T01:50:33.780Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*4p2q9pGNiULh0c4wzWLcWw.png" /></figure><p>In this article, we will be exploring Docker Swarm as we strive to achieve the following project goals.</p><h3>Project Objectives:</h3><p><em>Using AWS, create a Docker Swarm that consists of one manager and three worker nodes.</em></p><p><em>Verify the cluster is working by deploying the following tiered architecture:</em></p><ul><li><em>a service based on the Redis docker image with 4 replicas</em></li><li><em>a service based on the Apache docker image with 10 replicas</em></li><li><em>a service based on the Postgres docker image with 1 replica</em></li></ul><p><strong>Presiquites:</strong></p><ol><li>AWS Account</li><li>CLI</li><li>Some Docker Knowledge.</li></ol><h3>Step 1: Create Security Groups for our Nodes</h3><p>First off, we need to create <strong><em>Security Groups</em></strong> for our <strong><em>Manager and Worker Nodes.</em></strong></p><p>To create a <strong><em>Security Group</em></strong>, navigate to <strong><em>EC2 Dashboard</em></strong>, select <strong><em>Network &amp; Security</em></strong> &gt; <strong><em>Security Groups</em></strong>, then click on <strong><em>“Create Security Group”</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sP6taq8Y3k1WPE1b41b_tA.png" /></figure><p>The first <strong><em>Security Group</em></strong> we’ll be creating is for our <strong><em>Manager Node.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o9jCssMxbVn6VTbLwedW8g.png" /><figcaption>Pick our Default VPC</figcaption></figure><p>We’ll add the following <strong><em>Inbound Rules</em></strong> for our <strong><em>Manager Node’s Security Group.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mJ_c7c9wR_EqbCZFcHVGoQ.png" /><figcaption>Inbound Rules for Manager Node</figcaption></figure><p>Below are further explanations on what each port is used for quoted from this Docker tutorial, <a href="https://docs.docker.com/engine/swarm/swarm-tutorial/"><strong><em>HERE</em></strong></a></p><blockquote><strong>Open protocols and ports between the hosts</strong></blockquote><blockquote>The following ports must be available. On some systems, these ports are open by default.</blockquote><blockquote>Port 2377 TCP for communication with and between manager nodes</blockquote><blockquote>Port 7946 TCP/UDP for overlay network node discovery</blockquote><blockquote>Port 4789 UDP (configurable) for overlay network traffic</blockquote><blockquote>If you plan on creating an overlay network with encryption (--opt encrypted), you also need to ensure <strong>IP protocol 50</strong> (<strong>IPSec ESP</strong>) traffic is allowed.</blockquote><p>Once these Inbound Rules are added, click on <strong><em>“Create Security Group”</em></strong> to finish <strong><em>Manager Node’s Security Group</em></strong> creation.</p><p>Next up, Let’s create another <strong><em>Security Group</em></strong> with the following <strong><em>Inbound Rules</em></strong> for our <strong><em>Worker Nodes:</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5T1CPhHbM_rDNF8ivwCX8w.png" /></figure><h3>Step 2: Create Manager and Worker Nodes.</h3><p>First, we’ll launch our <strong><em>Manager Node</em></strong> by navigating back to <strong><em>EC2 Dashboard</em></strong>, then click on <strong><em>“Launch an Instance”.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*yrKE9BhcQCyhLrcMwdM7gg.png" /><figcaption>Name our Instance.</figcaption></figure><p>Choose <strong><em>t2.micro</em></strong> for <strong><em>Instance Type</em></strong>, and select a <strong><em>Keypair</em></strong> (I’m using my existing Keypair)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*14b4Oy12BCuUHwNI3aW7GA.png" /></figure><p>Under <strong><em>Network Settings</em></strong>, select the <strong><em>Security Group</em></strong> we just created previously for our <strong><em>Manager Node</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*cGMbRu8bZaknKGLlOp6lvQ.png" /></figure><p>In <strong><em>Advanced Details</em></strong>, under <strong><em>User Data</em></strong>, input the following script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96d0b1294bc41b2467407b1aa1d1898c/href">https://medium.com/media/96d0b1294bc41b2467407b1aa1d1898c/href</a></iframe><p>This script will update our system, install Docker, start the Docker service, and configure it to start automatically upon system boot-up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*r11iEn2iafEGfZ05GPMS2Q.png" /></figure><p>Double-check that everything looks correct, then click on <strong><em>Launch Instance</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*REE_LnidoKHfxQvNWVDJyQ.png" /></figure><p>Now we’ll be going through similar steps to create our (3) <strong><em>Worker Nodes</em></strong>. Make sure to select the <strong><em>Worker Security Group</em></strong> we created for this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*ocCB6XofvaBZcsyPb73Ecg.png" /></figure><p>Change the <strong><em>Number of Instances</em></strong> to “<strong><em>3</em></strong>” because this is the requested amount in our <strong>Objectives</strong>, then proceed to click on <strong><em>“Launch Instance”.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*X7QkXi4LQcvhbywVfIPgeg.png" /></figure><p>Now we’ll have (4) instances up and running — (1) Manager Node and (3) Worker Nodes (I renamed my Worker Nodes for easy identification)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*MO4iByBRRcyYOvn0At2SFg.png" /></figure><h3>Step 3: Initialize Docker Swarm</h3><p>Let’s connect to our <strong><em>Manager Node</em></strong> via SSH.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*vSJHTu6LWSEDtNO8ylAJgg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*JgGqZldDWDGND6sktqVlGw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*ZWvU_VPfl1w6V9AtbAIlzw.png" /><figcaption>Make sure to Change Directory to where your Keypair was saved.</figcaption></figure><p>Run the following command(s) to switch to root user and check Docker version to verify that Docker was successfully installed.</p><pre>#Switch to root user<br>sudo su<br><br>#Check Docker Version<br>docker version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*IG3_68Zn0--Et9I-bHKW9A.png" /></figure><p>Now, let’s initialize Docker Swarm with the following command:</p><pre>docker swarm init</pre><p>Next, make sure to save the join token info, as we’ll need it for our (3) Worker Nodes to join the Swarm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QHLF6vHJm1NvGZVtidlc8Q.png" /></figure><h3>Step 4: Join Worker Node(s) to the Swarm</h3><p>First, SSH into a <strong><em>Worker Node</em></strong> and run the script below to verify that Docker was successfully installed.</p><pre>#Switch to root user<br>sudo su<br><br>#Check Docker Version<br>docker version</pre><p>Then, paste in the join token command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_n1sypr9Nt-YHdJEaaB6lQ.png" /><figcaption>Worker Node — 1 joined.</figcaption></figure><p>Now, let’s do that for the rest of our Worker Nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PU2g4H-jjOy3O-_aLTCTHA.png" /><figcaption>Worker Node — 2 joined.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GmVbYHzRZiXUPPAYT7D5vQ.png" /><figcaption>Worker Node — 3 joined.</figcaption></figure><p>Now, in our Manager Node, let’s run the following command to list all the nodes:</p><pre>docker node ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OXDmKTtp_wgeDsO8tfE9Xg.png" /><figcaption>All (4) nodes are there!</figcaption></figure><h3><strong>Step 5: Deploying </strong>the tiered architecture</h3><ul><li><strong><em>Redis docker image with 4 replicas:</em></strong></li></ul><p>To create the Redis service with (4) replicas, execute the following command:</p><pre>docker service create --name redis --replicas 4 redis:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*-H0lsmbwLdqPJLrzdsM2VQ.png" /></figure><ul><li><strong><em>Apache docker image with 10 replicas:</em></strong></li></ul><p>To create the Apache service with (10) replicas, execute the following command:</p><pre>docker service create --name apache --replicas 10 httpd:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*NbxthCgwiDNNNlgpd4KXWw.png" /></figure><ul><li><strong><em>Postgres docker image with 1 replica:</em></strong></li></ul><p>To create the Postgres service with (1) replicas, execute the following command:</p><pre>docker service create --name postgres_service --replicas 1 -e POSTGRES_PASSWORD=mypasswd postgres</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*umn-aS0TS49sQD5lHbOdyQ.png" /></figure><p>Now, let’s verify that our services were successfully replicated:</p><pre>docker service ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*wMBDeDT-Q4NRQFocW-OwuA.png" /><figcaption>SUCCESS!</figcaption></figure><p>We have successfully created our (4) nodes and replicated the required services based on our Objectives!!</p><p>P/S: Please make sure to stop your EC2 instances to avoid unnecessary charges.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19c11d18e701" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Ubuntu Docker Containers with Boto3/Python]]></title>
            <link>https://medium.com/@mikaylapham/creating-ubuntu-docker-containers-with-boto3-python-467d570d7c40?source=rss-865021e8f9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/467d570d7c40</guid>
            <dc:creator><![CDATA[Mikayla Pham]]></dc:creator>
            <pubDate>Tue, 02 May 2023 06:44:20 GMT</pubDate>
            <atom:updated>2023-05-02T06:44:20.651Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rMAsHHFkskoc5LyWZybY5w.jpeg" /></figure><p>Hello everyone! In this article, we will explore Docker by pursuing the following project objectives.</p><h3>Project Objectives:</h3><ul><li>Build a docker file for Boto3 / Python</li><li>Use either the Ubuntu or Python official images on Dockerhub</li><li>Download any three repos to local host.</li><li>Create three Ubuntu containers</li><li>Each container should have a bind mount to one of the repo directories</li><li>Log into each container and verify access to each repo directory</li></ul><p><strong>Prerequisites:</strong></p><ol><li>AWS Account</li><li>IDE of choice (I’ll be using AWS Cloud9)</li><li>Some Docker &amp; containerization knowledge.</li></ol><h3>Step 1: Build a docker file for Boto3 / Python</h3><p>To begin, create a new directory for this project in your IDE environment, and then navigate “<em>cd”</em> to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*al_hYy8WrbcAxuNtttdBgw.png" /></figure><p>Next, use the <em>“vim”</em> command to create and edit our Docker file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*kikO2SC0TNUpAnLXctAdJw.png" /></figure><p>In our <em>Vim</em> editor, input the following code. (Make sure to edit the working directory on Line 8 to the directory name created previously)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34eec61219ed42cb1d38a604687a0a9d/href">https://medium.com/media/34eec61219ed42cb1d38a604687a0a9d/href</a></iframe><p>Line 1 — Creates a Dockerfile for building a Docker image that has Python 3.9 as its base image.</p><p>Line 3 &amp; 4 — Updates the package list and installs the required dependencies.</p><p>Line 6 — Installs the Python package “boto3” using pip3.</p><p>Line 8 — Specifies the working directory based on user input. (replaces <em>#INSERT_DIRECTORY_NAME</em> with an actual directory name).</p><p>Line 10 — Sets the default command to tail the <em>/dev/null</em> file, which means that when the Docker container is launched, it will simply run in the background and do nothing until it is stopped or deleted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*H1hBr8Ukg_0FLK2EdI4jcQ.png" /></figure><p>Use the following command to build out the docker image.</p><pre>docker build -t python .</pre><p>This will create a Docker image with the tag name “python” using the Dockerfile in the current directory “.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*2ozt9NaZoX6eyzffm-xxww.png" /></figure><p>Verify the image has been built with the command below:</p><pre>docker image ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*Z0-6t5aN-BxHvcQadQNxvQ.png" /><figcaption>Here it is!</figcaption></figure><h3>Step 2: Download any three repos to local host</h3><p>Use the following command to clone any (3) repositories:</p><pre>git clone &lt;GitHub Repository URL&gt;</pre><p>Then use <em>“ls”</em> to verify that those repositories have been cloned to our working directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*_i5uwpUnnA9QC56Pee3Elw.png" /></figure><h3><strong>Step 3: </strong>Create three Ubuntu containers and bind mount to the downloaded repos.</h3><p>Use the following code to create and run (3) Docker containers with specified names, using the Ubuntu image.</p><pre>docker run -d -t --name INSERT_CONTAINER_NAME -v &quot;$(pwd)&quot;/INSERT_REPOSITORY_NAME/INSERT_WORKING_DIRECTORY ubuntu</pre><p>Here is a breakdown of the options used in the command:</p><ul><li><em>“docker run”</em> command is used to run a Docker container.</li><li><em>“-d”</em> option runs the container in the background (detached mode) and prints the container ID.</li><li><em>“-t”</em> option allocates a pseudo-TTY terminal.</li><li><em>“ — name INSERT_CONTAINER_NAME”</em> option sets the name of the container to a specified name.</li><li><em>“-v”</em> option creates a bind mount - In our case, this maps the current working directory to a specified directory. <em>“$(pwd)”</em> is a shell command that returns the current working directory path.</li><li><em>“ubuntu”</em> specifies the base image for the container. The container will run a new instance of the Ubuntu operating system.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*oTRBhjhKWooDXqHBVXq_SQ.png" /></figure><p>Use the following command to display a list of all the containers that have been created:</p><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*Hg2Mcb5G1NNS9leIx7PPMg.png" /></figure><h3>Step 4: Log into each container and verify access to each repo directory</h3><p>Next, we will verify if each container can access its corresponding repository directory with the following command:</p><pre>docker exec -it &lt;INSERT_CONTAINER_NAME&gt; bash</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*M3cG-_zuHd9cB3ElCxKwzw.png" /></figure><p>Yay! Our objectives have been met!</p><p>Lastly, let’s stop and remove the (3) containers we had created.</p><pre>docker stop &lt;INSERT_CONTAINER_NAME&gt;<br>docker container rm &lt;INSERT_CONTAINER_NAME&gt;</pre><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=467d570d7c40" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intergrating Python, Lambda & SQS]]></title>
            <link>https://medium.com/@mikaylapham/intergrating-python-lambda-sqs-844f9f7be7ce?source=rss-865021e8f9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/844f9f7be7ce</guid>
            <dc:creator><![CDATA[Mikayla Pham]]></dc:creator>
            <pubDate>Sun, 30 Apr 2023 01:01:14 GMT</pubDate>
            <atom:updated>2023-04-30T01:02:17.767Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*HVacsaWHhcQnNb4BsYsOdQ.png" /></figure><p>In this article, we will go through the process of using Python to create an SQS queue to integrate with a Lambda function, and API Gateway trigger to track customer orders based on the scenario below. Follow along to get started with this step-by-step guide.</p><h3><em>Scenario:</em></h3><p><em>A company wants to create a system that can track customer orders and send notifications when orders have been shipped. They want to use AWS services to build the system. They have decided to use SQS, Lambda, and Python for the project.</em></p><p><em>All code should be inline commented.</em></p><p><em>1)Create a Standard SQS Queue using Python.<br>2) Create a Lambda function in the console with a Python 3.7 or higher runtime<br>3) Modify the Lambda to send a message to the SQS queue. Your message should contain either the current time or a random number. You can use the built-in test function for testing.<br>4) Create an API gateway HTTP API type trigger.<br>5) Test the trigger to verify the message was sent.</em></p><p><strong>Prerequisites:</strong></p><ol><li>AWS Account</li><li>IDE of choice (I’ll be using AWS Cloud9)</li><li>Some Python Knowledge.</li></ol><p><strong>Note:</strong> If haven&#39;t done so, it’s crucial to update your IDE with the latest version of Boto3 by running the following command before getting started:</p><pre>pip3 install boto3</pre><h3>Step 1: <em>Create a Standard SQS Queue.</em></h3><p>The first step is to create a <strong>Standard SQS (Simple Queue Service)</strong> queue and we can achieve this using <strong>Python</strong>. Head to your IDE of choice to start a <strong>Python</strong> script (I’ll be using <strong>AWS Cloud9</strong>).</p><p>Since we already have <strong>Boto3</strong> installed, we can create our new Python script following the code shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f844d9df6205fc442c3bf1336a396d3b/href">https://medium.com/media/f844d9df6205fc442c3bf1336a396d3b/href</a></iframe><p>This Python script allows us to create an <strong>SQS queue</strong> without going through <strong>AWS console</strong>. Once the script gets run, we will receive a direct link to the newly created <strong>SQS</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*arUmkCAFasHAO97i5hIlfg.png" /></figure><p>In our <strong>SQS Dashboard</strong> on <strong>AWS Console</strong>, we can see that our <strong>SQS queue</strong> was successfully created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*3OESXjldHVpW1VeZkvJ1Xg.png" /></figure><h3>Step 2: Create a L<em>ambda function in the console with a Python 3.7 or higher runtime.</em></h3><p>Navigate to Lambda Dashboard on AWS Console to create a new Lambda function using the settings shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*3pDZtoiZhySQLm172Q9N5g.png" /><figcaption>Choose your latest supported Python Runtime</figcaption></figure><p>In order for the Lambda function to interact with the <strong>SQS Queue</strong> that was created earlier, it’s necessary to set appropriate permissions. To edit permissions, under the <strong>“Configuration”</strong> tab, choose <strong>“Permissions”</strong> then click on our Role Name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*uQi4fq18EiXut-Y0qi5rrQ.png" /></figure><p>A new window will pop up, under <strong>“Permissions policies”</strong>, click on <strong>“Add permissions” </strong>and select <strong>“Attach policies”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VwXrsw9wWZRsaTYATac4dA.png" /></figure><p>Find and attach the <strong>“AmazonSQSFullAccess”</strong> policy to permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*705PCz8w6lC7WZaz1WVANg.png" /></figure><p>Once done, our permission policies should look like shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*nnG9EgW8hO6piPbq8R2tPQ.png" /></figure><h3>Step 3: <em>Modify the Lambda to send a message to the SQS queue.</em></h3><p>Let’s head back to our <strong>Lambda Dashboard</strong> to update our Lambda function. Under the <strong>“Code”</strong> tab, replace the current JSON code with the one below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84421c6ec90428b96e4cca1286f0b2b6/href">https://medium.com/media/84421c6ec90428b96e4cca1286f0b2b6/href</a></iframe><p>Input the <strong>URL</strong> we retrieved earlier from our IDE to where said <strong>“URL”</strong> on Line 15.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*r1UXjpoTC05BzbxL8GfpQA.png" /></figure><p>Next up, we’ll test our function. Click <strong>“Deploy”</strong>, then under <strong>“Test”</strong> select <strong>“Configure Test Event”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*YthssY4Vo6X3lsnmDLUvcQ.png" /></figure><p>Name our test event and choose <strong>SQS</strong> under the <strong>Template</strong> drop-down menu then save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*-T3EFNtrmeJySSM3rT7bAQ.png" /></figure><p>Once done, click on “Test”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C3rxGlj8wo43LgE9p6M0FQ.png" /><figcaption>Success! The lambda function can communicate with our SQS queue.</figcaption></figure><h3>Step 4: <em>Create an API gateway HTTP API type trigger.</em></h3><p>Under the “<strong>Function Overview</strong>” tab, select “<strong>Add trigger</strong>” to create an API gateway HTTP API type trigger for our Lambda function using the settings shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*ELvW6CbUe2Cafq9Lhgy-Mg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*kv9eB56d6Jrou1WLN7sPWg.png" /></figure><p>And now, our Lambda function can be triggered by API Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*c_glocvP6V90tjdBJdZeVg.png" /></figure><h3><em>Step 5: Test the trigger to verify the message was sent.</em></h3><p>Under the <strong>“Configuration”</strong> tab, select<strong> “Triggers”</strong>, then copy the <strong>URL</strong> content of API endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q8sk__uar71tmlJsv6iZKQ.png" /></figure><p>Paste it into your web browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*a6oE60ex_bvkF8iP6Umh0A.png" /></figure><p>Next, navigate to <strong>AWS SQS Dashboard</strong>, select the <strong>SQS queue</strong> we had created, and click on <strong>“Send and Receive Messages”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UtCxDhMTe6ODtZJyqbM-CA.png" /></figure><p>Scroll down and click on <strong>“Poll for messages”</strong>, then click on the latest (or the top) message on the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mkv6UF6Z1hS-GxgKbJNZdA.png" /></figure><p>The pop-up message should have the same timestamp as the message we got from our browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*nGk-E8VNxMpP8puCdA4v_w.png" /></figure><p>We’ve accomplished our goal! The Lambda function was triggered by API Gateway and has effectively sent a message to an SQS queue.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=844f9f7be7ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python — Start & Stop EC2 Instances]]></title>
            <link>https://medium.com/@mikaylapham/python-start-stop-ec2-instances-34ae6ab9cafe?source=rss-865021e8f9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/34ae6ab9cafe</guid>
            <dc:creator><![CDATA[Mikayla Pham]]></dc:creator>
            <pubDate>Sun, 23 Apr 2023 08:02:31 GMT</pubDate>
            <atom:updated>2023-04-23T08:11:52.008Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*_nawNenkZ-QBJsPSpHHGGw.png" /></figure><p>In this article, we will learn how to create a <strong>Python</strong> script to start &amp; stop <strong>EC2 instances</strong> based on the following scenario.</p><h3><strong>Scenario:</strong></h3><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 (for this example) 3 ec2 instances after all engineers are clocked out.</em></p><p><em>Create a Python script that you can run that will stop all instances. Push your code to GitHub and include the link in your write-up.</em></p><p><strong>Prerequisites:</strong></p><ol><li>AWS Account</li><li>AWS CLI</li><li>IDE of choice (I’ll be using AWS Cloud9)</li><li>Some Python Knowledge</li></ol><h3>Let’s begin with creating some EC2 instances with Python script!</h3><p>First up, we need to import <strong>Boto3</strong> library. <strong>Boto3</strong> is the <strong>Amazon Web Services (AWS) SDK</strong> for <strong>Python</strong>, which allows developers to write software that makes use of services like <strong>Amazon S3</strong> and <strong>Amazon EC2</strong>. Therefore, to interact with our <strong>EC2</strong> instances, we need to import <strong>Boto3</strong> library. Spin up our IDE (<strong>AWS Cloud9)</strong> and install <strong>Boto3</strong> with the following command:</p><pre>pip install boto 3</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*ypEnx8MwPcohbU74QPP1fQ.png" /><figcaption>Install Boto3</figcaption></figure><p>Then, install AWS CLI with the following command:</p><pre>pip3 install awscli</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*ZJZNY429Aoy92LFMN5KsqA.png" /><figcaption>Install AWS CLI</figcaption></figure><p>Next, we need to get <strong>AMI ID</strong> from our <strong>ASW Console</strong>. To do so, navigate to <strong>EC2 Dashboard</strong>, click on <strong>“Launch Instance”</strong>, and find <strong>AMI ID</strong> under “<strong>Application and OS Images (Amazon Machine Image)”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*5rW67OYDBlfgZJQ2MRA3SA.png" /><figcaption>Obtain AMI ID</figcaption></figure><p>Navigate back to <strong>AWS Cloud9</strong> terminal, let’s start our <strong>Python</strong> script to spin up some <strong>EC2 instances</strong> with the <strong>AMI ID</strong> we just obtained. Below is the full script with a more detailed explanation underneath.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3097dceee06ed3c9be4ef8014ee09951/href">https://medium.com/media/3097dceee06ed3c9be4ef8014ee09951/href</a></iframe><ul><li>Line 3 — <strong><em>“import boto3”</em></strong> statement loads the Boto3 library to interact with AWS services. Once imported, the boto3 module can be used to create clients and resources for interacting with AWS services.</li><li>Line 5— <strong><em>“ec2 = boto3.resource(‘ec2’)”</em></strong> statement creates an EC2 resource object using the Boto3 library.</li><li>Lines 7 to 12 —These codes create (3) EC2 instances in our ASW account. Here’s a breakdown of the parameters used in this call:</li></ul><blockquote><strong>ImageID:</strong> The ID of the Amazon Machine Image (AMI) that should be used to launch the instance. In this case, the “<strong>ami-069aabeee6f53e7bf”</strong> AMI is being used.</blockquote><blockquote><strong>InstanceType:</strong> The type of EC2 instance that should be launched. In this case, a “<strong>t2.micro”</strong> instance is being launched.</blockquote><blockquote><strong>MaxCount: </strong>The maximum number of instances that should be launched. In this case, three instances are being launched.</blockquote><blockquote><strong>MinCount:</strong> The minimum number of instances that should be launched. In this case, three instances are being launched.</blockquote><p>Runs the script to create our (3) EC2 Instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*ISfGiy2igNdMRBcr5vWrvA.png" /></figure><p>Navigate back to <strong>EC2 Dashboard</strong> on <strong>AWS Console</strong> to check that the instances are up and running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yaHz8N5fwKAtDT4fuhUH3w.png" /><figcaption>The (3) EC2 instances are up and running!</figcaption></figure><h3><strong>Let’s create a Python Scrip to stop our EC2 instances!</strong></h3><p>Now that we have our EC2 Instances up and running. Now let’s delve into Python script to stop these instances. My final Python script is below with a more detailed explanation underneath.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4e675fc230881daa0d84ac78534cda3/href">https://medium.com/media/b4e675fc230881daa0d84ac78534cda3/href</a></iframe><ul><li>Line 1 — <strong>“import boto3”</strong>. Again, this line imports the Boto3 library, which is used to interact with AWS services.</li><li>Line 3 — <strong><em>“ec2 = boto3.resource(‘ec2’)”</em></strong> creates a new EC2 resource object using the <strong><em>boto3.resource</em></strong> method.</li><li>Lines 4 to 6 — these lines stop EC2 instances with specified instance IDs in the following format:</li></ul><pre>ec2.Instance(&#39;INSERT_INSTANCE_ID_HERE&#39;).stop()</pre><p>Run this Python script then check back on our AWS Console to make sure the (3) EC2 Instances we created had been stopped.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*j0WR0VtSEmBmg1CqBMRYPQ.png" /><figcaption>And they’re gone!</figcaption></figure><p>There we have it - 2 Python scripts that start and stop EC2 instances. I pushed these codes onto my GitHub account. Please find them in the links below:</p><p><a href="https://github.com/mikaylapham/gold-member/blob/083d9afc97ebeaca16a08be8a218caa2159ef1e7/create_ec2.py">start_ec2.py</a> | <a href="https://github.com/mikaylapham/gold-member/blob/083d9afc97ebeaca16a08be8a218caa2159ef1e7/stop_ec2.py">stop_ec2.py</a></p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34ae6ab9cafe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python —Generating a List of Dictionaries]]></title>
            <link>https://medium.com/@mikaylapham/python-generating-a-list-of-dictionaries-f6301b3bb514?source=rss-865021e8f9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6301b3bb514</guid>
            <dc:creator><![CDATA[Mikayla Pham]]></dc:creator>
            <pubDate>Thu, 13 Apr 2023 05:10:07 GMT</pubDate>
            <atom:updated>2023-04-13T05:10:07.026Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*ReZ-FfeO9JZ0BcDDVgA9dQ.png" /></figure><p>In this article, we will explore how to use <strong>Python</strong> and <strong>AWS Cloud9</strong> to generate a list of dictionaries for files in our working directory, which can be useful for organizing and manipulating data efficiently in our Python programs.</p><p>What is <strong>Python</strong>? and A<strong>WS Cloud9</strong>?</p><p><strong>Python</strong> is a popular high-level programming language. It offers an efficient way to solve a wide variety of problems, ranging from simple scripts to complex applications.</p><p><strong>Cloud9</strong> is a cloud-based integrated development environment (IDE) from Amazon Web Services (AWS), that provides a flexible and scalable environment for developing and running applications in the cloud. With <strong>Cloud9</strong>, you can easily access your files and execute <strong>Python</strong> scripts from a web browser, without the need for local setup and installation.</p><h3>Scenario:</h3><p><em>“Your company needs to learn about the files located on various machines. You have been asked to build a script that extracts information such as the name and size of the files in the current working directory and stores it in a list of dictionaries.‌</em></p><p><em>Create a script to that generates a list of dictionaries about files in the working directory. Then print the list.”</em></p><p><strong>Prerequisites:</strong></p><ol><li>AWS Cloud9.</li><li>Some Python knowledge.</li></ol><h3>Let’s begin!</h3><ul><li>First up, we need to boost up our <strong>AWS Cloud9</strong> environment.</li><li>Then, proceed to create a new file — <strong><em>File &gt; New From Template &gt; Python File.</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*6Ck7t6b8NCF4omUHm1cmkQ.png" /></figure><ul><li>Once it’s opened up, click <strong><em>Ctrl+S</em></strong> to name and save our Python file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*6O92KXIirml8NpEPnNGZ6A.png" /></figure><ul><li>Next, in our command lines, <strong><em>CD</em></strong> (change directory) into where we had just saved our file, and grant executable permission to our script with the following command:</li></ul><pre>chmod u+x InsertFileName</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*mO2dXz-S6fE0gOXWkI4wxQ.png" /></figure><h3><strong>Now let’s delve into our Python script!</strong></h3><ul><li>Shown below is my final script — I’ll refer to each code line with a more detailed explanation underneath.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bf8ed642c9413a0cc9885de2c29cb02/href">https://medium.com/media/7bf8ed642c9413a0cc9885de2c29cb02/href</a></iframe><ul><li>Line 3 — <em>“import os”</em> allows us to access various operating system-dependent functionalities like running system commands, reading or writing to files, creating directories, etc.</li></ul><pre>#!/usr/bin/env python3.7<br><br>import os</pre><ul><li>Line 5 — assigns the current working directory path to a variable called <em>“directory” (</em>This is what I named mine, feel free to name it whatever you’d like, just make sure the name would be consistent throughout the script).</li></ul><pre>directory = os.getcwd()</pre><ul><li>Line 9 — creates an empty list named <em>“files_list”</em> to store our file information.</li></ul><pre>files_list = []</pre><ul><li>Line 12→22— loops through each file in our specified directory, gets its file size, and last modified time then creates dictionaries with the results.</li></ul><pre>for file_name in os.listdir(directory):<br>    file_path = os.path.join(directory, file_name)<br>    file_size = os.path.getsize(file_path)<br>    last_modified = os.path.getmtime(file_path)<br>    <br>    file_info = {<br>        &quot;File name&quot;: file_name,<br>        &quot;Path&quot;: file_path,<br>        &quot;File size&quot;: file_size,<br>        &quot;Last Modified&quot;: last_modified<br>    }</pre><ul><li>Line 25 — adds the dictionaries under<em> “file_info”</em> to our list named <em>“files_list”</em> (from Line 9)</li></ul><pre>    files_list.append(file_info)</pre><ul><li>Line 28 — prints the contents of our list <em>“files_list”</em> onto separate lines.</li></ul><pre>print(*files_list, sep=&quot;\n&quot;)</pre><p>And there we have it, a Python script that generates a list of dictionaries for files in our working directory.</p><p>Thank you so much for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6301b3bb514" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS 3-Tier Architecture]]></title>
            <link>https://medium.com/@mikaylapham/aws-3-tier-architecture-cd2ad8db5fa?source=rss-865021e8f9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd2ad8db5fa</guid>
            <dc:creator><![CDATA[Mikayla Pham]]></dc:creator>
            <pubDate>Mon, 13 Mar 2023 05:19:45 GMT</pubDate>
            <atom:updated>2023-03-13T05:19:45.306Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*kBoR8eR3eU2n8cUc15J_Rg.png" /></figure><p>In this article, we will be building a 3-Tier Architecture based on the following scenario.</p><h3><strong>OBJECTIVES:</strong></h3><p><strong>Scenario:</strong><br>You have been asked to design and create a highly available 3 Tier architecture for your company’s new web application.</p><p><strong>Web Tier</strong></p><ol><li>2 public subnets</li><li>Minimum of 2 EC2 instances with an OS of your choice (free tier) in an Auto Scaling Group.</li><li>EC2 Web Server Security Group allowing inbound permission from the internet.</li><li>Boot strap static web page or create a custom AMI that already includes the static web page.</li><li>Create a public route table and associate the 2 public subnets.</li></ol><p><strong>Application Tier</strong></p><ol><li>2 private subnets</li><li>Minimum of 2 EC2 instances with an OS of your choice (free tier) in an Auto Scaling Group.</li><li>EC2 Application Server Security Group allowing inbound permission from the Web Server Security Group.</li><li>Associate with private route table.<br>Note: This is not a true application tier as we don’t have any provided code to run on the EC2 instances.</li></ol><p><strong>Database Tier</strong></p><ol><li>Use a free Tier MySql RDS Database.</li><li>The Database Security Group should allow inbound traffic for MySQL from the Application Server Security Group.</li><li>2 private subnets.</li><li>Associate with a private route table.<br>Note: No need to use Multi-AZ but be sure to document how you would add it</li><li>Remember that when diagraming this tier you are only creating one RDS instance in one subnet even though you are creating two subnets. If you use multi-az or a read replica then and only then should you have a second instance. Make sure to label accordingly.</li></ol><h3><strong>Creating a VPC and More!</strong></h3><p>First off, let’s start with creating a VPC.</p><ul><li>Choose <strong>“VPC and more”</strong> option as other than just creating a VPC, it lets us configure availability zones, private &amp; public subnets, and NAT Gateway.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*6TuNXfXL4AnZZF9qm9ZlbA.png" /></figure><ul><li>We’ll have (2) Availability Zones, (2) public subnets, and (4) private subnets.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*Bt30ZpXZeSgiPoCR5SweDQ.png" /></figure><ul><li>For <strong>“NAT Gateway”</strong>, select <strong>“1 per AZ” </strong>(There’s a charge associated with NAT Gateway); Select <strong>“None”</strong> for <strong>“VPC Endpoints”</strong>. Then proceed to “<strong>Create VPC”</strong>.</li></ul><p>It will take a couple of minutes for everything to spin up.</p><p>Next up, we need to <strong>Enable Auto-Assign Public IPv4 address</strong> for all of the subnets we just created.</p><ul><li>Under our “<strong>VPC Dashboard”</strong>, click on “<strong>Subnets”</strong>, then select the subnet we just created, and choose <strong>“Edit Subnet Settings”</strong> under <strong>“Actions”</strong> drop-down menu.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GMuyH5h3eyABckScxBcK4A.png" /></figure><ul><li>Tick the box for <strong>“Enable auto-assign public IPv4 address”.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*fbzMaQ4Ehckq5QRh2EaclA.png" /></figure><ul><li>Repeat this step for <strong>ALL</strong> of the (6) subnets (2 public subnets &amp; 4 private subnets) we created.</li></ul><h3><strong>WEB TIER</strong></h3><h3>Creating a Launch Template</h3><ul><li>Under <strong>EC2 Dashboard &gt; Launch Template</strong>, click on <strong>“Create Launch Template”</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UvfqHLFc9gzAN5pqEcmb4w.png" /></figure><ul><li>Name our <strong>Launch Template</strong>, then select our OS.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*ixL9OeorRg5AgXFMLYoR0g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*s6tOMyJk2IusJYx-7VCcKg.png" /></figure><ul><li>Select <strong>Instance Type</strong>, and assign a <strong>Key Pair</strong>. (I’ll be using my existing keypair)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*UtQsm8t9eKAlDfRpLt72ww.png" /></figure><ul><li>Under <strong>Network Settings</strong>, <strong>“Create Security Group”</strong> and choose our previously created <strong>VPC</strong> as shown below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*RS1VKZ3SD_1qEucv8_ohlQ.png" /></figure><ul><li>Select <strong>“Add Security Group Rule”,</strong> then add security group rule for <strong>SSH</strong> and <strong>HTTP</strong> as shown below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*ju4aGBPu054ksQF0RWmPRg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*5SsHpI4wLzmj8OwL9Z4WMA.png" /></figure><ul><li>Select <strong>“Add Network Interface”</strong>, and under<strong> “Auto-assign public IP” </strong>select <strong>“Enable”</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*0d6gOkRRgI4tbgtDJeiWFA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*42aPUx9g4pWoSUn920Ci2w.png" /></figure><ul><li>Under “<strong>Advanced Settings”</strong>, scroll down to “<strong>User Data”</strong>, we’ll be bootstrapping a bash script for our static web page.</li></ul><pre>#!/bin/bash<br>yum update -y<br>yum install -y httpd<br>systemctl enable httpd<br>systemctl start httpd<br>echo &quot;&lt;h1&gt; Hello Gold Team! &lt;/h1&gt;&quot; &gt; /var/www/html/index.html</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EKXyB4WDd37B4kPR2CyN9Q.png" /></figure><ul><li>Review all our selections then click on <strong>“Create Launch Template”</strong>.</li></ul><h3>Creating an Auto-Scaling Group</h3><ul><li>Navigate to <strong>EC2 Dashboard</strong>, choose <strong>Auto Scaling &gt; Auto Scaling Groups</strong>, then select <strong>“Create Auto Scaling Group”.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nl4gc_0x-8N2StxaaUNPmw.png" /></figure><ul><li>Name our <strong>Auto Scaling Group</strong>, then click on <strong>“Create a Launch Template”</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*AYeRuRzn8kUP8cZXbp4Fqw.png" /></figure><ul><li>Select our <strong>VPC</strong>, then select our (2) <strong>public subnets</strong>, then click <strong>Next</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*Za9xYajZMCEMSu19sA8pnw.png" /></figure><ul><li>Under <strong>Configure advanced options</strong>, “<strong>Attach a new load balancer”</strong> as shown below, then click <strong>Next</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*Mxu3aFOAxyEvhw5_JewJUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*xmfgaS30brB6LHHqhG3tDA.png" /></figure><ul><li>Next up, configure group size, I’ll set the minimum capacity to 2, and the maximum capacity to 5.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*lOgbI073Mqbi11KpaSn5iA.png" /></figure><ul><li>Review all our selections then click on <strong>“Create Auto Scaling Group”.</strong></li></ul><h3>Verify Web Tier web page is accessible from the internet</h3><ul><li>Navigate back to <strong>EC2 Dashboard</strong>, click on either of the (2) running instances and copy the <strong>Public IP</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BVtJ1T_wuN0wvRQ3dDYkbg.png" /></figure><ul><li>Paste the <strong>Public IP</strong> into a web browser.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*3JvKIbB6M3PYvDrtQCxS9g.png" /><figcaption>Ta-dah!</figcaption></figure><h3>APPLICATION TIER</h3><h3><strong>Creating a Launch Template for Private Subnet</strong></h3><ul><li>This process will be similar to Launching Template for Web Tier with some modifications.</li><li>Name our <strong>Template</strong>, and select OS.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*B4eWnuP0MaAGc8e8Dyh2Fg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*2IB0XbY_lNh3UhN1QQJWZA.png" /></figure><ul><li>Select <strong>Instance Type</strong>, and assign a <strong>Key Pair</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*titD5yLFMNE6fUX-OdIQAg.png" /></figure><ul><li>Next, this is where the difference lies, under <strong>“Network Settings”</strong>, create a new security group with the following permissions.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*sIrI_VrRFl4ajIpfQFVjbQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*FjMVICs_YQyJ08lbgEK8XQ.png" /></figure><h3>Creating an Auto-Scaling Group</h3><ul><li>Name our A<strong>uto Scaling Group</strong>, then select the corresponding <strong>Launch Template</strong> we just created.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*lVDnbjEnMEgLWfhxBWCnIA.png" /></figure><ul><li>Choose our <strong>VPC</strong>, then select our (2) <strong>private subnets</strong>, then click <strong>Next</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*74kPU66EMqufxL9X-UAw4w.png" /></figure><ul><li>Select <strong>“Attach to a new Load Balancer”.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*6YEsgbcFwVotf77ANzrv6g.png" /></figure><ul><li>And don’t forget to select our target group.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*LGTNDGAva4zOWrdrLwvpuw.png" /></figure><ul><li>Finish the rest of the configuration similar to how it was done in Web Tier.</li></ul><h3>DATABASE TIER</h3><h3>Create an RDS Subnet Group</h3><ul><li>Navigate to <strong>RDS Dashboard</strong>, Under <strong>“Subnet Groups”</strong>, Click on<strong> “Create DB subnet group”</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RKqdd5TdUIDMfoTXV-_KIA.png" /></figure><ul><li>Name our <strong>DB subnet group</strong>, and select our <strong>VPC</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*Y7S8-co39Oci7b0WCa1yzA.png" /></figure><ul><li>Select our <strong>Availability Zones</strong>, and the remaining (2) <strong>private subnets, </strong>then click <strong>“Create”</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*re8GSKVXqHI0VQXB4K8x-A.png" /></figure><h3>Create a MySQL RDS Database</h3><ul><li>Navigate back to <strong>RDS Dashboard</strong>, then click on <strong>“Create Database”</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mpB1EzNG16vqLcEOvv0LNQ.png" /></figure><ul><li>Select <strong>MySQL</strong> per Objectives.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*NYRArbi7ocDHDARy_VUmHQ.png" /></figure><ul><li>Under <strong>Template</strong>, select <strong>“Free Tier”.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*cZwvUeZ-094eo_7mAaQ3Pg.png" /></figure><ul><li>Next up, under <strong>“Settings”</strong>, name our <strong>Database</strong> and input a <strong>Master password</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*6t7IJTQqbNtzSykvjoGhFQ.png" /></figure><ul><li>Under <strong>“Connectivity”</strong>, select our <strong>VPC</strong> and the previously created <strong>DB subnet</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*SeEjwLCT8REj1CRFs3cA-A.png" /></figure><ul><li>Next up, create a new <strong>VPC security group</strong> for this DB as shown below. Ensure <strong>Database Port</strong> is <strong>3306.</strong> Then click <strong>“Create Database”.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*n-A1X1pegHd1jU-kqfqDYQ.png" /></figure><ul><li>It will take a moment to be created.</li><li>Once done, click on our DB we just created, under <strong>“Connectivity &amp; Security”</strong>, and click on <strong>“VPC security groups”.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4gjCuDsRHhPQGT8sNFW20Q.png" /></figure><ul><li>Under the <strong>“Actions”</strong> drop-down menu, select <strong>“Edit Inbound Rules”</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CNhwupkzcoNoRm-B2RJNUw.png" /></figure><ul><li>Delete the existing <strong>Inbound Rule</strong>, then click “<strong>Add Rule</strong>”, with the source to be the Security Group we created for DB.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X4vEcxwffb4S56TcsmQYAA.png" /></figure><h3>Ping Application Tier from Web Tier</h3><ul><li><strong>SSH</strong> into (1) of our previously created public EC2 Instances.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*F7WIlXq7NIb__TIC8xlUuw.png" /></figure><ul><li>Run a <strong>“Ping”</strong> command followed by the private IP address of (1) of the private EC2 Instances</li></ul><pre>ping &lt;Private-IP-Address&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nm7HQtgRn2IRI-A3-DGs8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*quyLlaeucC3bScFb1OgCgw.png" /></figure><ul><li>The Ping was successful! And our <strong>Objectives</strong> are done!</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd2ad8db5fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a DynamoDB table with read-only access for EC2 instance]]></title>
            <link>https://medium.com/@mikaylapham/deploying-a-dynamodb-table-with-read-only-access-for-ec2-instance-36d7183ec415?source=rss-865021e8f9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/36d7183ec415</guid>
            <dc:creator><![CDATA[Mikayla Pham]]></dc:creator>
            <pubDate>Sun, 05 Mar 2023 09:21:22 GMT</pubDate>
            <atom:updated>2023-03-05T09:21:22.794Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rtbiJnn9pMGJ4YVzHFOl6w.png" /></figure><p>In this post, we’ll be creating a DynamoDB table with a read-only access role and testing it with an EC2 instance.</p><h3>Objectives:</h3><ol><li>Create a DynamoDB table for something of your choosing (e.g. movies, food, games)</li><li>Add 10 or more items to the table</li><li>Create a t.2micro Ec2 instance</li><li>Using an IAM role and the principle of least privilege, grant the EC2 instance read access to DynamoDB.</li><li>Use the AWS CLI in the EC2 instance to scan the DynamoDB table</li><li>Use the AWS CLI in the EC2 instance to validate you cannot write an item to the DynamoDB table</li></ol><h3>Step 1: Creating a DynamoDB table.</h3><ul><li>In our <strong>AWS Console</strong>, navigate to <strong>DynamoDB</strong> dashboard, then click on <strong>“Create Table”</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u9cbBqcdHckRMS3IXuV5Jw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Npvn0d8N0iotWBdctHxOA.png" /></figure><ul><li>Give our table a name (it mustn’t have any space). I’ll be creating a table regarding some of the iconic landmarks around the world.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*9-EhZX-RoUGPyTnGepSMAg.png" /></figure><ul><li>Everything else can be on default settings, click on <strong>“Create Table”</strong> to finish.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*n9QcVzOIh_ZrBz21Na4GSg.png" /></figure><h3>Step 2: Adding items to your table.</h3><ul><li>Next, let’s add “items” to our table. With the table selected, click on <strong>Action</strong> &gt; <strong>Explore Items</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qmTHbkKqfKyFFT-sd_N0Gg.png" /></figure><ul><li>Click on “<strong>Create Item</strong>”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agDSMudQL0GMUvlyYt_7Dw.png" /></figure><ul><li>Fill in the corresponding information. Click on <strong>Add New Attribute &gt; String</strong> to add other attributes as necessary, then finish by clicking on <strong>“Create Item”</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zJogkcBxmOdFz4aBkNdqZQ.png" /></figure><ul><li>Repeat the previous step(s) to create as many items as needed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hqXTlNvxDcPrhDqyyGt_xg.png" /></figure><h3><strong>Step 3: Create a t.2micro Ec2 instance with read access to </strong>DynamoDB<strong>.</strong></h3><ul><li>Navigate to <strong>IAM</strong> dashboard, and under the <strong>Roles</strong> tab, click on <strong>“Create Role”</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*saExBou-9ta7vYwD4LIRSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3PThwtZXJ7WorOijXvzt8A.png" /></figure><ul><li>Select <strong>EC2</strong> as we’ll use this permission for our <strong>EC2 instance</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QLPbGpi2YMnGib72wHcJOw.png" /></figure><ul><li>Next up, we can add permission policies by either creating our own policy or using the given premade policies. In this case, I’ll use the premade one since it has exactly what was asked for in the <strong>Objectives </strong>— read-only access for Amazon DynamoDB.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tDf2-7RLy8bnbw4wBAjrOA.png" /></figure><ul><li>Name our role (no space and/or capital letters).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNmKWtwDnS4C1KtfPW2-PA.png" /></figure><ul><li>Next, navigate to <strong>EC2 dashboard</strong> to launch a new instance. I’m using the default VPC and security group, with my previously created key pair.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*BWMfvHEXL1DcN3ikAmUU1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*efqIHfWOgj_pLVygwEFNqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dVCs6XMb-RPM53TFmUTXzA.png" /></figure><ul><li>Once the instance is up and running, under the <strong>“Action”</strong> drop-down menu, select <strong>Security</strong> &gt; <strong>Modify IAM Role</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*4a2lBcaaYNKbEhfC8fNBYA.png" /></figure><ul><li>Select the role we created then click on “<strong>Update IAM role</strong>”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*rMSZ0tAv3mx8QfF_TMFFeA.png" /></figure><h3>Step 4: Scan the DynamoDB table.</h3><ul><li>Next, SSH into the EC2 instance we just created. (DON’T forget to change directory to where our keypair was saved)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*MVrnQvqOuytHNHAYQgfyMg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*n-nsVV9Y8647Uvm2yA1CAg.png" /></figure><ul><li>Use the command below to scan the DynamoDB table. In my case, my TableName will be “Iconic_Landmarks” and the region will be “us-east-1”</li></ul><pre>aws dynamodb scan --table-name &#39;InputTableName&#39; --region &#39;InputRegion&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*G1PlO0j1I9ccCTZfwKsLag.png" /></figure><h3><strong>Step 5: Validating Read-Only access.</strong></h3><ul><li>To validate read-only access, we’ll be trying to add an item to our DynamoDB table with the following command:</li></ul><pre>aws dynamodb put-item --table-name &#39;InputYourTable&#39; --region &#39;InputYourRegion&#39; --item &#39;{&quot;YourPartitionKey&quot;: {&quot;S&quot;: &quot;PartitionItem&quot;},&quot;SortedKey&quot;: {&quot;S&quot;: &quot;SortedKeyItem&quot;}}&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sy7lWpgDgHhgQ7weu24bqA.png" /></figure><ul><li>An error occurred showing access denied — this means that we don’t have permission to write an item to this DynamoDB table.</li></ul><p><strong>And our Objectives are completed! Thanks for reading!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36d7183ec415" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Auto-Scaling Group of EC2 Instances for High Availability]]></title>
            <link>https://medium.com/@mikaylapham/creating-auto-scaling-group-of-ec2-instances-for-high-availability-946261550c88?source=rss-865021e8f9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/946261550c88</guid>
            <dc:creator><![CDATA[Mikayla Pham]]></dc:creator>
            <pubDate>Sun, 26 Feb 2023 23:16:45 GMT</pubDate>
            <atom:updated>2023-02-26T23:24:22.050Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*y0mzhAwrq5N71Df7vrnv5A.png" /></figure><p>In this article, we will explore how to create an Auto-Scaling Group of EC2 Instances for high availability based on the following objectives.</p><h3><strong>Objectives:</strong></h3><ol><li>Create a VPC with CIDR 10.10.0.0/16</li><li>Create three public subnets with 10.10.1.0/24 &amp; 10.10.2.0/24 &amp; 10.10.3.0/24</li><li>Create 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. Ensure the autoscaling group is using the public subnets from #2.</li><li>The autoscaling min and max should be 2 and 5.</li><li>Create an Application Load Balancer to distribute traffic to the autoscaling group.</li><li>Create web server security group that allows inbound traffic from HTTP from your Application Load Balancer.</li><li>Create a load balancer security group that allows inbound traffic from HTTP from 0.0.0.0/0.</li></ol><h3>Step 1: Create a VPC with CIDR 10.10.0.0/16</h3><ul><li>Head over to your <strong>VPC Dashboard</strong> on <strong>AWS Console</strong> and starts by creating a <strong>VPC</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*Jp_KflLnvS8RJuH_BpSNLA.png" /></figure><ul><li>Name your <strong>VPC </strong>as you please, then make sure to set your <strong>IPv4 CIDR Block</strong> to<strong> 10.10.0.0/16</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*eZmeFO50iLARgkUHkJxI5w.png" /></figure><ul><li>Next up is choosing <strong>Availability Zones</strong> - Select (3) availability zones (This means that traffic will be directed to the remaining availability zone(s) if one goes down)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*3DXU5N7R1frcQUcxqH4hTA.png" /></figure><h3>Step 2: Create three public subnets</h3><ul><li>Next, Create (3) <strong>Public Subnets</strong>. As <strong>Private Subnets</strong> aren’t part of the <strong>Objectives</strong>, select (0) <strong>Private Subnets</strong>.</li><li>Change <strong>CIDR blocks</strong> for <strong>Public Subnets</strong> as follow:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*pm-Tat1nGj7zBUxj6Y0_pg.png" /></figure><ul><li><strong>NAT Gateway</strong> is not necessary since our subnets are public. However, if you choose to create one, be aware of the cost associated with it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*K9_d-Yc55jrGkvsKkI6sIA.png" /></figure><ul><li>Click <strong>Create VPC</strong>.</li><li>Next, head over to the <strong>Subnets</strong> tab under <strong>VPC Dashboard</strong> to enable auto-assign IPv4 addresses for your subnets. Do so by selecting each subnet, under the <strong>Actions</strong> drop-down menu, selecting “<strong>Edit Subnet Settings</strong>” and ticking the box for <strong>“Enable auto-assign public IPv4 address”.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*iWeTBWDZCPXZJCFEqj6Eyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*OHSPj74OAU8ImXd8lWpW5w.png" /></figure><ul><li>Repeat the previous step for the other (2) public subsets we just created.</li></ul><h3>Step 3: Create a Launch Template</h3><ul><li>Navigate to <strong>Launch Templates</strong> on your <strong>EC2 Dashboard</strong>. Then go ahead and click on “<strong>Create Launch Template</strong>”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*oKWq3EMOfCLNpVvgzCiyUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7QuNO-eHMdEj2WCPVegBCQ.png" /></figure><ul><li>Name your template then tick the box for “<strong>Auto Scaling Guidance</strong>”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*b2det0tFk0rbYwKhRRsnTQ.png" /></figure><ul><li>Next, Select your OS under <strong>Application and OS Images (AMI)</strong>, I choose Amazon Linux, free tier.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*UIy4o88Ifz7_2z64acvn3w.png" /></figure><ul><li>Under <strong>Instance Types</strong>, select <strong>t2.micro </strong>as mentioned in <strong>Objectives.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*JWXCoJ4L55ziYZMHoMFI8g.png" /></figure><ul><li>Under Network Settings, choose <strong>“Create Security Group”</strong> then name and provide a description for it as required. Make sure to select the <strong>VPC</strong> we just created not long ago.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*qLUSS3PK9TawmFy-KsxDYg.png" /></figure><ul><li>Under<strong> “Inbound Security Group Rules”</strong>, select <strong>“Add Security Groups Rules”,</strong> then set up security group rules for <strong>SSH</strong> and <strong>HTTP</strong> as shown below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*64QfUpkFkS5Eub03JUFPZg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*7lKD4s9brf_2G9axXgb08g.png" /></figure><ul><li>Under “<strong>Advanced Network Configuration</strong>”, select <strong>“Add Network Interface”.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*np1gj-Z6MyBsNenq-QfrlA.png" /></figure><ul><li>Select <strong>“Enable”</strong> for “<strong>Auto-assign public IP”. </strong>Everything else can be left on default settings.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*zMocQZnKzFK2DTI7sOiYiA.png" /></figure><ul><li>Input bash script to install <strong>Apache</strong> web server under the “<strong>User Data” </strong>section in “<strong>Advanced Details”</strong>. The following bash script will install the <strong>Apache</strong> web server, then use the instance metadata service to find the name of the availability zone in which the instance is launched and add that to your <strong>index.html</strong></li></ul><pre>#!/bin/bash<br>yum update -y<br>yum install -y httpd<br>systemctl start httpd<br>systemctl enable httpd<br>EC2AZ=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone) <br>echo &#39;&lt;center&gt;&lt;h1&gt;This Amazon EC2 instance is located in Availability Zone: AZID &lt;/h1&gt;&lt;/center&gt;&#39; &gt; /var/www/html/index.txt<br>sed &quot;s/AZID/$EC2AZ/&quot; /var/www/html/index.txt &gt; /var/www/html/index.html</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*qcMq0cSOH1-b9pRg3FB-fw.png" /></figure><h3>Step 4: Create an Application Load Balancer</h3><ul><li>Navigate back to your EC2 Dashboard, under <strong>Load Balancing &gt; Load Balancers</strong>, click on <strong>“Create Load Balancer”.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8-226EJpPZCAnQ5Lxa9ohQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*qhFzJYxqkIV8MyCD21DWWA.png" /></figure><ul><li>Under “<strong>Basic Configuration</strong>”, input your <strong>Load Balancer Name</strong> then select <strong>“Internet-facing”</strong> scheme and <strong>IPv4</strong> address type.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*X_oLaHhx0IYzlydEX7jp_Q.png" /></figure><ul><li>Under <strong>“Network Mapping”</strong>, select the <strong>VPC</strong> we created earlier. Then under <strong>“Mappings”</strong>, make sure to tick all “3” boxes of availability zones.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*IieLG9GLcogMqG5VS5BxOQ.png" /></figure><ul><li>Under <strong>“Security Groups”</strong>, find and select the security group we created in the drop-down menu.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*E3kIpPCdEC2y6JqGgHUMxQ.png" /></figure><ul><li>Under “<strong>Listeners and Routing”,</strong> select <strong>“Create Target Group”.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jd-155bpD0VsPCitfqvv2Q.png" /></figure><ul><li>You will be navigated to a new window, choose <strong>“Instances</strong>” as the target group type.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*xDq8-zJs4o-xokKpBWu3yQ.png" /></figure><ul><li>Name your target group then choose our previously created <strong>VPC. </strong>Everything else can be left on Default settings, click <strong>“Next”</strong> then proceed with <strong>“Create Target group”</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*Ha4zXOdKpuLgtidhhL54_Q.png" /></figure><ul><li>Back to <strong>Load Balancer</strong>, click <strong>“Refresh”</strong> then choose the <strong>Target Group</strong> we just created.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zWQVKJ6YFxThX5VrwqgN2g.png" /></figure><ul><li>Then scroll down to the bottom of the page to finish this step up by clicking on <strong>“Create Load Balancer”</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QmVNK1K1bbUR8j4x4cMw5A.png" /><figcaption>Load Balancer successfully created!</figcaption></figure><h3>Step 5: Create an Auto-Scaling Group</h3><ul><li>In EC2 Dashboard, under <strong>Auto Scaling &gt; Auto Scaling Groups,</strong> click on<strong> “Create Auto Scaling Group”</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kkbYegDca4hgoL8LxavSqQ.png" /></figure><ul><li>Name your <strong>Auto Scaling Group</strong>, then under<strong> “Launch Template”</strong>, select the one we just created, then click <strong>Next.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*AilUtjN_KjftxQOSc9Pptw.png" /></figure><ul><li>Next up, under <strong>“Network”</strong>, choose your <strong>VPC </strong>then select all (3) of our <strong>Availability zones and subnets</strong>, then click <strong>Next.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*CE6JUhnEtd3Pn0e3P-BgwA.png" /></figure><ul><li>Under <strong>“Configure Advanced Options”</strong>, choose <strong>“Attach to an Existing Load Balancer”</strong>. Then in the drop-down menu, select the <strong>Application Load Balancer</strong> we just created in the previous step, then click <strong>Next.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*xl2BaoBWUB2fKQTkFQzoQw.png" /></figure><ul><li>Under “<strong>Group size</strong>”, input the capacities as shown below (This satisfies <strong>Objective#4</strong>) then click <strong>Next</strong> to finish up.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*KpbOmhJ8JD0HaAd6q4vgGA.png" /></figure><ul><li>Give it about a minute then navigate back to our <strong>EC2 Dashboard</strong>, you’ll see (2) <strong>EC2 Instances</strong> running. This is because previously we stated the <strong>Desired Capacity</strong> is (2).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L3XbdPB0eqtLkdiJK1DgOg.png" /></figure><h3>Last Step: Test your servers!</h3><ul><li>Copy the <strong>Public IP</strong> address(es) and paste them into your web browser to ensure everything is working correctly.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*5d7mioLj1IZAcA8_KO1LFA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tLm8WZzdRmxVSEVdKJoBRA.png" /><figcaption>Availability Zone: us-east-1a</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MansL4I0Lxm-joHK3HGtrA.png" /><figcaption>Availability Zone: us-east-1b</figcaption></figure><h3><strong>YAY! WE DID IT!</strong></h3><p>Now don’t forget to tear down everything to avoid unnecessary charges!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=946261550c88" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Launching an EC2 instance with NGINX installed]]></title>
            <link>https://medium.com/@mikaylapham/launching-an-ec2-instance-with-nginx-installed-12b9bfbf07f?source=rss-865021e8f9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/12b9bfbf07f</guid>
            <dc:creator><![CDATA[Mikayla Pham]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 08:35:41 GMT</pubDate>
            <atom:updated>2023-02-19T08:35:41.459Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*VJaxnP488TJ6uW9M1Wg7_g.png" /></figure><h3>Introduction:</h3><p>From last week’s post, we learned that Amazon Elastic Compute Cloud (EC2) is a powerful tool that allows users to launch virtual machines (instances) in the cloud, and EC2 instances can be configured with various operating systems, applications, and services to suit different needs. In today’s post, we’ll explore how to launch an EC2 instance with NGINX web server installed.</p><h3>Objectives:</h3><ol><li>Create a t2.micro EC2 instance with the OS of your choice (Just make sure it is free tier).</li><li>In the user-data field, use a script that updates all packages, installs NGINX, and starts the service.</li><li>Verify that the instance has the NGINX webserver downloaded and installed through the public IP.</li></ol><p><strong>Prerequisites:</strong></p><ol><li>A Command-Line Interface (CLI).</li><li>AWS account. (Sign-up for one through this <a href="https://portal.aws.amazon.com/billing/signup#/start/email">link</a>)</li></ol><h3><strong>Step 1: Creating EC2 instance with OS of choice</strong></h3><p>We will start by logging into the <strong>AWS Management Console</strong> and navigating to the <strong>EC2</strong> dashboard (refer to <a href="https://medium.com/@mikaylapham/how-to-launch-aws-ec2-instance-to-install-apache-5f2c7fbf26c3">my previous post</a> for detailed instructions on this). From there, we’ll launch an EC2 instance following the steps below:</p><ul><li>Input your <strong>Instance Name</strong></li><li>Select <strong>Instance Type</strong> (in this case, it’ll be <strong>t2.micro</strong> as mentioned in <strong>Objectives</strong>)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*ut_hK4TtR_j2XS6I9bGb8A.png" /></figure><ul><li>Select a <strong>Key Pair</strong> or <strong>Create New Key Pair</strong> (refer to <a href="https://medium.com/@mikaylapham/how-to-launch-aws-ec2-instance-to-install-apache-5f2c7fbf26c3">my previous post</a> for detailed instructions on how to create a new <strong>Key Pair</strong>). I’ll be using my existing Key Pair for this step.</li><li>Modify <strong>Network Settings</strong> — Tick the boxes to allow <strong>SSH traffic</strong> and <strong>HTTP traffic</strong> from the internet.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*PWFeiENp5Mk53u5nRPLdpA.png" /></figure><h3>Step 2: Installing NGINX</h3><ul><li>In the <strong>Advanced Details</strong> section, scroll down to <strong>User Data </strong>(This is the code that runs when the instance starts for the first time) and input the script below:</li></ul><pre>#!/bin/bash<br><br>sudo yum update -y<br>sudo amazon-linux-extras install nginx1 -y<br>sudo systemctl enable nginx<br>sudo systemctl start nginx<br></pre><ul><li>Once done, it’s time to Launch the instance!</li></ul><h3>Step 3: Verify that the instance has NGINX web server installed</h3><ul><li>With your instance selected, find and copy your <strong>Public IP</strong> address.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xqn7eKGLr0bNwpJ1njbd2Q.png" /></figure><ul><li>Paste your <strong>IP address</strong> to a web browser. If you see the screen below, Congratulations! You have successfully launched an EC2 instance with NGINX installed without even connecting to it!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W3G8mZ8UwnWB7JcwIRomwA.png" /></figure><p>P/S: Don’t forget to stop your instance once you’re done!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12b9bfbf07f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Launch AWS EC2 Instance to Install Apache using Bash script]]></title>
            <link>https://medium.com/@mikaylapham/how-to-launch-aws-ec2-instance-to-install-apache-5f2c7fbf26c3?source=rss-865021e8f9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f2c7fbf26c3</guid>
            <dc:creator><![CDATA[Mikayla Pham]]></dc:creator>
            <pubDate>Mon, 13 Feb 2023 00:01:17 GMT</pubDate>
            <atom:updated>2023-02-17T21:17:18.632Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*w4bNJnfroejxXxYJ3gsyCw.png" /></figure><h3>Introduction:</h3><p>Amazon Elastic Compute Cloud (EC2) is a powerful and flexible service that allows you to launch virtual servers in the cloud. One common use case for EC2 is to host web applications in which you’ll need to install a web server like Apache on your EC2 instance. In this post, we’ll go through the steps to launch an EC2 instance and install Apache, so you can get your web application up and running in no time.</p><h3>Objectives:</h3><ol><li>Launch an EC2 Amazon Linux t2.micro (free tier) in a public subnet of your <strong>Default VPC</strong>. (You should NOT be creating a custom VPC for this project)</li><li>Create a security group that allows inbound traffic on HTTP for 0.0.0.0/0 and allows inbound traffic on SSH from your IP address.</li><li>SSH into your EC2 instance and install Apache with a custom webpage using a BASH script.</li></ol><p><strong>Prerequisites:</strong></p><ol><li>A Command-Line Interface (CLI).</li><li>AWS account. (You can simply sign-up for one through this <a href="https://portal.aws.amazon.com/billing/signup#/start/email">link</a>)</li></ol><h3>Launch an EC2 Amazon Linux t2.micro:</h3><ul><li>After logging in to your <strong>AWS</strong> account, you can easily navigate to <strong>EC2 Dashboard</strong> by searching “<strong>EC2</strong>” in the search bar at the top. I’d recommend adding it to your Favorites for easy future access by clicking on the ⭐ icon as shown below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M3tNZRh6nPdy2v8im9rbcg.png" /><figcaption>Add EC2 to your Favorites</figcaption></figure><ul><li>Next, to create your instance, click on the orange box that says <strong>“Launch instance”</strong> and select “<strong>Launch instance</strong>” from the drop-down menu.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*tlUldSGQIhHAZRJUljnOtA.png" /></figure><ul><li>Name your instance as you’d like and choose an OS. In this project, I’ll choose Amazon Linux for my OS.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*v9QLq3itNl4LW7QhYRhzZg.png" /></figure><ul><li>Make sure to choose <strong>“t2 micro”</strong> for your instance type as it was mentioned in the <strong>Objectives</strong> above.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*5x3DS4U0OVFAnmT0zpoeXw.png" /></figure><ul><li>Next up, you’ll need to make a key pair for your instance. Creating a key pair is essential when launching an EC2 instance because it allows you to securely connect to your instance via SSH.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*njTgodbHV0OTUpiAr7XPRg.png" /><figcaption>Select “Create new key pair”</figcaption></figure><ul><li>Name your key pair, then choose its format and type. Afterward, click on <strong>“Create key pair”</strong> to save it to your local machine.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*mydvzVxRDLKIGbBdKhNZZw.png" /><figcaption>Create key pair</figcaption></figure><ul><li>And don’t forget to make sure the right key pair is selected!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*gOIKjvQh7PVtOFTeq4W7IA.png" /><figcaption>Don’t forget to double-check that your key pair was selected!</figcaption></figure><ul><li>Next up is to choose your <strong>Network</strong> option. Make sure to tick all 3 boxes below to allow traffic from the internet to your website. Everything else can be left on default settings.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*xSXA0qSY-LuTBXSZCtILyw.png" /></figure><ul><li>Click on <strong>“Launch Instance”</strong> to launch your EC2 instance.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*se27vXPD0W0OnUCRvGenIA.png" /></figure><ul><li>This takes a few seconds, but once you see the message stating your instance was successfully launched, then you’re ready for the next steps!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*IyYdmaWqL0STFF2F3dgoNQ.png" /></figure><h3>SSH into your EC2 instance and install Apache:</h3><ul><li>Your instance will be in <strong>“Pending”</strong> state for a few minutes after launching before changing to <strong>“Running”</strong>. Refresh your page as necessary then click on <strong>“Connect”</strong> to start the process of SSH into this instance.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RI0_9ZuuLPbG0FUYLkCdVQ.png" /></figure><ul><li>We will be connecting to this instance via <strong>SSH</strong>. Make sure you’re on the <strong>“SSH client”</strong> tab and get your <strong>CLI</strong> ready.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*l7BjRkHNSp9fYT0klJ4ZKQ.png" /></figure><ul><li>On your <strong>CLI</strong> (as a Windows user, I’ll be using PowerShell), <strong>Change Directory</strong> into the folder you had saved your <strong>Key pair</strong> previously. In my case, I saved it into \<strong>Downloads\LUIT</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*FsC-RhStpRRDRPsBqTMZrA.png" /></figure><ul><li>Next, we’ll <strong>SSH</strong> into our <strong>EC2 instance</strong>. Click on the icon shown below to copy the command into your clipboard, then paste it onto your CLI.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*ORuHD7QY6OjZe8DsXoLsAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E189thlBHFQD-mWLhRBclQ.png" /></figure><ul><li>There are updates available per the screenshot above, but we’ll be creating a bash script that will cover updating this so let’s move on.</li><li>Create your bash script with the command below:</li></ul><pre>vim &lt;InsertFileName&gt;.sh</pre><ul><li>In your VIM editor, input the following script, then save it with the shortcut <em>:wq! </em>(Change the content of your message as you please by editing the message between &lt;h1&gt; &amp; &lt;/h1&gt;)</li></ul><pre>#!/bin/bash<br>sudo yum update -y<br>sudo yum install -y httpd<br>sudo systemctl enable httpd<br>sudo systemctl start httpd<br>echo &quot;&lt;h1&gt; Hello Gold Team! &lt;/h1&gt;&quot; &gt; /var/www/html/index.html<br>sudo systemctl restart httpd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*qxG6Oya7Nedvuxc0Xh8clQ.png" /><figcaption>Input your message, then save with “:wq!”</figcaption></figure><ul><li>Check your permission with the command:</li></ul><pre>ls -l</pre><ul><li>If there’s no “x” (executable permissions), use the following command to modify:</li></ul><pre>chmod +x &lt;InsertFileName&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*tCfpE2_PnKeKJOLJ-pww3A.png" /><figcaption>Executable permission ADDED!</figcaption></figure><ul><li>Now, let’s run the file!</li></ul><pre>sudo ./&lt;InsertFileName&gt;</pre><ul><li>Next up, find and copy your Public IP address on the “<strong>EC2 Instance Connect</strong>” tab.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*Hbf9ZtRg4JZtlSv22-PHqg.png" /></figure><ul><li>Paste your IP address to a web browser.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*hHDzDHmZElpdpma-3fIEjA.png" /></figure><p>If you see a similar screen. Congratulation!! You just finished installing Apache webpage with a custom Bash script!</p><p><strong>P/S: THIS IS IMPORTANT! STOP YOUR EC2 INSTANCE BEFORE YOU GET CHARGED!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UWQwso3Lh5JXAwYPLswslg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f2c7fbf26c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>