<?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 Jacob Rivera on Medium]]></title>
        <description><![CDATA[Stories by Jacob Rivera on Medium]]></description>
        <link>https://medium.com/@jjrivera142?source=rss-504cba90c997------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6xithw_PI4wl2KQVNrAdTw.jpeg</url>
            <title>Stories by Jacob Rivera on Medium</title>
            <link>https://medium.com/@jjrivera142?source=rss-504cba90c997------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 09:49:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jjrivera142/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[Proof of Concept application powered by Docker and AWS Elastic Container Service]]></title>
            <link>https://medium.com/@jjrivera142/proof-of-concept-application-powered-by-docker-and-aws-elastic-container-service-419da6d8e6ed?source=rss-504cba90c997------2</link>
            <guid isPermaLink="false">https://medium.com/p/419da6d8e6ed</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[gunicorn]]></category>
            <category><![CDATA[elastic-container-service]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Jacob Rivera]]></dc:creator>
            <pubDate>Tue, 11 Jun 2024 20:55:50 GMT</pubDate>
            <atom:updated>2024-06-11T20:55:50.440Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rDyn8QImjPEwufyJFGEyFQ.png" /></figure><p>Continuing with the evolution of my SaaS application ‘HumanGov’, I’ve been tasked with migrating the application from Virtual Machines (VMs) to containers and deploying it to an Amason Web Services (AWS) Cloud environment.</p><p>Much easier said than done. We must write Dockerfiles to create images for our Nginx and Gunicorn servers, create Elastic Container Registry (ECR) repositories and push the images up, provision bucket storage and the database using Terraform, spin up a serverless Elastic Container Service (ECS) cluster, create a new IAM role for ECS Task Execution and Task Definition, and finally deploy the application. All in a day&#39;s work for a cloud engineer.</p><p>We’ll move along this project the same way we eat an elephant. One bite at a time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jbSN8VxMcdAgKoDfi9K8eQ.png" /></figure><p>It all starts with creating a new IAM role that will be used later to grant the Amazon ECS container and Fargate agents permission to make AWS API calls on our behalf. Referencing our previous architecture hosted on VMs, this new IAM role will need S3 full access, DynamoDB full access, and ECS task execution role policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vMt0hs4NWApZ09o5Sw8TFA.png" /><figcaption>creating new IAM role</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cjBcv4-elfSLncc63cYexA.png" /><figcaption>new IAM role permissions</figcaption></figure><p>Next up is creating the Dockerfiles for both Nginx and Gunicorn servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lz_MAC8WmwOfnz29RXWLqQ.png" /><figcaption>Gunicorn server image Dockerfile</figcaption></figure><p>A central piece of the above Dockerfile is the requirements.txt file containing a list of packages and dependencies, seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ACyFgt0-EiwtlGv4fL4AyA.png" /><figcaption>requirements.txt</figcaption></figure><p>Following the Dockerfile creation, I spun up a repository for the Gunicorn server on the AWS Elastic Container Registry. This took no more effort than to name the repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uKXKV_UaEe_jixT1SdntGg.png" /><figcaption>Gunicorn server repository</figcaption></figure><p>However, notice the “view push commands” link. This will give us a list of commands to build an image from our Dockerfile and push it to the respective repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EAGDLKA4g-iusikPXVjKGA.png" /><figcaption>commands to create the image and push to the repository</figcaption></figure><p>The push commands are tailored to the name of your repository. Step by step running the commands will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cbJjPIOOWzqZ0u1LaJGvBQ.png" /><figcaption>“Retrieve an authentication token and authenticate your Docker client to your registry”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9L29ejbqcxDKRlknBuJQIA.png" /><figcaption>“Build your Docker image”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XwgyGKdHSA24vofZwbAQ3A.png" /><figcaption>“push this image to your newly created AWS repository”</figcaption></figure><p>And when it’s all said and done, we should have a brand new image sitting in our likewise new repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ye7Z2CGGeB9lD_oUYbKBw.png" /><figcaption>Gunicorn server Docker image in our repository</figcaption></figure><p>The same will be done with our Nginx server with a few extra steps. The Nginx server is a proxy and will need 2 additional files- (additional to the Dockerfile) one for configuration-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sinV8Bas33ZXDPaaFEPifQ.png" /><figcaption>Custom Nginx configuration file</figcaption></figure><p>and another for parameters to forward information to the application that we’re proxying to (below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WOcv0FoE6fyk2NPmkOscNA.png" /><figcaption>proxy_params file</figcaption></figure><p>Now to write our Nginx Dockerfile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2NxbxoO58LpjBqbKxqZv9w.png" /><figcaption>Nginx Dockerfile</figcaption></figure><p>And push it to its repository</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rmwDdaCu65vTXWFq2aS1ng.png" /><figcaption>pushing Nginx image to its repository</figcaption></figure><p>With the application silo’s Terraform architecture already written, I’ll comment out resource blocks unrelated to what&#39;s needed (everything except S3 and DynamoDB), or in English, I’m telling my Terraform files to ignore everything outside of carefully placed asterisks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2tj8H2qCCwgtK8POCdeWFw.png" /><figcaption>Commenting out blocks in Terraform config files</figcaption></figure><p>Notice the asterisks at lines 64 and 95 and how everything above and below them is darkened out.</p><p>The same thing will be done with two separate outputs.tf files to ignore configurations that had to do with EC2. Since EC2 is a VM service and we need containers, we can do away with them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gxl_KJXsDMfVNd00BsjL4A.png" /><figcaption>Commenting out blocks in Terraform config files</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3ne4GolMtrNYNKFSgDo7sw.png" /><figcaption>Commenting out blocks in Terraform config files</figcaption></figure><p>So now after provisioning our new infrastructure with Terraform, we should only see an S3 bucket, DynamoDB, and a Random String for the bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tVR-PAqhX6DeN_RBFnNvOA.png" /><figcaption>Terraform provisioning output</figcaption></figure><p>Now that the heavy lifting is done, we’re left with creating an ECS cluster, Task Definitions, and Services to run the new containers. When creating the cluster, all that&#39;s taken into account is the name and infrastructure. We’ll be running AWS Fargate Serverless.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3yiGFV6p9LAMPKwNGXwoRw.png" /><figcaption>creating an ECS cluster</figcaption></figure><p>With only two steps left, we’ll manually configure the ECS cluster task definitions in the AWS GUI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*my2tqs7P4vyld6vUI_UPFw.png" /><figcaption>Configuring the task definition</figcaption></figure><p>The focus here is the launch type (AWS Fargate above), task role/execution role- remember our new IAM role from the beginning? And the container networking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TW3kiDYCvzWM2dJlLa9-YA.png" /><figcaption>Configuring the task definition</figcaption></figure><p>Container 1 will be our Gunicorn server. The Image URI was taken directly from its repository in ECR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ThkHgUKrNxg2YiwbwVkcZg.png" /><figcaption>Configuring the task definition</figcaption></figure><p>Our environment variables should look pretty familiar- almost like the text output after Terraform configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eMg3OWo-i4C-9O6IpzaZmw.png" /><figcaption>Configuring the task definition</figcaption></figure><p>Container 2 hosts our Nginx server. Above it looks like I forgot to add an application protocol. After seeing port 80 above, you should assume the protocol will be HTTP. With this, the task definition is finished and all that is left are the services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h7CrYST6rAi6169wOvfS-w.png" /><figcaption>Task definition successfully created</figcaption></figure><p>Let’s remember that we’re using Fargate and select it as our compute option during service creation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NjOzli-YFrZLORLB5mYfYw.png" /><figcaption>ECS service creation</figcaption></figure><p>Below you’ll notice “Desired tasks: 2”-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NQkzhfSQNpM43Ksu14nIEA.png" /><figcaption>ECS service creation</figcaption></figure><p>A task role allows your application code on the container to use other AWS services and is required when your application accesses other AWS services, such as Amazon S3; and an ECS Task consumes resources to run containers based on the configuration in a task definition.</p><p>With our Nginx server acting as our proxy, we’ll want to make sure to spin up a load balancer for it and put the listener on the proper port (HTTP)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g-h-FcGouZwRhJN8SUnN4Q.png" /><figcaption>ECS service creation</figcaption></figure><p>I was originally stuck on this part because my services kept failing to start the application. After shamelessly asking for help, I was pointed to the logs that told me I had a misconfigured DynamoDB.</p><p>After deleting and manually provisioning a new DB……. The services worked!!!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VO5WKWFUkobU1XHoVUcZQg.png" /><figcaption>ECS service running 2 tasks successfully</figcaption></figure><p>Let’s take a closer look at the task services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKk-7x3LlkGohTa7DNzCew.png" /><figcaption>ECS service running 2 tasks successfully</figcaption></figure><p>This part was so sweet to see after running into issues with the DB.</p><p>Now if we move to the Networking tab, we should be given a DNS link to our newly provisioned application. (below on the right)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pyty99vmDEV8_sXfIW_kLw.png" /></figure><p>I’ll click it and see what happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y3axE2JbGT3o1McrO6DkEg.png" /><figcaption>HumanGov SaaS application running in a container</figcaption></figure><p>Boom! We’ve successfully migrated our application from VMs to containers!</p><p>It wouldn’t seem real unless we tested it. I’ll click ‘add employee’ and input dummy info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OmMFPpl_6NC2yI2FDrL6uQ.png" /><figcaption>testing application by adding an employee</figcaption></figure><p>If the application is working correctly, we should get a hit in our S3 bucket with the new employee’s info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uxdsFHPFyNOvVeccdtWI9g.png" /><figcaption>Sample employee info in the S3 bucket</figcaption></figure><p>And there you have it folks. This was a fun project to wrap up learning Docker.</p><p>To summarize all; Using Terraform, I provisioned an AWS S3 Bucket and a DynamoDB table. Terraform’s Infrastructure as Code capability streamlined this process, allowing me to instantiate, modify, and version infrastructure safely and efficiently. With AWS S3 and DynamoDB ready, it was then onto the Elastic Container Service (ECS). After creating an ECS cluster, I formulated a Task Definition for our ECS deployment.</p><p>This definition detailed the containers, their roles, and necessary configurations from environment variables to port settings.</p><p>Finally, it was time for deployment. I set up a service on ECS, using Fargate as the launch type. The service seamlessly integrated our Docker containers, AWS configurations, and the necessary resources to ensure our application’s optimal performance. The results were a fully functional, scalable, and resilient cloud-based HumanGov application.</p><p>Overall, this project gave me an in-depth understanding of cloud deployment processes, from IAM roles, to Docker containerization, AWS ECR, Terraform provisioning, and AWS ECS service deployment. Each step was a lesson in best practices, troubleshooting, and the immense potential of cloud technologies.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=419da6d8e6ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deployment and Configuration of a SaaS Application on AWS Using Ansible, Terraform, and CodeCommit]]></title>
            <link>https://medium.com/@jjrivera142/deployment-and-configuration-of-a-saas-application-on-aws-using-ansible-terraform-and-codecommit-d6cf52c1dbd9?source=rss-504cba90c997------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6cf52c1dbd9</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[gunicorn]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[ansible]]></category>
            <dc:creator><![CDATA[Jacob Rivera]]></dc:creator>
            <pubDate>Wed, 15 May 2024 00:28:56 GMT</pubDate>
            <atom:updated>2024-05-15T17:30:20.243Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P92V6tmNopQvU4xZDWWvKg.jpeg" /></figure><p>This project focuses on the power of Ansible, an Infrastructure as Code(IaC) tool I will use to configure Nginx and Gunicorn servers running on RedHat EC2 instances in AWS. Files were sent to a local Git repository many times throughout the project as I am building upon a reusable Software as a Service(SaaS) application that is siloed. The silo infrastructure was built in my last project that focused on the power of <a href="https://medium.com/@jjrivera142/building-a-reusable-saas-multi-tenant-cloud-infrastructure-using-terraform-and-aws-code-commit-a8a7aaa148dd">Terraform</a>, another IaC tool that’s instrumental in the automation of the app.</p><p>This is by far the most complex project in my portfolio to date- so before we begin creating the Ansible Playbook, there are a few prerequisites to knock out. What is an Ansible Playbook you ask?</p><p><em>Ansible Playbooks are lists of tasks that automatically execute for your specified inventory or groups of hosts. One or more Ansible tasks can be combined to make a play — an ordered grouping of tasks mapped to specific hosts — and tasks are executed in the order in which they are written. — </em><a href="https://www.redhat.com/en/topics/automation/what-is-an-ansible-playbook#:~:text=Ansible%20Playbooks%20are%20lists%20of,in%20which%20they%20are%20written."><em>Redhat</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hq0mMmPL7XnwquEm9RR_5A.png" /></figure><p>I use an AWS Cloud9 EC2 instance as my go-to for managing projects. So, Step 1. Disable the AWS-managed temporary credentials on Cloud9.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GJDSbI2BI40jb3YUZeEvSw.png" /><figcaption>Disabling AWS-managed temporary credentials</figcaption></figure><p>Next is to configure Cloud9 to use an IAM user with full credentials. As I already had an IAM account and access key ready, it was time to hit the terminal and run:</p><p>aws configure</p><p>You’ll be asked for the Access and Secret keys, then for a default region. I left mine in us-east-1. You can finish by changing the output format but I skipped that. We’re done. Now Cloud9 has the privileges with the assumed IAM user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AQEIEeqS35nX7e7NjOsbTQ.png" /><figcaption>Configuring Cloud9 with new IAM user credentials</figcaption></figure><p>Step 2. Updating the silo’s Terraform files by first adding the IAM role code (line 64–109 below) to one of many main.tf files-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-iDbGSPNkeVuwpzsN7h5Qg.png" /><figcaption>Adding new IAM role to Terraform files</figcaption></figure><p>then updating the security groups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kMg1f68mNvDskdv3MT01aA.png" /><figcaption>Updating security groups in Terraform files</figcaption></figure><p>Real quick, let’s try and deploy this to see if everything works fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*31RTr44y0CZVp8W43kYalQ.png" /><figcaption>Testing AWS silo infrastructure code</figcaption></figure><p>Alright! Look at the ‘Outputs:’ in the lower screen and you’ll see this silo is for the state of California only and can be scaled to every US state with 9 resources per state.</p><p>Step 3. Commit the changes to a local git repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fs0FL5vdbSksn-syeeb-Aw.png" /><figcaption>Committing changes to Git repository CodeCommit</figcaption></figure><p>It’s important to leave notes with every push to a repository so others on your team can see what you’ve done/changed. I added a new IAM role to a Terraform module and made sure to jot that down above.</p><p>The next leg of this project is deploying the app without Ansible. <strong>Why would we do that? </strong>To show you what Ansible will do, the problem it is solving, and why it’s so popular.</p><p>First up, let’s create a new Git ignore file to make sure the repository will not consider zip files when uploading the source code, then download the application file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QT4rExIwZ6ihzRhFPUDz9g.png" /><figcaption>Downloading source code</figcaption></figure><p>Let’s unzip it and see what&#39;s inside.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d9NQg4tliFwEskujOGiwtg.png" /><figcaption>Application files</figcaption></figure><p>And now I’ll push it all to the repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sxfcr6hUfpSeAPeT8_1HOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W95ngJ7x9xXuQv-CXCxR3Q.png" /><figcaption>Pushing application files to the repository</figcaption></figure><p>This seems like a good time to install and manually configure the app. I’ll update some permissions and SSH into the EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*be-jdyBi6Go70GeTpvBYhA.png" /><figcaption>Accessing the EC2 instance via SSH</figcaption></figure><p>We’re in! Now it’s time to update and install Nginx amongst other things to create this server:</p><p>sudo apt-get update</p><p>sudo apt-get upgrade -y</p><p>sudo apt-get install -y nginx python3-pip python3-dev build-essential libssl-dev libffi-dev python3-setuptools python3-venv unzip</p><p>Next is ensuring Uncomplicated Firewall(UFW-minimizes the effort of setting up a firewall by starting with an optimal default configuration) allows Nginx HTTP traffic:</p><p>sudo ufw allow ‘Nginx HTTP’</p><p>Then create a project directory and create a Python virtual environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H17B2zQDnwfRstpTLq3eog.png" /><figcaption>Prompting UFW to allow Nginx HTTP traffic</figcaption></figure><p>Now that we’ve exited the web server, let&#39;s copy the application zip file to the destination and SSH back in:</p><p>scp -i /home/ec2-user/environment/humangov-ec2-key.pem humangov-app.zip ubuntu@172.31.46.60:/home/ubuntu/humangov</p><p>ssh -i /home/ec2-user/environment/humangov-ec2-key.pem ubuntu@172.31.46.60</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fpm5CIQa0yf9NDWgIMrAQA.png" /><figcaption>Copying app files to the EC2 instance and SSH’ing back in</figcaption></figure><p>And unzip the application file:</p><p>export project_path=/home/ubuntu/humangov</p><p>export username=ubuntu</p><p>export project_name=humangov</p><p>unzip $project_path/humangov-app.zip -d $project_path</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBEzESQKQv1urmfcZtDTQg.png" /><figcaption>Validating that the app files made it to the server</figcaption></figure><p>Then install Python packages from requirements.txt into the virtual environment:</p><p>$project_path/humangovenv/bin/pip install -r $project_path/requirements.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hPxPPW15w4_5EumG8yae0Q.png" /><figcaption>Installing app files</figcaption></figure><p>Said packages in a better list-read view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c4iX9jzGZY6CCQC57Ylj_w.png" /><figcaption>app files list</figcaption></figure><p>And now to create a ‘systemd service file’ for Gunicorn- a Python Web Server Gateway Interface HTTP server. I first pasted it into a text file and it looked like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*77wOwtqOqpF5oEcVsb22oQ.png" /><figcaption>systemd service file</figcaption></figure><p>This will start the server during the boot process and ‘serve’ the HumanGov application. Running these commands in the terminal will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Imvg6f2s18JthjzvkQusGg.png" /><figcaption>Running the systemd service file in the terminal</figcaption></figure><p>If everything was done correctly, I should be able to go into the stated directory and see a file named “humangov.service” Let’s check it out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-y0513GC4tP26EFK73FlLg.png" /><figcaption>Validating the humangov.service file found it’s new home</figcaption></figure><p>There it is in the left-middle. Now we’ll update the permissions to allow read/execute status for everyone- or chmod 0755, remove the default Nginx configuration file, and configure Nginx to proxy requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Ry8-Pu0_-lnEZYCLkbOYg.png" /><figcaption>Changing permissions, removing default configs, setting new configs</figcaption></figure><p>At this point, we’ll enable and start the Gunicorn service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ew68i4sgtDROeca8Lvuvbw.png" /><figcaption>Starting Gunicorn server</figcaption></figure><p>The above screenshot is showing us a green status in our application server, however, we wouldn’t be able to access the server yet because Nginx is not up and running, so let’s enable it.</p><p>I’ll first enable the service, check if the file (from the screenshot just before the above) gets populated in the proper directory, restart the HumanGov application, and check its status.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qDP8lN6Bpp8yoMICXnGAZQ.png" /><figcaption>Enabling the Nginx server and restarting the Gunicorn server</figcaption></figure><p>Ok. The manual configuration is done. Should we take a quick peek on the application and see if it really did work?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*syyzelJzMrEJ2uVrTwrLYQ.png" /><figcaption>Testing app after manual configuration</figcaption></figure><p>There it is! I’ll go ahead and hit the “add employee” button to add the CTO, Joe Shmo. If everything absolutely worked out, we should see his info in both DynamoDB and the S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wVup-29mBKOhSIRDPO0jXg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cRyuiVvr8lKgKpNn3fyzqg.png" /><figcaption>Validating the test data finds its way to DynamoDB and S3</figcaption></figure><p>Nice! Joe Shmo’s information was captured and stored just as we intended. That was a lot of work. I mean, not really, but we could have done a lot less than that. Let’s try again, but with ansible this time.</p><p>Real quick I’d like to add provisioners to the meat and potato main.tf file in Terraform. These provisioners belong under the EC2 instance resource block in the main.tf file. I’ll let you peak at it and explain what they do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mNqrv92SM56K3OCgTWiqvA.png" /><figcaption>Adding provisioners to Terraform file</figcaption></figure><p>The first is going to wait 30 seconds after the EC2 instance is provisioned and run the command:</p><p>ssh-keyscan ${&lt;private_ip&gt;} &gt;&gt; ~/.ssh/known_hosts” }</p><p>The output should be the public keys that will be added to the non-host file at the Ansible host level, so that Ansible doesn’t need to ask for confirmation about non-hosts everytime a new one is added or configured using Terraform.</p><p>The next one is pretty cool. It will populate the Ansible inventory file in a dynamic way. Once the EC2 instance is provisioned, it will add info about the instance to the Ansible file. It was a longer command and cut off by the screenshot. Think of it as a detailed nametag.</p><p>The last provisioner will run a ‘sed -i’ command that will look inside of the file (/etc/ansible/hosts) for an EC2 instance that matches the ID of a recently destroyed instance- to remove the Ansible Inventory file.</p><p>Moving on, I’ll create an empty Ansible inventory file on the patch /etc/ansible/hosts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nYVGXOQX43p4KHUQeI5xZw.png" /><figcaption>Creating Ansible inventory file</figcaption></figure><p>At this point I tested my infrastructure again by provisioning it with Terraform and pushed the changes to the local Git repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nDsk14K2Ht9OuGsAET7Xnw.png" /><figcaption>Pushing changes to the local repository</figcaption></figure><p>Heading into the real focus of this project(Ansible configuration) I outline the structure for the Ansible role. This consists of a few different folders and files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jubjsMVmeC39N1siZ8JPMw.png" /><figcaption>Ansible role structure</figcaption></figure><p>Of course I still had to create these manually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IISsDNosX4k8v4Tgv7ulLQ.png" /><figcaption>Creating Ansible role directories</figcaption></figure><p>And create a short Ansible config file getting rid of deprication warnings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ljFOKNVa6OBYydieK67GbA.png" /><figcaption>Disabling deprication warnings</figcaption></figure><p>Super quick, let’s Ansible ping all new instances and then create the necessary files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8D9ksdWx0NvTJbXnpGIVDQ.png" /><figcaption>Creating Ansible role files</figcaption></figure><p>Notice above how I had to add the private key for a successful ping.</p><p>I’ll move on by writing a file that contains the default values for our role variables:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dx_Vrrkdl7fK07NyCtrNeA.png" /><figcaption>Ansible default variable values</figcaption></figure><p>And now for the only section that gave me grief, handlers. Learning Ansible after Terraform can be rough on many folks because of the syntax. One wrong letter spacing or capital letter that should be lowercase will ruin it for you. I redid this step 2 times before having it work.</p><p>This next file contains handlers that restart the webserver and application. They’re triggered by configuration changes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AiqqqXxZpKVuDpySUnLUDA.png" /><figcaption>Ansible handlers</figcaption></figure><p>Now onto the grand daddy of them all. Our next main tasks file is where all tasks are defined.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cUVHwRFaBbdrNurQa0rNhw.png" /><figcaption>The heart and soul Ansible file part 1</figcaption></figure><p>If you skim over the above screenshot, you’ll get a sense of familiarity. Probably because I previously did all those tasks manually to configure the application. Here’s the rest of the file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IAjZmsg1fXR6HjlWJqPmhw.png" /><figcaption>The heart and soul Ansible file part 2</figcaption></figure><p>The last two files needing to be created are templates. The first is a Jinja2 template for the Gunicorn systemd service:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YFtyGR5sCBUi1OGzwnSkEw.png" /><figcaption>Jinja2 template</figcaption></figure><p>This is the systemd service file from earlier in this project. When this is ran, Ansible will use these variables to replace content of said files dynamically. In english, everything is curly brackets will grab the value of whatever they’re calling for. Example below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BlklvxZbLgUsdR6-X80BAw.png" /><figcaption>Validating the jinja2 template worked</figcaption></figure><p>All variables from the jinja template were named and given to this file above.</p><p>Now for our next template. Another Jinja2 template but for the Nginx configuration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l8hlONHXbfEcht-pvLhDXQ.png" /><figcaption>jinja2 template</figcaption></figure><p>There&#39;s one last file we must edit. To use this Ansible role, we’ll update the playbook deploy-humangov.yml and include it in the playbook:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TDpI4KAtYBKQBqyZUF4WLQ.png" /><figcaption>Updating the Ansible playbook</figcaption></figure><p>Let’s see what happens if we run the Ansible playboook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xz2Igsv5TohVGPzJbVGnaQ.png" /><figcaption>Running the Ansible playbook</figcaption></figure><p>I was so close to getting this done without issues, but remember I mentioned having trouble with the handlers file and syntax? That happened here and I couldn’t fix it without destroying the infrastructure and starting again. I did eventually correct the issue but failed to screenshot. I would look like the above anyway, minus the fatal handler at the bottom.</p><p>Let’s do a bigger test. I have only been spinning up and configuring one states worth of instances. Let’s add two more states the the mix and see if we can configure them all to work properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rsGuSDCyCFmh0eN4hjl3jA.png" /><figcaption>Adding 2 more state silo’s for creation</figcaption></figure><p>If we remember, each state gets 9 instances. With California already created, we should see 18 new resources provisions after running:</p><p>Terraform apply -auto-approve</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Fln5v6fqLWBP_YEMJfN5Q.png" /><figcaption>Validating successful creation of silo infrastructure</figcaption></figure><p>There you have it. 18 new instances. Now if I run:</p><p>cat /etc/ansible/hosts</p><p>The output should be each states EC2 instance IP address amongst other info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SdsFL4N3Pvoi5zz1aW_7dw.png" /><figcaption>Each states siloed infrastructure in readable format</figcaption></figure><p>Nice! Let’s Ansible ping all instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CfIgAK_2K55NmLvZGMH1ZA.png" /><figcaption>Pinging Ansible hosts</figcaption></figure><p>Thumbs up! you can also see that I ran the Ansible playbook to configure all 3 states HumanGov applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9sBlzULxtPfzuUq1LO-9AQ.png" /><figcaption>Running the Ansible playbvook</figcaption></figure><p>And everything worked out just fine. I’ll take the IPv4 DNS info for California and see if the HumanGov application is live.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5GzvGvjpWzrBnYImKnWsXw.png" /><figcaption>Grabbing the IPv4 DNS info for California from AWS</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5VFqEKDd108UqpINxLy3zw.png" /><figcaption>Testing California’s website</figcaption></figure><p>Woah! How about Florida and Nevada?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p8t89OW1XI1y9xIV3NTj7w.png" /><figcaption>Testing Florida’s website</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H6twRXW8LZBZvxbaA6q_wQ.png" /><figcaption>Testing Nevada’s website</figcaption></figure><p>Incredible! each state’s application was provisioned properly and shows their name.</p><p>Know what we should do right about now? Commit and push all changes to the local repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZBbNBAr5DbmJ-LcSAPHIVA.png" /><figcaption>Pushing last changes to the local repository</figcaption></figure><p>That’s it folks. If you’ve made it this far, you’ve earned your beans. You’re cool beans!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6cf52c1dbd9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Reusable SaaS Multi-Tenant Cloud Infrastructure Using Terraform And AWS CodeCommit]]></title>
            <link>https://medium.com/@jjrivera142/building-a-reusable-saas-multi-tenant-cloud-infrastructure-using-terraform-and-aws-code-commit-a8a7aaa148dd?source=rss-504cba90c997------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8a7aaa148dd</guid>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[dynamodb]]></category>
            <dc:creator><![CDATA[Jacob Rivera]]></dc:creator>
            <pubDate>Tue, 23 Apr 2024 01:23:46 GMT</pubDate>
            <atom:updated>2024-05-13T16:40:40.576Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z9xnKV5FyT6iIa6HCXbScg.jpeg" /></figure><p>This project is based on a real-world scenario. I acted as a DevOps Engineer writing the Terraform modules from scratch. To ensure the secure storage of the Terraform configuration files, I pushed them to AWS CodeCommit.</p><p>The infrastructure was based on AWS services such as EC2, DynamoDB, S3, and a Virtual Private Cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sza7LJiuU52_YpnMEW7-KQ.png" /></figure><p>The running theme of my last few projects is using Infrastructure as Code (IaC) to build on a software as a service (SaaS) company called HumanGov- which contracts with the federal government. The application is hosted on EC2, uses a DynamoDB to store the data, and an S3 bucket to hold the files. Each US state will claim an identical silo, but for the project, we’ll max out at three states.</p><p>The work starts by creating a new root directory to store the Terraform files, another to hold the module files, and standing up the big 3 of main.tf, variables.tf, and outputs.tf.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1advP_S2DtfbMZXK33rUrw.png" /><figcaption>Variables.tf</figcaption></figure><p>As seen above, I created a handy variable that lays the foundation for ease of usability while handing each state a silo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a8fBp1MDxahBjXBtHkSQfA.png" /><figcaption>Main.tf</figcaption></figure><p>Our main.tf above is the meat and potatoes of the project. My first move was creating a security group and naming the ports for the traffic to move through. The ‘tags’ uses interpolation to label each state&#39;s silo with its state name. The first resource created is an EC2 instance with its specific AMI, instance type, key name, and security group ID. Next is a DynamoDB- later on in the project I also spin up a DB from the command line. Following that, I created a ‘Random String’ for the bucket that will generate four arbitrary characters in their instance names. The file finishes by creating an S3 bucket.</p><p>Everything then gets tied in with our outputs.tf file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HTQk83TNdNrF5PgHDumbOg.png" /><figcaption>outputs.tf</figcaption></figure><p>We kick it up a notch by moving back to the root directory and creating a new set of main, variables, and output files to consume the directory our first set of files are in.</p><p>The purpose of our new main.tf file is to create the infrastructure for each state we list for creation simultaneously when it is executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AS5nlz8urU4MaxokPkW64g.png" /><figcaption>root main.tf</figcaption></figure><p>Moving on, our variables.tf file will list the states we choose to spin up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jTdpCXHXu2yP-i6pWTCiwg.png" /><figcaption>root variables.tf</figcaption></figure><p>Above, I’ve only listed California but I later added Texas and Florida. Our last file, outputs.tf, is used to group the siloed infrastructure instances by each state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8iGwgFDLWKU9QcWvaXhQFw.png" /><figcaption>root outputs.tf</figcaption></figure><p>I start taking action by initializing Terraform and validating that my files are ready. In the command line I ran:</p><p>terraform init</p><p>terraform validate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KSykrkGTd-zmRWJ4nx3wvw.png" /><figcaption>terraform Init and validate commands output.</figcaption></figure><p>I was given a warning that my files were skirting the line but may still work so I moved forward. Next up in running the command:</p><p>terraform plan</p><p>We should see five resources to be created since only one state was listed in the variables.tf file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xuVG8VXhxKDHg3kQwbZF_Q.png" /><figcaption>terraform plan</figcaption></figure><p>Perfect! Everything was written correctly in Terraform and after running:</p><p>terraform apply</p><p>-the infrastructure was completed in seconds! I ended up adding Texas and Florida to the variables file and spun up their silos:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OQoIFNJKGf9VnfFZfZRNNQ.png" /><figcaption>terraform apply</figcaption></figure><p>California&#39;s resources were already created, that’s why we see “10 added” resources instead of 15 since each state gets 5. Let’s head over to the AWS console to see if this magic has worked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gVSBvWLkX4mYBpOPxDdpWA.png" /><figcaption>DynamoDB tables</figcaption></figure><p>Nice! Now we see our IaC in action by labeling each state&#39;s resources. All three DBs are alive and well. Now onto EC2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AJZVlh-nn94g0RIqftAh6A.png" /><figcaption>EC2 instances</figcaption></figure><p>And there they are looking healthy. Let’s do one more check for our S3 buckets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q7ff_WgjEkHiW6OPLK-o5g.png" /><figcaption>S3 buckets</figcaption></figure><p>Would you just look at it?</p><p>It was at this moment, I zoned out for 20 minutes and didn’t screenshot my progress so I’ll walk you through. I created a new S3 bucket from the command line to store the Terraform state file remotely. The command was easy enough:</p><p>aws s3api create-bucket — bucket humangov-teraform-state-x142 — region us-east-1</p><p>If you look closely enough, you’ll notice I forgot an R in Terraform. Now to create a DynamoDB from the command line:</p><p>aws dynamodb create-table \</p><p>— table-name humangov-terraform-state-lock-table \</p><p>— attribute-definitions AttributeName=LockID,AttributeType=S \</p><p>— key-schema AttributeName=LockID,KeyType=HASH \</p><p>— provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \</p><p>— region us-east-1</p><p>While the S3 bucket was a quick one-liner command, the DB command line creation was long enough that I could’ve made it in the console faster- but it’s still important to learn how to create it from the command line. Afterwards, I created a new file in the project&#39;s root directory named backend.tf which will unironically hold our back-end configuration:</p><p>touch backend.tf</p><p>The file was edited with the following content:</p><p>terraform {</p><p>backend “s3” {</p><p>bucket = “humangov-terraform-state-x142”</p><p>key = “terraform.tfstate”</p><p>region = “us-east-1”</p><p>encrypt = true</p><p>dynamodb_table = “humangov-terraform-state-lock-table”</p><p>}</p><p>}</p><p>This configuration will send our terraform.tfstate file to an S3 bucket as well as the lock file to a DynamoDB.</p><p>After this, I ran:</p><p>terraform init</p><p>terraform apply</p><p>and the files successfully made it to their new homes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e-FkuLimAiH2Piu_c7p2xw.png" /><figcaption>tfstate file in an S3 bucket</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dQbiDVT_0houoSTEMJ49Lw.png" /><figcaption>lock file in DynamoDB</figcaption></figure><p>I’m going to do something crazy and delete the tfstate file from Terraform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jpvPtLoVGf6ZDy05pM7N7Q.png" /><figcaption>removing the tfstate file</figcaption></figure><p>After removing the file and running:</p><p>terraform show</p><p>We can still visualize the content!? We shouldn’t be able to without a tfstate file but it’s held in an S3 bucket and kicking hard.</p><p>Now to add a .gitignore file to my repository to exclude sensitive information and temporary files generated by Terraform from being tracked. The following extensions and files on the git ignore list looked like:</p><p>.terraform/</p><ul><li>.tfstate</li></ul><p>*.</p><p>tfstate.backup</p><p>*.tfvars</p><p>*.tfplan</p><p>*.tfr</p><p>*.tfstate.lock.info</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vf0a_L5QNqwXNVGutZyvNw.png" /><figcaption>.gitignore list</figcaption></figure><p>The file was pushed to my git repository on AWS Code Commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AvAUx7SvD2M9h8CzcjW3Pw.png" /><figcaption>pushing .gitignore to Code Commit</figcaption></figure><p>Let’s check Code Commit for any new files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9pvaKO2ctXDpmAOjpSpwJw.png" /><figcaption>AWS Code Commit repository</figcaption></figure><p>Nice! Now what’s in that Terraform folder?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8FuzjBvP3DDYTHFo-SD5g.png" /><figcaption>Reusable HumanGov infrastructure</figcaption></figure><p>And there you have it folks. Anyone on my team can look at and edit these files because I pushed them to the repository instead of keeping them local on my machine.</p><p>The project wouldn&#39;t be real if I didn&#39;t run:</p><p>terraform destroy</p><p>If you’ve made it this far, you’re cool beans.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8a7aaa148dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementation Of Git Repositories For Infrastructure And Application Code Using AWS CodeCommit]]></title>
            <link>https://medium.com/@jjrivera142/implementation-of-git-repositories-for-infrastructure-and-application-code-using-aws-codecommit-3339b5a5d214?source=rss-504cba90c997------2</link>
            <guid isPermaLink="false">https://medium.com/p/3339b5a5d214</guid>
            <category><![CDATA[codecommit]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Jacob Rivera]]></dc:creator>
            <pubDate>Sun, 07 Apr 2024 20:35:28 GMT</pubDate>
            <atom:updated>2024-04-07T20:35:28.503Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4_q0fVHf2x69W2RzJJaF8w.jpeg" /></figure><p>This project was based on a real-world scenario of two developers working on a project for a Software as a Service (SaaS) company named HumanGov. I implemented Git repositories for application and infrastructure code using AWS CodeCommit and acquired hands-on experience with the Proof of Concept (PoC) process of commit, push, and revert code changes. An AWS Cloud9 EC2 instance was utilized throughout this project. Cloud9 is not the focus. This would work using any linux terminal and code repository.</p><p>Learning how to navigate Git and repositories is crucial for environments where teamwork is necessary- like working on a team of developers and DevOps engineers perchance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U1fObhflzzOpwhYUBCd9Dg.png" /></figure><p>In this simple scenario, we have a developer finishing a project and leaving on vacation any minute whilst another is in his second week on the job. Our second developer already knows his way around Git and GitHub of course. Let’s set up the Cloud9 environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jpR07KW8cG6rJVpK7mZDCg.png" /><figcaption>Configuring Cloud9</figcaption></figure><p>As seen above, I simply gave the Cloud9 instance a name and left the rest default. You’ll notice that it will create an EC2 instance using the free tier t2.micro vCPU. We like free.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kr3UNNPyfGXL3zpdoUtUDw.png" /><figcaption>Configuring Cloud9</figcaption></figure><p>Lastly, above you’ll see we’re utilizing Amazon Linux as our EC2 platform, 30 minutes timeout, and will connect via SSM and not SSH. This streamlines the project as it only takes one click to access the instance.</p><p>Before we truly kick things off, we must create two repositories in AWS. This takes nearly 0 brain power. To do this, we navigate to CodeCommit in AWS, click ‘Create repository’, and give them each names while leaving everything else default. Below, we have repositories named Human-Gov-Infrastructure and Human-Gov-Application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eJJGH3nTNArDoLTNh9y1VQ.png" /><figcaption>AWS CodeCommit repositories</figcaption></figure><p>Task 1. And now to configure the AWS CLI credential helper in our AWS Cloud9 development environment. We will run the commands:</p><p>git config — global user.name “Jacob Rivera — DevOps Engineer”</p><p>git config — global user.email jjrivera142@yahoo.com</p><p>git config — global credential.helper ‘!aws codecommit credential-helper $@’</p><p>git config — global credential.UseHttpPath true</p><p>Following these commands, we’ll need to clone our AWS CodeCommit repositories to the Cloud9 CLI, specifying the HTTPS clone URL. See below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x3MubiY5do5o5bRp0bqHjA.png" /><figcaption>Configuring the AWS CLI credential helper and cloning the repository</figcaption></figure><p>Task 2. Using AWS Cloud9, perform proof of concept (poc) process of commit, push, and revert code changes. The developers come into play soon. First, let’s create and configure a Cloud9 environment to simulate Software Developer 1 working environment. I opened up a new Cloud9 EC2 instance and ran the same commands as the previous configuration.</p><p>git config — global user.name “Software Developer 1”</p><p>git config — global user.email dev1@humangov.com</p><p>git config — global credential.helper ‘!aws codecommit credential-helper $@’</p><p>git config — global credential.UseHttpPath true</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fme6ycpDZfTk-0ShGKwKqg.png" /><figcaption>Configuring Dev1’s Cloud9 Environment</figcaption></figure><p>Moving on, we clone the Human-Gov-Application repository to their Cloud9, create the index.html file they’re working on, and then commit and push it to our AWS repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q4_G7BeEQpm1fHimcDywCA.png" /><figcaption>index.html file in Cloud9</figcaption></figure><p>The index.html file reads:</p><p>&lt;!DOCTYPE HTML&gt;</p><p>&lt;HTML&gt;</p><p>&lt;head&gt;</p><p>&lt;title&gt;My Website&lt;/title&gt;</p><p>&lt;/head&gt;</p><p>&lt;body&gt;</p><p>&lt;header&gt;</p><p>&lt;h1&gt;Welcome to HumanGov!&lt;/h1&gt;</p><p>&lt;nav&gt;</p><p>&lt;ul&gt;</p><p>&lt;li&gt;&lt;a href=”#”&gt;Home&lt;/a&gt;&lt;/li&gt;</p><p>&lt;li&gt;&lt;a href=”#”&gt;About&lt;/a&gt;&lt;/li&gt;</p><p>&lt;li&gt;&lt;a href=”#”&gt;Contact&lt;/a&gt;&lt;/li&gt;</p><p>&lt;/ul&gt;</p><p>&lt;/nav&gt;</p><p>&lt;/header&gt;</p><p>&lt;main&gt;</p><p>&lt;p&gt;This is a PoC for HumanGov Git Repository.&lt;/p&gt;</p><p>&lt;/main&gt;</p><p>&lt;footer&gt;</p><p>&lt;p&gt;© My Website. All rights reserved.&lt;/p&gt;</p><p>&lt;/footer&gt;</p><p>&lt;/body&gt;</p><p>&lt;/html&gt;</p><p>And now to commit the index.html file-</p><p>To do this, I changed directory to human-gov-application, ran ‘git status’ to show that the file was untracked, ran ‘git add index.html’ followed by ‘git status’ again to show the changes to be committed to the repository, and finished with ‘git commit -m first commit to poc’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Brfcum5MJuVwCBM2e-ZzUw.png" /><figcaption>Commit and push the first commit</figcaption></figure><p>Above you’ll notice I also ran ‘git log’ because returns the hash, author, date, and comment on the commit. The last thing to do was push it to the repository. For that, I ran:</p><p>git push -u origin master</p><p>Now if we check our repository in AWS, we just might see the file named index.html.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5R8RD2-hzkvgWWIgD6prw.png" /><figcaption>index.html in the repository</figcaption></figure><p>There it is plain as day. I want to see a bit more detail about this push. For that, I navigated the options on the left to ‘Commits’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d7RVpvkbZjLHSTg4g6hl6Q.png" /><figcaption>index.html commit info</figcaption></figure><p>So now, developer 1 does a quick preview of the website before he changes the code and leaves on vacation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HKaslBxxjTS9YKZfxoT6Ig.png" /><figcaption>Dev 1 previewing the website</figcaption></figure><p>He’s been tasked with changing the size of the welcome comment. Simple enough right? All he has to do is change</p><p>&lt;h1&gt;Welcome to HumanGov!&lt;/h1&gt;</p><p>to</p><p>&lt;h2&gt;Welcome to HumanGov!&lt;/h2&gt;</p><p>but he makes a simple mistake- adds an extra W and clocks out for vacation. Now we have</p><p>&lt;h2&gt;WWelcome to HumanGov!&lt;/h2&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7kPOGlulnuXL1NcfsZJ-9g.png" /><figcaption>Dev 1 mistake</figcaption></figure><p>Oh boy. This is about to be set free in the production environment. The new guy is still here, right? Get him to fix this before we lose a little credibility with our customers.</p><p>Dev 2 quickly configures his Cloud9 environment exactly as Dev 1 has.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KbEOhLzfyK7CwFwUNs7Pqg.png" /><figcaption>Developer 2 configuring their Cloud9 EC2 instance</figcaption></figure><p>He previews the website and gives out a subtle chuckle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ER3Kt-KKMyaF_mdjmdL8GQ.png" /><figcaption>Dev 2 previewing the website mistake</figcaption></figure><p>He knows exactly what to do in this scenario. He checks the log to get the hash given for the commit that messed up the website. He simply runs:</p><p>git log</p><p>and copies the hash from the header change commit and runs:</p><p>git revert &lt;hash&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oAq_JEPu2oBn9GinLPP6Kw.png" /><figcaption>Getting the hash from the git log</figcaption></figure><p>Nice! And now to remove the extra W.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2mExc2P1wDg01Fq0GYPsuA.png" /></figure><p>Dev 2 finishes the job by running:</p><p>git add index.html</p><p>git commit -m “fixed header size to h2”</p><p>git status</p><p>git push -m origin master</p><p>ALL in a day’s work! When the manager checks out the commits in the AWS CodeCommit, it should look something like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s4zwax_h3lpO7uaQ4vfzAA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3339b5a5d214" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating an E-Commerce website hosted on AWS using Terraform and Ansible]]></title>
            <link>https://medium.com/@jjrivera142/automating-an-e-commerce-website-hosted-on-aws-using-terraform-and-ansible-b0ee8fa8023b?source=rss-504cba90c997------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0ee8fa8023b</guid>
            <category><![CDATA[ecommerce]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[ansible]]></category>
            <dc:creator><![CDATA[Jacob Rivera]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 16:24:26 GMT</pubDate>
            <atom:updated>2024-03-25T16:26:38.040Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c42Po6Sq_9iP_uAJ_-l6Xw.png" /></figure><p>In my last AWS project for the foreseeable future, I worked as a Cloud Engineer using DevOps tools to implement an e-commerce MVP (Minimum Viable Product) on AWS in less than an hour. The website was automated using Terraform and Ansible (Infrastructure as Code — IaC).</p><p>I provisioned the infrastructure using Terraform- and Ansible to automate the configuration management process, software installation, and package management of the EC2 instance. Magento, PHP, MySQL, and Redis were also used to complete this project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*maPof0YhnzOd4K1M8kIS2Q.png" /></figure><p>First things first is creating an account on Magento, an E-commerce platform now owned by Adobe, where our online store will run. Following creating an account, we create a pair of access keys so Ansible can download the necessary software on our virtual machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C4cmV5RburuciHZL0_e2mg.png" /></figure><p>Next is installing Terraform and the AWS Linux repo on the AWS Cloud Shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MCo-SQmvoctlGqsCxWt_Ww.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n_Ng0yk65MpFeKIZ3TSUvg.png" /></figure><p>At the bottom of the screenshot above, you can see that I created a new directory for my final project and downloaded my Terraform files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qYQ0NmAbAwwnZdMAk-LjVA.png" /></figure><p>I usually run a t2.micro on my EC2 instances but it does not have enough memory to run Magento. While the t3a.large is not free, I won&#39;t run it for long. It’ll cost me 7 cents an hour which isn’t exactly breaking the bank.</p><p>It is not a security best practice to open up the traffic to the internet like shown in the main.tf above, this is just for the project and it will be destroyed not long after fruition.</p><p>Let’s get this instance running:</p><p>terraform init</p><p>terraform plan</p><p>terraform apply</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kfQ5EJdpSIjQY_jgSZSfGw.png" /></figure><p>I neglected to take a screenshot of terraform plan. That being said, we’re provisioning an EC2 instance and a security group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hNKFAtXVObyuy12kFupfBw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vO6uiZhNMsGqZia_TPC-zg.png" /></figure><p>It took only 13 seconds to stand up! How’s that for automation?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ADJWwOpQRPSJsgrc0xOXvQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tIwiTHm9cHANiebV-UMX5g.png" /></figure><p>Let’s SSH into our VM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hDa0HOiunfs9ueHjmYPMYA.png" /></figure><p>Next is installing Ansible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*95nmLfkFgDehFP2bEpTE0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HnRhVsTHJvw4STs-xE9Ybw.png" /></figure><p>And now to download/unzip our playbook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PfLBC6DQdUr2lgDJzt5D0Q.png" /></figure><p>Our Magento access keys will come to life as we edit our group_vars/all.yml file. Of course, I blacked them out below. We also input our EC2 instance public IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GFQgD2HpLgI351UylE3KMA.png" /></figure><p>Running Ansible to deploy the stack of tools for the e-commerce website was by far the longest step of this project. It took roughly 20–25 minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xaL-YHtuvE1f8jkRqA0KGA.png" /></figure><p>I was ecstatic that I had no failures. See below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QRPUZN_3gdGipV1gMbsRZw.png" /></figure><p>Alright! Everything should be working. Let’s copy the public IP of the EC2 instance into our browser and see what we find.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GGUUSxHgy2fs_lGVFBlF9g.png" /></figure><p>LET’S GO!!! The website took about 15 seconds to load. I can’t lie, I was sweating a bit. Editing the website isn’t the focus of this project, but indulge me for a moment. You’ve read this far, so might as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zf7jWvlVl-IBZp7aVbjaIw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5kGTtWcFB2LlvCn71gjeTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-TS4dgHiwwamC5iRCppqYQ.png" /></figure><p>Wow! (That’s an expensive shirt) By now you should have realized the power of Terraform and Ansible. I can’t imagine how long this would have taken if every step had been manually inputted. Until next time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0ee8fa8023b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On-Premises to AWS SAP Migration Project and Executive Presentation]]></title>
            <link>https://medium.com/@jjrivera142/on-premises-to-aws-sap-migration-project-and-executive-presentation-79dab28d043c?source=rss-504cba90c997------2</link>
            <guid isPermaLink="false">https://medium.com/p/79dab28d043c</guid>
            <category><![CDATA[aws-pricing-calculator]]></category>
            <category><![CDATA[cloud-migration]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Jacob Rivera]]></dc:creator>
            <pubDate>Fri, 22 Mar 2024 15:58:05 GMT</pubDate>
            <atom:updated>2024-03-22T15:58:05.126Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zMSfjs3oRtaM-isZHBrPzw.png" /></figure><p>Back with another real-world scenario, I acted as a Cloud Architect and created an executive presentation of infrastructure costs for an SAP migration project from On-Premises to AWS.</p><p>In other words, we’re going window shopping today.</p><p>SAP workloads ran in a corporate data center with the environment divided into Production, Quality Assurance — QA, and Development/Test layers.</p><p>My mission was to estimate the cost of migration to AWS, considering that the infrastructure will run on AWS for at least 3 years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YAWiEB6UsU4Npr2a7D_c8w.png" /></figure><p>After glancing over the solution architecture above, we can reference the AWS Pricing Calculator for solid numbers on our migration and export our findings in .csv format to an Excel spreadsheet.</p><p>I must reiterate that our infrastructure will run for at least 3 years because AWS offers up to a 72% discount on some reserved instances, for example, EC2 and RDS. This comes with an “hourly spend commitment”. When you buy Reserved Instances- the larger the upfront payment, the greater the discount. We will elect not to pay upfront, allowing us to free up capital to spend on other projects. Let’s crunch some numbers, shall we?</p><p>First up will be the web servers and block storage belonging to Production. They’ll need five application servers- each with 8vCPU of the t3a.2xlarge family, 16GB memory, and 400GB of block storage for each instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_O4qsGWV_peheUFdvG3RQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKYLhQQsLpZiq8CimYmKNw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z8Oaxa_DBRLg_anVH2zsgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L1067ZrOxnhenA9eERHAng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XUH-g1AS4j9ck9e0T7C6gA.png" /></figure><p>The t3a.2xlarge did not offer 16GB memory so we opted for the 32GB version. Now take careful consideration and attempt to guess the first leg of our 12 months cost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OCx03yPtg6j7yD_5mj3HHg.png" /></figure><p>Aaaand we’re just north of $15,000. Strap in, because this is a legitimate business with legitimate business needs.</p><p>Our load balancers are next up and every org needs one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*sKKVCDR893S9unWtpNXkwg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DxQUlNF9wIAT17fRtg-maQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bqLiAznJtw9U2i1DlTzWzA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xdCi2EuawVFhvEYNLlym8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6AtWi7qaHgWzIfNLixoC7Q.png" /></figure><p>That’s just about $3,500 for load balancers.</p><p>Moving on to our network file system storage. We’ll need 1750GB per month.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LaZDqBBY4kNm1DUDeWVTlg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NkDjOFPmub5pAM1TRecQxQ.png" /></figure><p>Our Elastic File System will run us north of $3,100 yearly.</p><p>On deck are five more servers and block storage for Stage and Dev/Test. They’re asking for 4vCPU of the t3a.xlarge family, 8GB memory, and 300GB block storage for each instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H68JFyrdEtPmHO-b-ZCtVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7YKvhdK959UfLRSltFLQ4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-AtXXV2TzOBVEfpkbVIf4w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B8V8tghKS42668rSHQI_jg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pjoMKdwNjfR_i-z9v17Cjw.png" /></figure><p>I’ll spare you the calculations until we finish and export them to Excel.</p><p>Now to Oracle databases. Production needs two and we oblige. They call for two instances in the db.m4.10xlarge class accompanied by 40vCPU and 160GB- multi-availability zone deployment, 1500GB storage per instance, and 3TB backup storage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*USVodIlcZX-0orPxclbTBQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pv5f9r1Z9xmovLNJ2lqNAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yn6REo2vOdcdRSo_3N-KjA.png" /></figure><p>That was quite the jump from $30,000. To add insult to injury, Stage also needs two Oracle database instances. Each will be of the db.m4.4xlarge family, 16vCPU, 64GB memory, single availability zone, 1500GB storage, and 3TB backup storage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j40ihVP-HL3bs4IDAQNXKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r_EdudeJUgRgtm35JrDLqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pDVWNryi_FhtabuYBV6Fyg.png" /></figure><p>While not as expensive as the databases belonging to Production, they’re still a pretty penny. Now hold on, because Dev/Test mentioned needing an order of two databases. db.m3.2xlarge family, 8vCPU, 30GB memory, single availability zone, 500GB per instance, and 1TB backup storage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*88Or2FsGGbBKl8yY_xl3OQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W21PBxWV0lFqS0eeXnk2NQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*96tCf2_h3nj_oJ6VEkQf3Q.png" /></figure><p>By now the finance department is screaming “No more! Stay on-prem!” So we hit them with a jab, touched on our need for an enterprise support plan, and suggested hiring a better CPA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DMqKn78xDn-WOqE46GiYJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6LJDDqbYXh7x5kKcWuMgJw.png" /></figure><p>Drumroll for our combined 12-month bill…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*10RoWweRMukv5H-WdCyBmA.png" /></figure><p>$454,000 smackeroos. This includes any upfront costs and will not be our final yearly number. We’re also tasked with creating a PowerPoint for the stakeholders. In the top right of the screen, hit export&gt;.csv format. Start up Excel and open the new .csv file. It should look something like…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yWR4oQvr2t1bngi1qEnb8A.png" /></figure><p>Now throw your numbers into a PowerPoint-like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9sChCyDbgWhl2vgH5XGsVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PYZNmQ5iC2wkiALuhvC2UA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6QH_IolmflPfxNNRk93dmw.png" /></figure><p>As gut-punching as the yearly bill is, the decision is ultimately up to the C-suite and we now have an executive presentation ready to go!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79dab28d043c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Set of EC2 Instances Using Terraform and AWS Systems Manager Configuration with Amazon…]]></title>
            <link>https://medium.com/@jjrivera142/implementing-a-set-of-ec2-instances-using-terraform-and-aws-systems-manager-configuration-with-7381ee6dcb23?source=rss-504cba90c997------2</link>
            <guid isPermaLink="false">https://medium.com/p/7381ee6dcb23</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devsecops]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Jacob Rivera]]></dc:creator>
            <pubDate>Mon, 18 Mar 2024 04:54:17 GMT</pubDate>
            <atom:updated>2024-04-26T22:07:34.944Z</atom:updated>
            <content:encoded><![CDATA[<h3><em>Creating a Set of EC2 Instances Using Terraform and AWS Systems Manager Configuration with Amazon Simple Notification Service for Automated Installation of Agents</em></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vKdof7cu7jfz9EzF6PRNpw.png" /></figure><p>This project is based on a real-world scenario. I acted as DevSecOps Engineer and deployed a set of EC2 instances and infrastructure in an automated fashion using Terraform (infrastructure as code — IaC). Also, installing a security agent in all instances was necessary.</p><p>Once I provisioned the infrastructure, AWS System Manager and its component ‘Command Run’ were used to install the security agents. I used the Amazon Simple Notification Service(SNS) to send an email informing the whole processes status.</p><p>So what will the solution architecture look like?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l5nIFDSszczl4WNhBGpnYA.png" /></figure><p>This was no beast of a project and if you run into any issues, it very well may pertain to the terraform portion. We’ll talk about that later. I format my articles in a way that you as the reader may execute along with me, so long as you have your own intricate items- or specifically for this project, your own terraform files, AWS key pair, and agent. Let’s get started.</p><p>The first thing you’ll want to do is download VSCode. Boot up VSCode and download two extensions. 1. ‘Hashicorp Terraform’ VSCode extension and 2. A material icon theme extension called “Prettier’. These cover color and formatting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4SCYzlhkO4r6EEEcB051DQ.png" /></figure><p>You can find IaC templates on the Terraform website. I merely had to input some specifics. For example, my VPC ID, subnet ID, and key name amongst other things. You also see a security group and web servers that will be provisioned, but the first three examples will have to be manually provisioned and their data written in your IaC. At the very least, you’ll have to create a key pair in your AWS IAM console, use the default VPC, and subnet. I recommend doing this from an IAM user account and not root, as it’s against security best practices to create a key pair for your root account. You will have to add specific permissions to the IAM user like EC2FullAccess, SNSFullAccess, and CloudShellFullAccess. There is no cut-and-dry SystemsManagerFullAccess and this will get in the way during the latter portion of this project so I indeed finished it using my root account. Back to IaC-to finish, create a zip folder out of the folder holding main.tf and provider.tf.</p><p>Above in the IaC snippet, you can see &lt;variable “key_name”&gt; so let’s create one. Head over to EC2&gt;Key pairs&gt;Create Key pair. Our main.tf already has a name for the key pair as “sshkey1”. Everything else will remain default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ErCi7ip2d35Rvj5kRBgfBA.png" /></figure><p>Now let’s install Terraform on AWS Cloud Shell. This comes with 4 commands that should be run separately.</p><p>sudo yum install -y yum-utils</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NqAnoctflC1pkcLOQbQTAA.png" /></figure><p>sudo yum-config-manager — add-repo <a href="https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo">https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo</a></p><p>followed by:</p><p>sudo yum -y install terraform</p><p>terraform -v</p><p>Now upload the terraform zip file to the AWS Cloud Shell. If you don&#39;t know how, click ‘Actions&gt;Upload file’.</p><p>And now to provision our infrastructure with three commands:</p><p>terraform init</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vddn2hNc8-TB9QGIxBZJeg.png" /></figure><p>I was moving through this project on cloud 9 and forgot to get screenshots of the next two commands so here are examples of what it should look like:</p><p>terraform plan</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lWxmGPq8svJxtJXzuKtDvQ.png" /></figure><p>terraform apply</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3OKRstJvBvFEwJU16Bp2Cg.png" /></figure><p>Say yes if everything looks good.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hm8KVE-kD8cJIKAc_0-v1g.png" /></figure><p>Looking back on our IaC, the three resources we set to create were two web servers and a security group.</p><p>Next is creating an IAM role SystemsManagerToSNS. Head to the IAM console&gt;Roles&gt;Create Role. Use cases for other AWS services: Systems Manager | Allows SSM to call AWS services on your behalf. Hit Next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xGZc6FnANviNUQZzA82WBg.png" /></figure><p>Continuing on, we’ll select the policy AmazonSNSFullAccess.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M617cJl6vkyrWFng5CPz-Q.png" /></figure><p>Role Name: SystemsManagerToSNS</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XGNr5_x5YGBHl8iRT7KeEg.png" /></figure><p>Moving on, let&#39;s create a Notification Topic named DevOpsNotification and copy the ARN for later. Head to the SNS console&gt;Topic&gt;Create Topic.</p><p>Change the ‘Type’ to Standard. Nothing follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oY6r1qDaQNT0RnHcTygn_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FdTU-HngEoUSjWVrH5QYLg.png" /></figure><p>There’s the ARN. Screenshot or copy it to a note for later.</p><p>Now let’s make sure we get emailed when instances are created. It’s actually called a subscription (free of charge). Still in the SNS console, go to Subscriptions&gt;Create Subscription. The protocol will be ‘email’ and the endpoint will be whichever email we’d like to receive the notifications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vkcEHzLTzFYgxYksNeX73g.png" /></figure><p>After hitting ‘Confirm Subscription’ you’ll have to head to that email and confirm to start.</p><p>We’re getting close to the end. We now have to configure a run command to install our agent on the web servers. This has three parts.</p><p>Part 1. Head to the Systems Manager console&gt;Quick Setup&gt;Host Management&gt;Create. Select Current Region (or Choose Region if your instances are in other regions), under ‘choose how you want to target instances’ select Manual, and select both web servers that Terraform created, then scroll down to click Create and wait about 10–15 minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7qsMj89HaW3Hpd4jHE9-gg.png" /></figure><p>Part 2. Validate the configuration “Success” status, then you’ll want to scroll down the left column to ‘Node Management’ and select ‘Session Manager’&gt;Start Session. Select one of the web servers and click ‘start session’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tvs-Crb3mCb5xEabdqFQpg.png" /></figure><p>Another tab will pop up with a terminal. We’ll run the command:</p><p>cat /etc/*release*</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EHgupdKyCW15Z777_cv8-A.png" /></figure><p>Above you can see how I got ahead of myself by running:</p><p>ls -ltr /usr/bin/security_agent</p><p>But we haven’t installed an agent yet. We’re so close to the end.</p><p>Part 3. Execute “Run Command” to deploy the security agent installation. Back under ‘Node Management in the left column, select Run Command&gt;Run A Command. We’re going to select AWS-RunShellScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ybfq-qr4euDaHTX4x2AiXg.png" /></figure><p>Let’s feed it some command parameters. Here’s mine which included my agent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9hvesg9s7IJFMr_Z5qbl5w.png" /></figure><p>Select ‘Choose Instances Manually’ and highlight both the web servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I5RuqjiZIXrW97cjnVW0rA.png" /></figure><p>Scroll down and uncheck ‘Enable writing to S3 Bucket’ and select Enable SNS Notification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4q_Rn6PV8jh_KLbIDREkxg.png" /></figure><p>In the IAM Role dropdown, choose SystemsManagertoSNS and then it’s showtime for the DevOpsNotifications ARN from earlier. Pull it up and input it to the SNS topic. When done, hit run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a4bWexcGkiWjQWw49rCOrg.png" /></figure><p>We should have some event notifications in our email by now. Go ahead and check. Here’s what mine looked like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHbRqLlzumALgkO_ioJObQ.png" /></figure><p>Lastly, refresh the page and check the output!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OykF72MUz27BCdgBpOafMg.png" /></figure><p>Let’s go!!!!!! My security agent is up and running!</p><p>Let’s say you did follow along, you’ll want to de-provision all of these newly created instances to save money. Re-run those terraform commands to reinstall it in the AWS Cloud Shell and run:</p><p>Terraform destroy</p><p>If you run into issues with terraform destroy; delete the tf.state files and try again. Still running into issues? Manually delete all newly created instances.</p><p>You’ve made it to the end, you’ve earned your beans. You’re cool beans.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7381ee6dcb23" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Execution of a Scalable Web Application using AWS Elastic Beanstalk, DynamoDB, CloudFront, and Edge…]]></title>
            <link>https://medium.com/@jjrivera142/implementation-of-a-scalable-web-application-using-aws-elastic-beanstalk-dynamodb-cloudfront-and-00d16e9385a7?source=rss-504cba90c997------2</link>
            <guid isPermaLink="false">https://medium.com/p/00d16e9385a7</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[elastic-beanstalk]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Jacob Rivera]]></dc:creator>
            <pubDate>Sat, 09 Mar 2024 04:19:44 GMT</pubDate>
            <atom:updated>2024-04-26T22:06:07.146Z</atom:updated>
            <content:encoded><![CDATA[<h3><em>Execution of a Scalable Web Application using AWS Elastic Beanstalk, DynamoDB, CloudFront, and Edge Locations</em></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vyyUmMJxKPSGow2Ns1FIsw.png" /></figure><p>In this project based on a real-world scenario, I was responsible for implementing an application that needed to support a high demand of users accessing it simultaneously- a conference with 10,000 participants in person AND online.</p><p>Ten vouchers for three different cloud certifications would be raffled off. At that moment, those 10,000 in the audience will register their e-mails hoping to be a lucky contestant.</p><p>I used AWS Elastic Beanstalk services to deploy the web application, DynamoDB to store emails, and CloudFront to cache static and dynamic files in Edge Locations worldwide.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fh-2rrUNSN2eMAFC2HaBsQ.png" /></figure><p>My first step was creating DyanoDB to store participants&#39; emails hoping to get their hands on a cert voucher.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dlrq5pT1opnr2CMYfv9zsw.png" /></figure><p>This took close to zero effort.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eu76Qm5dF1egn_xEJiuIPQ.png" /></figure><p>As shown above, the DynamoDB table was given the name “users” and the partition key name “email”. That’s it.</p><p>Now to the fun part- Elastic Beanstalk, which “is an orchestration service for deploying applications which orchestrate various AWS services, including EC2, S3, Simple Notification Service, CloudWatch, autoscaling, and Elastic Load Balancers.” Or in English, you can provision an application and its underlying infrastructure without having to manually create each alone.</p><p>Elastic Beanstalk will first provision EC2 instances, then a load balancer, followed by an autoscaling group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f0CyRpZAVw51IYEcbJnKbg.png" /></figure><p>Actually- before we move forward, this would be a good time to create a new SSH key pair in ‘.pem’ format. This will be used to SSH into the application via the terminal later on. Save it somewhere safe as we’ll need to remember the path. Now back to Elastic Beanstalk.</p><p>Step 1. <em>Configure Environment</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*STw6O54_gIkD4aM7fl7tFA.png" /></figure><p>The beginning is simple enough. Name the application and environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uXIGvDBHmCp7Vi5el0PZHA.png" /></figure><p>Next is choosing the runtime environment that will serve our application. I’m a Python type of guy so what the heck. This application necessitated high availability- you’ll see that in the presets below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o3DQUsQeeBCNdy1Js_NiTQ.png" /></figure><p>I have source code coming from an S3 bucket. How about a preview?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qHH1FRm-JAwD__ZID2ZPbw.png" /></figure><p>Step 2. <em>Configure service access</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GlP8kmdXbik_nMg9wRssbA.png" /></figure><p>Basically, we’re giving Elastic Beanstalk power of attorney to create new services and instances. More specifics on that later. The service role selected above came with two policies; <strong>AWSElasticBeanstalkEnhancedHealth </strong>and <strong>AWSElasticBeanstalkManagedUpdatesCustomerRolePolicy. </strong>There goes that SSH key pair I mentioned earlier too.</p><p>Elastic Beanstalk Enhanced Health: “This policy grants all of the permissions that Elastic Beanstalk requires to monitor environment health. It also includes Amazon SQS actions to allow Elastic Beanstalk to monitor queue activity for worker environments.”</p><p>Elastic Beanstalk Managed Updates Customer Role Policy: “This policy grants permissions for Elastic Beanstalk to update environments on your behalf to perform managed platform updates.”</p><p>Oops, I forgot to create an EC2 instance profile. Let’s open another tab and head over to IAM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fd0SgCIoMjanmy9bxAsUgg.png" /></figure><p>The permissions needed for this role were <strong>AWSElasticBeanstalkWebTier, AWSElasticBeanstalkWorkerTier, </strong>and<strong> AWSElasticBeanstalkMulticontainerDocker.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KLcQKCu_3uVGMSfz4CznxQ.png" /></figure><p>Alright, back to Elastic Beanstalk.</p><p>Step 3. <em>Set up networking, database, and tags</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AxFBVCWH-A9FIDDx-OqRew.png" /></figure><p>The default VPC was used because when I selected my previously created VPC, it didn&#39;t allow for any instance subnets, and this application needs to be highly available i.e. we will end up with instances in different subnets. Don’t get too confused, we’re not there just yet. Above, you see that I selected only one zone. We will change the instance size in the next step and then come back to this step to select all zones. If you select all zones now, you’ll get an error. Moving on!</p><p>Step 4. <em>Configure instance traffic and scaling</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h5U0gHR0JxfbvjHXJKLl1g.png" /></figure><p>This step is very important because we will tell Elastic Beanstalk “if we receive too much traffic and cannot handle it, create a few more EC2 instances to lessen the load.” I started by choosing ‘General Purpose SSD’ with a size of 10 GB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CWzr9H6jTVfhbx_WrrxWtg.png" /></figure><p>The above reads a minimum of 1 instance but I later changed that to 2. With max at 4, that means Elastic Beanstalk will provision 2 more EC2 instances if our traffic load becomes too great for the 2 originally provisioned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z3xQpz4a058-3O3k_tZf8g.png" /></figure><p>I changed my instance type to ‘t2.micro’ because it is ‘free tier’ eligible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7iJEcUH398bkfC_TQKv8KQ.png" /></figure><p>Here is the meat and potatoes. The above shows our scaling trigger. What you don’t see, is the metric and units I fed to it. I chose ‘CPUUtilization’ as the metric and ‘percent’ as the units. These together will let Elastic Beanstalk know when it’s time to scale up and create new EC2 instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7iJEcUH398bkfC_TQKv8KQ.png" /></figure><p>The above image tells us that when an EC2 instance meets 50% utilization, it’s time to create another. Likewise, when those new instances drop below 40%, they are to be de-provisioned- or ‘deleted’ if you will.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q5yI7biOx1mocUofL_LT3Q.png" /></figure><p>Public visibility means the load balancer will be exposed to the internet. Notice how I chose all available subnets? Now we must return to the previous step and select them as well because we only have 1 subnet selected there. Other than that, step 4 is complete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*maPR1syM_yzO-UbXESmDtg.png" /></figure><p>Alright. Everything is moving along just fine. Onto the last step.</p><p>Step 5. <em>Configure updates, monitoring, and logging</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6VyHxZJLlsK-3Qo3zAl5MA.png" /></figure><p>I scrolled to the bottom of this page to add another environment variable. Later, this environment variable will be passed to Linux in our EC2 instance to use our new variable and understand that the application is getting deployed in the above-shown region of ‘us-east-1’.</p><p>That’s it for Elastic Beanstalk. What’s left is to review your configurations before selecting to create the app. This will take a few minutes. You can go to the ‘Events’ tab in Elastic Beanstalk and look at its logs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ejBqkl3NMkaPMTra7ictkg.png" /></figure><p>Here you’ll find any errors Elastic Beanstalk came across during the provisioning process if there were any.</p><p>Let’s validate that everything is working and access the domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jZPXy1Qh0e1XA4igk9ez4Q.png" /></figure><p>Nice! The app is working. Should we try and add Joe Shmo to the voucher raffle? That would be cool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZ8_SRyZu5E8LBJbCkTY-w.png" /></figure><p>Oops. But what&#39;s wrong? We just configured our Elastic Beanstalk- everything was working, right? Maybe we should head back to the Elastic Beanstalk module and check out the logs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AN4kFySncXH3bCqsf7npDw.png" /></figure><p>Come to think of it, Elastic Beanstalk may not have full access to DynamoDB. Why don’t we take care of that?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yRirYRlrLS3uYndPGorwNQ.png" /></figure><p>Head over to IAM-Roles-&lt;Elastic Beanstalk EC2 Role&gt; and add another permission to the list (<em>AmazonDynamoDBFullAccess). </em>Now let’s try adding Joe Shmo again<em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rl4-GKLehk37XWatC2TInw.png" /></figure><p>Let&#39;s go!!! And if we check DynamoDB, we should see the email address(es) we entered for the raffle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1LcFkkHZ4idv575wd5O3zw.png" /></figure><p>There they are clear as day. If you remember the solution architecture illustration, then you’d probably ask, “Where is CloudFront? How will the participants in other countries enjoy low latency during the conference?” CloudFront will cache our data in an Edge Location near them so their internet doesn’t need to travel across the world and back. Let’s go ahead and create it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fh-2rrUNSN2eMAFC2HaBsQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KqVL6AMvqyF2eKtxOjddXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g8U5nAAbdgl6dfzpyAlKKQ.png" /></figure><p>Our origin is the Elastic Load Balancer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5LbVSkpeqiN5OUHKPFA1-g.png" /></figure><p>Under ‘allowed HTTP methods’ I chose the third option because I needed my application to use the POST method for inserting data inside DynamoDB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4hCmDAH6qWCW9UHJLSHTLw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bvkdcwBmWjFzj1ADOKP98Q.png" /></figure><p>That’s it. Let’s click ‘Create distribution’ and see what happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TOdXjhqvglM92NTF2f7CYg.png" /></figure><p>Now all static and dynamic files coming from this application will be cached in edge locations worldwide, reducing latency for a participant from Ecuador for example.</p><p>That’s it. Everything has been provisioned. We could end here, but we couldn’t confidently tell our manager that we’re certain this app can handle those 10,000 plus participants accessing the app. What if we performed a stress test?</p><p>What we want to see from this stress test is Elastic Beanstalk provision extra EC2 instances to help handle the expected traffic.</p><p>Pull up the path to our SSH ‘.pem’ key I mentioned earlier so we can access one of our provisioned EC2 instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lHB1kPg4zsC5Gm8x5cXlRA.png" /></figure><p>If you have any trouble getting in like I did, you’ll need to ‘chmod 400’ your ‘.pem key’ like so:</p><p>chmod 400 &lt;ssh.pem key&gt;</p><p>Or you can follow the above image.</p><p>chmod 400 grants only the owner or user of the file read permission while restricting everyone else entirely. Now let&#39;s go ahead and download the stress tool.</p><p>Sudo yum install stress -y</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S1FYp6o8k_HBLv1VPZqtZg.png" /></figure><p>Time to put some stress on our system:</p><p>stress -c 4</p><p>The above command will bump up the CPU utilization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L_eMf2l1YxCWD660w04NhA.png" /></figure><p>If you return to your Elastic Beanstalk environment on AWS, you should see the health status change to “Warning”. This is a good sign (for this project). This means the CPU is nearing the maximum acceptable range before deploying another EC2 instance.</p><p>Let’s open a new terminal for a second SSH connection so we may check out the CPU utilization.</p><p>Once you SSH into the instance, run these commands:</p><p>ps aux</p><p>ps aux — sort=-pcpu</p><p>top</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7mCyuG_mWvvQtZlE_JbpHw.png" /></figure><p>Woah! That’s showing 4 CPU’s which would mean our Elastic Beanstalk provisioned two more EC2 instances for us. All four have equal CPU utilization, proving that our load balancer is doing its job.</p><p>Lastly, let’s see if our logs did their job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eWt3Jpkw05hcv8teNnYDLw.png" /></figure><p>The above logs are from ‘Elastic Beanstalk-events’. You can see when we started our stress test and when a new EC2 instance was provisioned to handle the increased load.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uZqJah1UQaNqBLI5t2TUUg.png" /></figure><p>‘EC2-auto scaling groups’ logs show us the same.</p><p>Let’s go back to the terminal and end the stress test. Simply run ‘control c’. To ensure the test is over, run:</p><p>ps -ef |grep stress</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LqCcEkEeF9ZpX8mGu0NVOw.png" /></figure><p>That’s it! I’ll give myself a pat on the back for this one. If you’ve read this far, you have earned your beans. You’re cool beans.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=00d16e9385a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migration of a Workload running in a Corporate Data Center to AWS using the Amazon EC2 and RDS…]]></title>
            <link>https://medium.com/@jjrivera142/aws-project-2-migration-of-a-workload-running-in-a-corporate-data-center-to-aws-using-the-amazon-c58f748405ca?source=rss-504cba90c997------2</link>
            <guid isPermaLink="false">https://medium.com/p/c58f748405ca</guid>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Jacob Rivera]]></dc:creator>
            <pubDate>Wed, 28 Feb 2024 22:21:04 GMT</pubDate>
            <atom:updated>2024-03-24T03:25:59.499Z</atom:updated>
            <content:encoded><![CDATA[<h3><em>Migration of a Workload running in a Corporate Data Center to AWS using the Amazon EC2 and RDS service</em></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MYrkt1lvCnZ1olMs3npi1w.png" /></figure><p>In this project I was responsible for migrating a workload running in an Enterprise Data Center to AWS, or specifically, migrating an application and its database using Amazon EC2 and RDS services.</p><p>The application and database were migrated to AWS using the Lift &amp; Shift (rehost) model, moving both application and database data. I followed the migration steps: Planning (sizing, prerequisites, resource naming), Execution (resource provisioning, best practices), Go-live (validation test — Dry-run, final migration — Cutover), and Post Go-live (ensure the operation of the application and user access).</p><p>The solution architecture comprised of implementing a Virtual Private Cloud with its subnets, an EC2 instance to store the application, and an RDS instance to store the database. For the app to be accessible via the internet and attached to the VPC, an internet gateway was established.</p><p>NOW IN ENGLISH!</p><p>Our customer sends us a spreadsheet outlining the specifics of their application and database including server names, descriptions, compute power, and storage necessary. We then determine which services in AWS would be necessary to move their operation to the cloud whilst keeping costs low.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*30akkcHIdP9zDtw6pT01Bg.png" /></figure><p>As seen above, we’ve chosen to utilize EC2 and an RDS paired with MySQL, both employing t2.micro with AWS’s free tier eligibility. We also see the region, availability zone, VPC, and subnet they will belong to.</p><p>AWS RDS Subnet Group is a collection of subnets that you can use to deploy your RDS database in a VPC. Your VPC must have at least 2 subnets and they must be in different Availability Zones. When creating the VPC, we follow our spreadsheet and give it the proper name. IPv4 will remain default with ‘IPv4 CIDR manual input’ and a CIDR block of 10.0.0.0/16. (In a production environment, we wouldn’t define a CIDR block that will overlap with our on-premise environment) That’s it for VPC.</p><p>Now to our subnets. We need a few in place for our app server, a public subnet for users to reach, and a private subnet for our database-also making sure they fall under the proper availability zone. During creation, we relate it to our newly created VPC. Our public subnet falls under 10.0.0.0/24 and private under 10.0.1.0/24. Now our database will reside in a different availability zone to safeguard our data in the unlikely event of a DB instance component failure or loss of service in one availability zone. The subnet will still follow the current trend as 10.0.2.0/24. We now have all three of our subnets created.</p><p>At this point we need to create an internet gateway for our EC2 traffic to communicate to the internet.</p><p>The next step is to attach the VPC and gateway. When doing so, a route table is created that needs to be updated. Head over to the route tables section, select the route related to our vpc, scroll down to “routes”, and click add routes.</p><p>You’ll see one route with a destination of 10.0.0.0/16 and target of ‘local’. Click add routes, destination “0.0.0.0/0” and select our gateway for the target. Whenever there is a request from a client anywhere on the internet to the EC2 instance, the traffic will be routed through our gateway. Similarly, whenever the EC2 initiates an outbound request to the internet, the traffic is also routed through the gateway. Now we save our changes and the route table has been updated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Y_jNDDOvBs6UwkMYSFa2g.png" /></figure><p>So far we’ve created a new VPC, a few new subnets, an internet gateway, and a route table pointing to the internet gateway. The next step is to provision the EC2 instance that will host our application.</p><p>Navigate to the EC2 module in AWS, select ‘instances’ on the main screen OR off in the left column, and click the orange button ‘launch instances’.</p><p>Name the EC2, and choose Ubuntu 22.04 64bit as our OS because it’s free tier eligible. Our instance type; or the size, is listed in our spreadsheet. It’s the t2.micro because it works for our client and is also free tier eligible.</p><p>STOP! The next step is extremely important as it pertains to connecting with our virtual machine over SSH.</p><p>It’s time to create a new key pair. Give it a name and save the file as ‘.pem’. Move this file to a folder specific to this project. Once again, this is extremely important.</p><p>Now let’s define our network settings. We’ll edit those settings to include our newly created VPC and change the subnet to our also newly created PUBLIC subnet. This instance needs to be available over the internet so we can access the application to see it up and running.</p><p>Next, under ‘auto-assign public IP’, click ‘Enable’. Moving forward, we’ll create a new security group. On AWS, a security group is like a firewall. We’ll already see a security group rule “TCP, Port 22, 0.0.0.0” in the settings that are open to the entire internet.</p><p>You should never have an SSH port open to the world when it comes to production instances. For now, we’ll continue. Add a new rule, select type ‘Custom TCP’, Protocol ‘TCP’, and port ‘8080’. Under source type, click ‘anywhere’. Do a quick review on ALL settings then go ahead and launch the instance.</p><p>While that’s launching, we’ll create our RDS instance. Navigate over to RDS, then instances, and select the orange button “create database”. Keep ‘standard create’ selected and choose ‘MySQL’ as your engine. I used MySQL 8.0.35 and also selected the free tier for my template. In settings, choose your new database name and configure your credential settings- or “log in/password”. This DB class was also t2.micro because that’s coming from our planning spreadsheet. 20GB storage was the minimum given and also works for our clients as they needed much less.</p><p>Scroll down to ‘connectivity’ and change the VPC to our newly created VPC. Leave ‘create a new subnet group’ enabled. Next, leave “public access-no” enabled. Our database should never be exposed to the internet.</p><p>Under VPC security group, select ‘create new’ and insert your necessary group name. Under ‘availability zone’, select the same AZ as your EC2 instance. In my case, this also came from the planning spreadsheet. If you migrate back up to the solution architecture, you’ll notice that both the EC2 and the DB must fall under the same AZ. We can go ahead and review all changes made and create our database.</p><p>By now we’ve created a new VPC, an EC2 that will host our application, an RDS that will host our database, and an internet gateway.</p><p>Now we need to connect to our EC2 instance and prepare it with all the libraries and packages necessary to receive the application. Go ahead and copy the public IP address as it’ll be needed to remote in.</p><p>Open your terminal or GitBash, change directory to your desktop, CD to your folder with the SSH key pair, and run remote connectivity. This can be done by running:</p><p>ssh ubuntu@&lt;public IP&gt; -I &lt;ssh key pair&gt;</p><p>It’ll give a warning, say yes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z-2sbw0HtXt7PprXXRQaXw.png" /></figure><p>Not working? Then run:</p><p>Chmod 400 &lt;ssh key pair&gt; and try again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0K8Z0QzidPvmtTPxDIREQ.png" /></figure><p><strong>“Ubuntu 22.04</strong>” prompts ‘pop-ups’ after install/update packages requiring:</p><p><em>“What service should be restarted?”</em></p><p>By default, this is set to “interactive” mode which causes the interruption of scripts.</p><p>To change this behavior, we can edit the file:</p><p><strong><em>/etc/needrestart/needrestart.conf</em></strong></p><p>cat /etc/needrestart/needrestart.conf | grep -i nrconf{restart}</p><p>You’ll get ‘i’</p><p><strong>From:</strong></p><p><strong><em>#$nrconf{restart} = ‘i’;</em></strong></p><p><strong>To:</strong></p><p><strong><em>$nrconf{restart} = ‘a’;</em></strong></p><p>‘<strong>i</strong>’ interactive | ‘<strong>a</strong>’ automatically</p><p>Change by using the ‘sed’ command:</p><p>sudo sed -i “/#\$nrconf{restart} = ‘i’;/s/.*/\$nrconf{restart} = ‘a’;/” /etc/needrestart/needrestart.conf</p><p>Checking:</p><p>cat /etc/needrestart/needrestart.conf | grep -i nrconf{restart}</p><p>Now that’s settled, you’ll want to update the OS. Run:</p><p>sudo apt-get update</p><p>At this point, I needed to install the proper packages and libraries necessary for this project.</p><p>sudo apt install</p><p>python3-dev -y</p><p>sudo apt install python3-pip -y</p><p>sudo apt install build-essential libssl-dev libffi-dev -y</p><p>sudo apt install libmysqlclient-dev -y</p><p>sudo apt install unzip -y</p><p>sudo apt install libpq-dev libxml2-dev libxslt1-dev libldap2-dev -y</p><p>sudo apt install libsasl2-dev libffi-dev -y</p><p>pip install Flask==2.3.3</p><p><strong>You’ll get a Warning…</strong> continue on with:</p><p>export PATH=$PATH:/home/ubuntu/.local/bin/</p><p>pip3 install wtforms</p><p>sudo apt install pkg-config</p><p>pip3 install flask_mysqldb</p><p>pip3 install passlib</p><p>Now on to installing MySQL client:</p><p>sudo apt-get install mysql-client -y</p><p>We’re almost ready. We still want to make sure the application server can connect to the RDS.</p><p>Head back to the AWS console and move to VPC. On the left column, scroll down and select ‘security groups’.</p><p>Now select the security group you created during the RDS provisioning. If you don’t remember which, look under ‘Description” and find the group that states “Created by RDS…….”</p><p>Look for ‘Inbound Rules’ and select ‘edit inbound rules’. You’ll see that traffic is only allowed from one IP address. For this project, we’ll allow traffic from anywhere, or 0.0.0.0. This is not a security best practice. In the real world, you’d place only the allowed IP addresses.</p><p>Now save the rules.</p><p>Head over to EC2 and copy the public IP of our newly created instance so that we may remote in.</p><p>Open your terminal or GitBash and create a new SSH connection as we did earlier:</p><p>ssh ubuntu@&lt;public IP&gt; -I &lt;ssh key pair&gt;</p><p>Now it was time for me to download the dump files that came from the on-premises database and the zip file that has the application deployment file. For me, it looked like:</p><p>wget <a href="https://aws-mod3.s3.amazonaws.com/wikiapp.zip">https://aws-mod3.s3.amazonaws.com/wikiapp.zip</a></p><p>wget <a href="https://tcb-bootcamps.s3.amazonaws.com/bootcamp-aws/en/module3/dump-en.sql">https://tcb-bootcamps.s3.amazonaws.com/bootcamp-aws/en/module3/dump-en.sql</a></p><p>Next, let’s go ahead and open a remote connection to the MySQL DB:</p><p>mysql -h &lt;endpoint_do_rds&gt; -P 3306 -u admin -p</p><p>It’ll ask you for the password you created earlier in RDS provisioning.</p><p>This next step is very important. I tripped over configuring the DB and had to re-do this step during my project creation. We’re going to import the data coming from the database dump.</p><p>Creating a DB ‘wikidb’ and importing data to it:</p><p>Create database wikidb;</p><p>Use wikidb;</p><p>The terminal will say “Database Changed” and that’s what we’re looking for. Continuing, we’ll run a source command to import the data from the dump. For me, it looked like:</p><p>source dump-en.sql;</p><p>show tables;</p><p><strong>select * from articles;</strong></p><p>Next up is creating a new user for the application:</p><p>CREATE USER wiki@’%’ IDENTIFIED BY ‘admin123456’;</p><p>GRANT ALL PRIVILEGES ON wikidb.* TO wiki@’%’;</p><p>FLUSH PRIVILEGES;</p><p>exit;</p><p><strong>The database portion is now finished.</strong></p><p><strong>Now to unzip the app deployment files. For me, it looked like:</strong></p><p><strong>unzip wikiapp-en.zip</strong></p><p><strong>From all the files unzipped, one needed to be edited. First I changed directory over to it:</strong></p><p><strong>cd wikiapp/</strong></p><p><strong>Then:</strong></p><p><strong>vi wiki.py</strong></p><p><strong>Under ‘# Config MySQL’ I needed to edit the output of ‘MYSQL_HOST’ to the RDS endpoint- the very same that was used to remote into the MySQL DB. The user and password also needed editing.</strong></p><p><strong>Once done, hit Esc, then ‘:x’ to save and exit.</strong></p><p><strong>The very last step was of the project. Test the application!</strong></p><p><strong>Run:</strong></p><p><strong>Python3 wiki.py</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*AzvjAyYk4bJ3IxioLRKPeg.png" /></figure><p>Alright, it’s running in the terminal. Open up your browser, input your EC2 public IP, and remember to input &lt;:8080&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*Sk8lx96Xa24rp1jLAugDQw.png" /></figure><p>THE WEBSITE WORKS AND THE MIGRATION WAS SUCCESSFUL!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E2tCj5SUhHa4n8AYmjIHoA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j-ju2zbrzaBw3FFqXwR96A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c58f748405ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated user migration and management of AWS Identity and Access Management (IAM) resources]]></title>
            <link>https://medium.com/@jjrivera142/automated-user-migration-and-management-of-aws-identity-and-access-management-iam-resources-fe835d8331a8?source=rss-504cba90c997------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe835d8331a8</guid>
            <dc:creator><![CDATA[Jacob Rivera]]></dc:creator>
            <pubDate>Mon, 19 Feb 2024 02:56:26 GMT</pubDate>
            <atom:updated>2024-02-19T02:56:26.877Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AE_ZAX_PBZlbp9eByk9L8g.png" /></figure><p><strong>In this project based on a real-world scenario, I acted as a Cloud Specialist with the mission to migrate users to the cloud in an automated fashion and manage AWS IAM resources.</strong></p><p>100 users needed migration AND have MFA enabled on their accounts, as this is a security best practice.</p><p>To avoid repetitive and manual tasks in the AWS console, I automated the process using GitBash with AWS CLI and Shell Script.</p><p>Now let’s dive in.</p><p>I was given a spreadsheet containing all users with accompanying names, emails, and teams (eg. DBA, Network Admin, Linux Admin, Cloud Architect, and Trainees) and a JSON file needed later to manually create an MFA enforcement policy.</p><p>First things first, I had to manually create user groups in AWS identical to the format on the spreadsheet so we’d have a seamless transition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n-COmwZpqohd0r2ofaTH0Q.png" /></figure><p>I then needed to install dos2unix in the AWS CloudShell followed by the IAM script file that would automate the whole process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uJTBig3iJ6Yirzx6jm9GeA.png" /></figure><p>Based on the first argument of the script, the given spreadsheet had to be converted to CSV format.</p><p>This script read the file, ran the AWS CLI commands to create the user and login profile, forced the password to be changed on the first login, and added the user to their perspective group defined in the spreadsheet.</p><p>Before uploading the file to the CLI, the permissions of the script had to have been changed giving an execution permission.</p><p>Now it was time to run the script and give the CSV file as a parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hqjcQNSSrM1Om4YeOgMpDw.png" /></figure><p>After taking a quick trip over to the AWS IAM console, we see that the users have been imported. For time sake purposes, I migrated only a few users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qi-P2KTlHWd6LHiYz_l9ig.png" /></figure><p>The work was not done here. I manually added the IAMUserChangePassword policy to every group.</p><p>Taking a quick trip to an incognito window, we can now see the password policy in effect when trying to log in from a new user account</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ljxe_TDk4PIb6KMGqBe-0Q.png" /></figure><p>Lastly, I created a customer-managed policy named ‘EnforceMFAPolicy’ and attached it to each group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xEAOmavBN88RsBHv7zdCxA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZsFKart2yJFrAPcL4NMedw.png" /></figure><p>Moving forward, all users will be forced to use MFA to operate in their respective AWS accounts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe835d8331a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>