<?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 Babatunde Aborisade on Medium]]></title>
        <description><![CDATA[Stories by Babatunde Aborisade on Medium]]></description>
        <link>https://medium.com/@babatunde.aborisade1?source=rss-a5a8b319b1ea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jlUH-3uKMH9pJ24D</url>
            <title>Stories by Babatunde Aborisade on Medium</title>
            <link>https://medium.com/@babatunde.aborisade1?source=rss-a5a8b319b1ea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 03:15:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@babatunde.aborisade1/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[Building A Three-Tier Architecture In AWS!]]></title>
            <link>https://medium.com/@babatunde.aborisade1/building-a-three-tier-architecture-in-aws-5f9357e7774a?source=rss-a5a8b319b1ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f9357e7774a</guid>
            <dc:creator><![CDATA[Babatunde Aborisade]]></dc:creator>
            <pubDate>Sun, 24 Mar 2024 18:41:52 GMT</pubDate>
            <atom:updated>2024-03-24T18:41:52.047Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*PR19gPNH5SIKbt_Hh3_TWw.png" /></figure><p><strong>Scenario:</strong> A small e-commerce company named Toy-Blitz wants a scalable and reliable e-commerce platform for their toy business and decided to get a 3-tier architecture deployed with the help of an AWS Engineer.</p><h3><strong>Objective 1:</strong> Create a Web Tier</h3><h3><strong>VPC</strong></h3><p>We need to create a VPC first. Login to your AWS account and type VPC into the search box and click Create VPC.</p><p><strong>VPC Settings:</strong> VPC only.</p><p><strong>VPC Name:</strong> Toy-Blitz-VPC.</p><p><strong>IPv4 CIDER block:</strong> IPv4 CIDER manual.</p><p><strong>IPv4 CIDR:</strong> 10.0.0.0/16.</p><p>IPv6 CIDR block: No IPv6 CIDR block.</p><p><strong>Tenancy: </strong>Default.</p><p>Click <strong>create VPC</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*GlWDWtSpo_zvfCIHwvQPFQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pyPyFtdCKGHHR32XVgsPYQ.png" /></figure><h3>Internet Gateway</h3><p><strong>Name Tag : </strong>Toy-Blitz-IGW</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*wNlAEfvbjhr61VPVW6WjXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/223/1*HxF0YmiBw0k1bjYxzucy8g.png" /></figure><p>Attach to VPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*Cfm5EzKScXSDByPfHJ1hAg.png" /></figure><p>Select <strong>Toy-Blitz-IGW.</strong></p><h3>Public Subnets</h3><p>Next we need to create two Public Subnets for the VPC. Click on Subnets underneath the virtual private cloud section on the left.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/204/1*GB3TsjPWoQs_BEqvcYmIMw.png" /></figure><p>Click on <strong>create subnet</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZjYEGyUZq2yT2dkYaAHfNQ.png" /></figure><p><strong>VPC ID:</strong> Toy-Blitz-VPC.</p><p><strong>Subnet Name:</strong> Toy-Blitz-Public-Subnet-1</p><p><strong>Availability Zone:</strong> US East (N. Virginia)/ us-east-1a.</p><p><strong>IPv4 VPC CIDR block:</strong> 10.0.0.0/16</p><p><strong>IPv4 subnet CIDR block:</strong> 10.0.1.0/24</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Bov7gWXyQKih-F7yhJLFtA.png" /></figure><p><strong>Subnet Name:</strong> Toy-Blitz-Public-Subnet-2</p><p><strong>Availability Zone: </strong>US East (N. Virginia)/ us-east-1a.</p><p><strong>IPv4 VPC CIDR block:</strong> 10.0.0.0/16</p><p><strong>IPv4 subnet CIDR block:</strong> 10.0.2.0/24</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*yj2b3Kx_iFzGQL93ndOltA.png" /></figure><p>Click create subnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KUfWX53QHr0BFWl4nSZqMw.png" /></figure><h3>Public Route Table</h3><p>Click on Route tables on the left side underneath Virtual Private Cloud and click on Create route table.</p><p><strong>Name: </strong>Toy-Blitz-Route-Table.</p><p><strong>VPC: </strong>Toy-Blitz-VPC.</p><p>Click<strong> create route table</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*vOVT7Tum6OUhi0DpJkxZlQ.png" /></figure><p>Now lets connect our subnets we created earlier to the route table.</p><p>click on the route table, go to the subnet associations tab and click edit subnet associations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iX-fSVy_aqOUS7COcQ_6lQ.png" /></figure><p>Select both Public subnets and click save associations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vZVHd-ysrljevzsZohBZog.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cF2blipq5iJUXCqCkwNoAg.png" /></figure><p>The Public Subnets are successfully attached to the route table.</p><p>Click on <strong>Routes </strong>tab and click on edit routes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ul3vfDm1kNp6QK-1S2hWAg.png" /></figure><p>Attach the Internet Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQqU5RhVMOJee2gvCanxQw.png" /></figure><h3>NAT Gateway</h3><p>Click on <strong>NAT Gateway</strong> on the side panel underneath Virtual private cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/1*_6B6stSaFc97mml_BaUETQ.png" /></figure><p>Click <strong>Create NAT Gateway.</strong></p><p><strong>Name: </strong>Toy-Blitz-Public-NAT-Gateway.</p><p><strong>Subnet:</strong> Toy-Blitz-Public-Subnet-1.</p><p><strong>Connectivity Type:</strong> Public.</p><p><strong>Elastic IP allocation ID: </strong>Click on Allocate Elastic IP to generate it.</p><p>click <strong>create NAT gatway.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*EgsHRCjLZ2ojIdoYlhh4xg.png" /></figure><h3>AMI/Launch Template</h3><p>We are going to create a AMI with a bootstrap of Apache 2 included in the user data.</p><p>Search<strong> AMI</strong> in the search bar.</p><p>Click <strong>AMI Catalog </strong>and search for Ubuntu, choose the free tier U<strong>buntu Server 22.04</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ST5sFuAbUSGHkLtgo91hHQ.png" /></figure><p>Click<strong> Create AMI with Template</strong>.</p><p><strong>Name:</strong> Toy-Blitz-EC2-AMI.</p><p><strong>Template version description: </strong>Template for EC2.</p><p><strong>Auto Scaling guidance:</strong> ✅</p><p><strong>Application and OS Images (Amazon Machine Image):</strong> Ubuntu.</p><p><strong>Instance Type:</strong> t2.micro.</p><p><strong>Key Pair:</strong> Toy-Blitz-KeyPair.</p><p><strong>Network Settings:</strong></p><p><strong>Subnet:</strong> Do not included in launch template.</p><p><strong>Create Security Group:</strong> ✅</p><p><strong>Security Group Name:</strong> Toy-Blitz-SG.</p><p><strong>Description:</strong> Security Group for Toy-Blitz.</p><p><strong>Advanced Details:</strong></p><ol><li><strong>User Data</strong>:</li></ol><pre>#!/bin/bash<br>sudo apt-get update -y<br>sudo apt install -y apache2<br>systemctl start apache2<br>systemctl enable apache2</pre><p>This is going to install <strong>Apache</strong> to our EC2 Instances.</p><p>Click <strong>Create Template</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZV4WW4m6GmQddA8pbf0cHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UakxN0RBkEj5DrppEA5zmg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*sP-MqM7uWaez5zCVek_xzw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*O6aRSxCYe5np7ghzDuJD1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*UOVX5AoSQoGJfGsJfi1NIQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*EqKwbhF9b0_7DcLcFddzNQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MVLG8pA_D9qXzAneSTAQRw.png" /></figure><h3>Web Security Group</h3><p>Within our launch template we specified to create a security group, lets verify it is created.</p><p>Type <strong>security group</strong> in the search bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ZGPOLtVbhOjHSacGzEYNg.png" /></figure><p>Click <strong>Toy-Blitz-SG ID</strong>.</p><p>Let’s add inbound permissions, click edit<strong> inbound rules</strong>.</p><p><strong>Add Rules:</strong></p><ol><li>HTTPS Port 443.</li><li>HTTP Port 80.</li><li>SSH Port 22.</li><li>Custom TCP Port 8080.</li></ol><p>Set them to your IP Address for best practice standards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S8EmxwI5UkiVEdSXSflQuw.png" /></figure><p>Click save rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lw4KvQsO3mXvcGpaQIOpiQ.png" /></figure><h3>Autoscaling Group</h3><p>We need an Autoscaling Group, type Autoscaling Group in the search bar.</p><p>Click<strong> create Auto scaling Group</strong>.</p><p><strong>Auto scaling group name: </strong>Toy-Blitz-ASG.</p><p><strong>Launch template:</strong> Toy-Blitz-EC2-AMI.</p><p><strong>Version: </strong>Default (1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*vJQaw6EAgrqsAsH-Ox8hqw.png" /></figure><p>Click<strong> next.</strong></p><p><strong>VPC:</strong> Toy-Blitz-VPC.</p><p><strong>Availability Zones and subnets</strong>: Toy-Blitz-Subnet-1, Toy-Blitz-Subnet-2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*9gHHdNbDRKLsekLznoNMdQ.png" /></figure><p>Skip Load Balancer.</p><p><strong>Desire Capacity: </strong>2</p><p><strong>Min. Desire Capacity:</strong> 2.</p><p><strong>Max Desired Capacity</strong>: 5</p><p><strong>Automatic scaling</strong>: No scaling policies.</p><p><strong>Instance maintenance policy:</strong> No policy.</p><p>Click next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*0O0fuo_H_kpumTh_1yxGZw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*xgmUVuJoWVugqmH0WgmUvA.png" /></figure><p>Skip Notifications &amp; Tags.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*YUgapfp11z_XrXCX6JAjcQ.png" /></figure><p>Click<strong> create Auto Scaling Group</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eTV9fHdfdDXB2tMrw0E8ag.png" /></figure><p>Lets verify our EC2’s were created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ej3bxpcpf0_t97iyXFsBrA.png" /></figure><h3><strong>Objective 2:</strong> Create a Application Tier</h3><h3>Private Subnets</h3><p><strong>VPC ID:</strong> Toy-Blitz-VPC.</p><p><strong>Subnet Name:</strong> Toy-Blitz-App-Private-Subnet-1</p><p><strong>Availability Zone:</strong> US East (N. Virginia)/ us-east-1a.</p><p><strong>IPv4 VPC CIDR block:</strong> 10.0.0.0/16</p><p><strong>IPv4 subnet CIDR block:</strong> 10.0.160.0/24</p><p><strong>VPC ID:</strong> Toy-Blitz-VPC.</p><p><strong>Subnet Name:</strong> Toy-Blitz-App-Private-Subnet-2</p><p><strong>Availability Zone:</strong> US East (N. Virginia)/ us-east-1a.</p><p><strong>IPv4 VPC CIDR block:</strong> 10.0.0.0/16</p><p><strong>IPv4 subnet CIDR block:</strong> 10.0.128.0/24</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*MxJt8uRnkLYDdR7Buz2_ig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*WzWNgoXauVBYDKejoKSB4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DQxMO8sSLyEIjHkn-t_Esw.png" /></figure><h3>Private Route Table</h3><p><strong>Name:</strong> Toy-Blitz-App-Private-Route-Table</p><p><strong>VPC:</strong> Toy-Blitz-VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*UL5H-oTYBGyT8ap8bhXtaQ.png" /></figure><p>Click<strong> create route table</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*muRhz-NQ52NHt903Q3GknQ.png" /></figure><p>Associate your Private Subnets to the Private Route Table.</p><p>In Route Table, select <strong>Toy-Blitz-App-Private-Route-Table and</strong> select<strong> subnet associations tab t</strong>hen click on<strong> edit subnet associations under explicit associations.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G875i4GX9-cL72WEmTHSug.png" /></figure><p>Select <strong>Toy-Blitz-App-Private-Subnet1</strong> &amp; <strong>Toy-Blitz-App-Private-Subnet2.</strong></p><p>Click <strong>save association.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KcN6VrPbXD5dGZaS_Bfdnw.png" /></figure><p>Go to the<strong> Toy-Blitz-App-Private-Route-Table</strong> and click on routes and edit routes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*20mtSxdke3Qv_LwzzeXHYA.png" /></figure><p>Attach the NAT Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3dU9lJ6XIxUHSsE-KEh28Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pAWAUBJoo13IZkfmHsaPrQ.png" /></figure><h3>AMI/Launch Template</h3><p>Create another launch template for your Application tier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*hb3WrAkBUfMmte-Kko43-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*RQP3XHk67ZRvHku-2X9rFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*Te7g43HItFPwXnNinQjisQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*HF7np0bWM-5m3SvN4_YUWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*k7q9auggcuz-TkwA6VO-lw.png" /></figure><p>Click <strong>create launch template</strong>.</p><h3>Auto scaling Group</h3><p>Complete the steps to create a Autoscaling group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YakqhnaHBFCHGfBVXRu_6w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*MqLAbczdTbRLABC08j3GZg.png" /></figure><h3><strong>Security Group</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nzGcH0iwToAFSoR-Y6W1Yg.png" /></figure><h3><strong>Objective 3:</strong> Create a Database Tier</h3><h3>Private Subnets</h3><p><strong>VPC ID:</strong> Toy-Blitz-VPC.</p><p><strong>Subnet Name:</strong> Toy-Blitz-DB-Private-Subnet-1</p><p><strong>Availability Zone:</strong> US East (N. Virginia)/ us-east-1a.</p><p><strong>IPv4 VPC CIDR block:</strong> 10.0.0.0/16</p><p><strong>IPv4 subnet CIDR block:</strong> 10.0.96.0/24</p><p><strong>VPC ID:</strong> Toy-Blitz-VPC.</p><p><strong>Subnet Name:</strong> Toy-Blitz-DB-Private-Subnet-2</p><p><strong>Availability Zone:</strong> US East (N. Virginia)/ us-east-1a.</p><p><strong>IPv4 VPC CIDR block:</strong> 10.0.0.0/16</p><p><strong>IPv4 subnet CIDR block:</strong> 10.0.64.0/24</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*CSCwLO3z86-vof6HkTAvHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*tCdGQlLer0gawsMOTuBKvA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*SdRMSOLBAtWlsyycUJ486A.png" /></figure><h3>Private Route Table</h3><p><strong>Name:</strong> Toy-Blitz-DB-Private-Route-Table</p><p><strong>VPC:</strong> Toy-Blitz-VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*I2ttHfhp0gTdlpGbi7IZ7Q.png" /></figure><p>Associate your Private Subnets to the Private Route Table.</p><p>In Route Table, select <strong>Toy-Blitz-DB-Private-Route-Table and</strong> select<strong> subnet associations tab t</strong>hen click on<strong> edit subnet associations under explicit associations.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*G875i4GX9-cL72WEmTHSug.png" /></figure><p>Select <strong>Toy-Blitz-DB-Private-Subnet1</strong> &amp; <strong>Toy-Blitz-DB-Private-Subnet2.</strong></p><p>Click <strong>save association.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3KYyODbGXRsEJhFfPVZQVg.png" /></figure><h3>Database Security Group</h3><p>Create a Database Security Group and allow port 3306 inbound for mysql.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ovz_sC1yFxP5t3iPspZTOQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xu6fIzTWNph30mmdN8sotA.png" /></figure><h3>MySQL DatabaseType RDS</h3><p>Click<strong> create database.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*_RXqE-ks-nVgsRlkbmI61w.png" /></figure><ol><li>Standard create.</li><li>MySQL.</li><li>Free Tier.</li></ol><p><strong>DB instance identifier: </strong>database-1.</p><p><strong>Master username</strong>: admin.</p><p><strong>Self managed.</strong></p><p><strong>Master password</strong>: 12345678 (For demonstration purposes only you would created a more secure password in production.)</p><p><strong>Instance configuration: </strong>db.t3.micro.</p><p><strong>Storage:</strong> General Purpose SSD, 20 GIB.</p><p>Connectivity:</p><ol><li>Do not connect to an EC2 compute resource.</li><li>VPC: Toy-Blitz-VPC.</li><li><strong>Public Access:</strong> No</li><li>Existing VPC security groups: Toy-Blitz-SG</li><li><strong>Availability Zone:</strong> us-east-1a</li></ol><p>Create Database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*xp7uJUOC0NNaX0TfsEYQJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*BQDkBUiJFHimseZ8o8dRZg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*rRthNYnhiFoeqQTbn4smKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*ELPoW3A1hf1Q-t1pQArgZg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*s8hvBWqFJ7lNvI_y3NYbsA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GjSdTg71-ipFJ3CmD2XzLA.png" /></figure><p>The database tier is successfully created.</p><p>Lets verify.</p><p>Apache:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c4Ti-jU4eVpBIsUvo0dCwQ.png" /></figure><p>Database:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*khbgdpqE53RcRhXWkvEZCg.png" /></figure><h3>References:</h3><p><a href="https://docs.aws.amazon.com/">https://docs.aws.amazon.com/</a></p><p>Follow me on Medium for more cloud blogs and add me on LinkedIn.</p><p>LinkedIn: <a href="https://www.linkedin.com/in/babatundeaborisade/">https://www.linkedin.com/in/babatundeaborisade/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f9357e7774a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Networking & Wordpress Deployment!]]></title>
            <link>https://medium.com/@babatunde.aborisade1/docker-networking-wordpress-deployment-29b38155cc05?source=rss-a5a8b319b1ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/29b38155cc05</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker-swarm]]></category>
            <dc:creator><![CDATA[Babatunde Aborisade]]></dc:creator>
            <pubDate>Sat, 23 Mar 2024 23:17:12 GMT</pubDate>
            <atom:updated>2024-03-25T15:20:35.623Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*6GIyitNo_4oYVS9ulRJxcA.jpeg" /></figure><p>If you want to put your containerized applications on a network, Docker Networks have you covered. Ensuring the application is highly available is critical to better availability and fault tolerance. In this tutorial, we will create a docker swarm, a frontend network, and a backend network for our applications.</p><h3>Key Terms to remember:</h3><p><strong>Docker: </strong>A set of platform as a service products that use OS-level virtualization to deliver software in packages called containers.</p><p><strong>Docker Networks:</strong> Enables a user to link a Docker container to as many networks</p><p><strong>Docker Swarm: </strong>A<strong> </strong>container orchestration tool for clustering and scheduling Docker containers.</p><p><strong>Container:</strong> A standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.</p><p><strong>Linux:</strong> A family of open-source unix-like operating systems based on the Linux kernel.</p><p><strong>Visual Studio Code: </strong>A<strong> </strong>source-code editor developed by Microsoft for Windows, Linux and macOS.</p><p><strong>EC2: </strong>Amazon Elastic Compute Cloud is a web service that provides secure, resizable compute capacity in the cloud.</p><p><strong>Ubuntu:</strong> A Linux distribution based on Debian and composed mostly of free and open-source software.</p><p><strong>Bash:</strong> A Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell.</p><p><strong>Hostname:</strong> The name of the hosted Docker Nodes.</p><p><strong>Docker Hub:</strong> Acontainer registry built for developers and open source contributors to find, use, and share their container images.</p><p><strong>Replicas: </strong>Multiple Docker Nodes.</p><p><strong>MySQL: </strong>An open-source relational database management system.</p><p><strong>Wordpress: </strong>A web content management system.</p><h3>Docker Commands:</h3><p><strong>Docker Run: </strong>Used to create and start a Docker container based on a specified Docker Image.</p><p><strong>Docker Version: </strong>The version of Docker installed on your System.</p><p><strong>Docker Images:</strong> Lists the Docker images that are currently on your system.</p><p><strong>Docker PS: </strong>Used to list the current running Docker containers.</p><p><strong>Docker Pull: </strong>Downloads Docker images from the internet.</p><p><strong>Docker Push: </strong>A<strong> </strong>command that is used to push or share a local Docker image or a repository to a repository.</p><p><strong>Docker Start: </strong>Used to start any stopped container.</p><p><strong>Docker Container ls:</strong> Lists the docker containers.</p><p><strong>Docker Swarm Init:</strong> Starts the Docker Swarm.</p><p><strong>Docker Swam Join:</strong> Joins the manager(leader) node to the worker nodes.</p><p><strong>Docker Service Create:</strong> Creates the Docker service.</p><p><strong>Docker Node ls: </strong>Lists the Docker Nodes.</p><p><strong>Docker Service ls</strong>: Lists all Docker services.</p><p><strong>Docker Service Scale: </strong>Adds or removes Docker Replicas.</p><h3>Setting up Docker</h3><p>First, we need to set it up to use Docker. In this tutorial, we will use an EC2’s named <strong>BA-Docker-Node-1, BA-Docker-Node-2, and BA-Docker-Node-3 </strong>to host our Docker environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5sjxfGHYo0ascuHsxBUKYQ.png" /></figure><p><strong>Keypair:</strong> DockerKeyPair.pem</p><p><strong>Security Group: </strong>DockerDemoSG</p><p>Now, let’s open Visual Studio Code.</p><p>You must open a new folder, log in as the root user, go to your <strong>.ssh</strong> folder, and create a config file.</p><p>Path:</p><pre>C:\Users\Babor\.ssh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*j_gL06QKvXrCshHp.png" /></figure><p>Open the config file in Visual Studio Code and type this information:</p><pre># Docker EC2 1<br>Host Manager<br>#IPV4 Address will change every time.<br>HostName  34.203.237.176<br>User ubuntu<br>IdentityFile C:\Users\Babor\Documents\AWS\LevelUpInTech\Docker\DockerKeyPair.pem<br><br># Docker EC2 2<br><br>Host WorkerNode1<br>#IPV4 Address will change every time.<br>HostName  54.197.175.222<br>User ubuntu<br>IdentityFile C:\Users\Babor\Documents\AWS\LevelUpInTech\Docker\DockerKeyPair.pem<br><br># Docker EC2 3<br><br>Host WorkerNode2<br>#IPV4 Address will change every time.<br>HostName 54.237.222.199<br>User ubuntu<br>IdentityFile C:\Users\Babor\Documents\AWS\LevelUpInTech\Docker\DockerKeyPair.pem</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FT92WLXrY__zhdM1Lt-8OA.png" /></figure><p>This allows our Docker file to communicate with our EC2 instances. (Note: your public IP address will change each time you stop or shut down your EC2, so you must update your config file every time.)</p><p>Create a dockerfile and name it <strong>dockerswarm</strong>.</p><p><strong>New File -&gt; Text File -&gt; Select a language-&gt;Docker File.</strong></p><p>Open up the command terminal in Visual Studio Code and SSH into <strong>all</strong> 3 of the EC2&#39;s.</p><h3>SSH</h3><p>In order for us to interact with the EC2 instances we need to SSH into them.</p><p><strong>SSH:</strong></p><pre>ssh Manager<br>ssh WorkerNode1<br>ssh WorkerNode2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WIY9u1j2pSnDBq393d7thA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*egLZ0BxaBhTyqPpPjKkw1A.png" /></figure><p>For us to run docker commands, we need to grant permissions using this command:</p><pre>sudo chmod 666 /var/run/docker.sock</pre><h3>Installing Docker</h3><p>Next, we need to install Docker into each instance with this command:</p><pre>curl -fsSL https://get.docker.com -o get-docker.sh <br>sh get-docker.sh</pre><p>To verify the version of Docker type <strong>docker version.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cHpRtmtw8isVXMaSCK3cVw.png" /></figure><p>In order to check the active state of docker we need to run the <strong>status</strong> command.</p><pre>sudo systemctl status docker</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uab14I7QuPBTSaYJvBMmqw.png" /></figure><p>Press <strong>q to </strong>exit.</p><h3>Hostname</h3><p>First we need to identify which host is the master node, which is the <strong>Manager </strong>and the worker nodes are <strong>WorkerNode1</strong> &amp;<strong> WorkerNode2. </strong>The master node managers the clusters, the worker nodes executes them.</p><pre>sudo hostnamectl set-hostname master<br>sudo hostnamectl set-hostname worker1<br>sudo hostnamectl set-hostname worker2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WFvYXRuW0FyGtFO8cnwj_g.png" /></figure><p>Let’s verify.</p><pre>hostnamectl</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IuV-8ke_BdRTM5sByfwdqw.png" /></figure><p>The host names were successfully changed.</p><h3>Creating A Swarm</h3><p><strong>Objective 1: </strong>Deploy a 3 node Docker Swarm cluster.</p><p>To create a docker swarm you need to initialize the master node also you have to use your master nodes private IP address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ecMH9wxf2D9iTL-l0CTLdw.png" /></figure><pre>docker swarm init --advertise-addr 172.31.36.179</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*Rst7Rs6VqhsH9AGH4u_Cyw.png" /></figure><pre>docker swarm join --token SWMTKN-1-64mval5iw3v113jt4h9z8pn3tz4905vjkh3vo9ef93949uymzn-7ihig8nzvimlaax70dxmnprxm 172.31.36.179:2377</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0tCr5uMpd8YVETOLCwLN8g.png" /></figure><p>The token allows the other Nodes to join the swarm.</p><h3>Node Status</h3><p>Verify by using <strong>docker node ls:</strong></p><pre>docker node ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*j3JSLxA2C2nCPgYswdSelg.png" /></figure><p>The worker nodes are active and attached to the master node completing the swarm.</p><h3>Frontend and Backend Networks</h3><p><strong>Objective 2:</strong> Create 2 networks. One for frontend and another for backend.</p><p>In order to create a docker network you need to use <strong>docker network create.</strong></p><pre>#Frontend <br><br>docker network create --driver overlay ba-frontend_network<br><br>#Backend <br>docker network create --attachable --driver overlay ba-backend_network</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*x3tiu10bWOVEH3g4JhIC9A.png" /></figure><h3>MySQL</h3><p><strong>Objective 3:</strong> Create a MySQL service.</p><p>We will be pulling the <strong>MySQL image </strong>from Dockerhub.com</p><pre> docker pull mysql </pre><p>Use docker images to verify MySQL is downloaded.</p><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*jtfc0tT3atF82HvKvZiM_w.png" /></figure><h3>Creating a Container</h3><p>Lets create a container for our mysql image.</p><pre>docker run -t --name ba-mysql-container -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -d mysql:8.0.36-debian</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r01nP_6DnyOKQK7R5rfGRw.png" /></figure><p>The mysql container was created successfully.</p><ol><li>associated with the backend network.</li><li>Only 1 replica.</li><li>Create a volume using <strong>docker volume.</strong></li><li>Make the database service resilient and its data persistent across container restarts, use Docker Volumes.</li></ol><pre>docker volume create ba-mysql</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*jh-xOy6fePU4aDsqEqaOZA.png" /></figure><pre>docker service create --network ba-backend_network --replicas 1 -p 8080:80 -mount type=volume, source=ba-mysql-data, target=var/www/html mysql:8.0.36-debian</pre><p>Now when you create a container you can reference the volume.</p><p><strong>Objective 4:</strong> Create the Wordpress service.</p><p>Run a <strong>docker pull .</strong></p><pre>docker pull wordpress</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*GgVpscuRJTUn_5rWS1QpVw.png" /></figure><ol><li>Associated with the frontend network</li><li>Should use port 80</li><li>Accessible from the browser</li><li>3 replicas</li><li>Associated with the MySQL service</li></ol><pre>docker service create --network ba-frontend_network --replicas 3 -p 8080:80 -mount type=volume, source=wordpress-data, target=var/www/html wordpress:6.4.3-php8.1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QivSbgX_YQuqya1KrmvmPg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PjUZRKKh3rmuNk4JkLrxGw.png" /></figure><p>Paste your Public IPv4 address in the browser to verify.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gu_3rW32rtArUVFpqCobKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V7frWyB5mrFUmOFQCznIGg.png" /></figure><p>Success! We are able to view our Wordpress site!</p><h3>Conclusion:</h3><p>Utilizing Docker Networks allows us to establish individual front-end and back-end networks for our MySQL database and WordPress site. This gives us a more secure and efficient environment while maintaining a seamless computing experience.</p><p>Follow me on Medium for more cloud blogs and add me on LinkedIn.</p><p>LinkedIn: <a href="https://www.linkedin.com/in/babatundeaborisade/">https://www.linkedin.com/in/babatundeaborisade/</a></p><h3>References:</h3><ul><li><a href="https://hub.docker.com/">Docker Hub Container Image Library | App Containerization</a></li><li><a href="https://docs.docker.com/"></a></li></ul><h3>Errors/Fixes:</h3><ol><li>docker run — name ba-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag<br>Unable to find image ‘mysql:tag’ locally<br>docker: Error response from daemon: manifest for mysql:tag not found: manifest unknown: manifest unknown.<br>See ‘docker run — help’.</li><li><strong>Remove the tag at the end of mysql.</strong></li></ol><p>3. docker run — name ba-mysql-container-e MYSQL_ROOT_PASSWORD=root -p 3333:3306 -d mysql<br>docker: invalid reference format: repository name (library/MYSQL_ROOT_PASSWORD=root) must be lowercase.<br>See ‘docker run — help’.</p><p><strong>Needed to put a space after -e.</strong></p><p>4. docker run — name ba-mysql-container -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -d mysql<br>3d701aec3c839fc28b25309d14858685ac2d0aeebef493eef2467e0f539c753f<br>docker: Error response from daemon: failed to write unhaltered resolv.conf file content when setting up dns for sandbox 3dc57d976a4df3358269ea618cc72d7d229a188de89c98acb2a3c23daedabbdf: write /var/lib/docker/containers/3d701aec3c839fc28b25309d14858685ac2d0aeebef493eef2467e0f539c753f/resolv.conf: no space left on device.</p><p>R<strong>an out of space have to run docker system prune -a to clear more space.</strong></p><p>5. Command ‘mysql’ not found, but can be installed with:<strong> sudo apt install mysql-client-core-8.0 # version 8.0.35–0ubuntu0.22.04.1, or<br>sudo apt install mariadb-client-core-10.6 # version 1:10.6.12–0ubuntu0.22.04.1</strong></p><p>6. sudo apt install mysql-client-core-8.0 <br>Reading package lists… Done<br>Building dependency tree… Done<br>Reading state information… Done<br>The following NEW packages will be installed:<br> mysql-client-core-8.0<br>0 upgraded, 1 newly installed, 0 to remove and 15 not upgraded.<br>Need to get 2692 kB of archives.<br>After this operation, 62.0 MB of additional disk space will be used.<br>E: You don’t have enough free space in /var/cache/apt/archives/.</p><p>Use <strong>sudo apt clean.</strong></p><p>7. sudo apt install mysql-client-core-8.0 <br>Reading package lists… Done<br>Building dependency tree… Done<br>Reading state information… Done<br>The following NEW packages will be installed:<br> mysql-client-core-8.0<br>0 upgraded, 1 newly installed, 0 to remove and 15 not upgraded.<br>Need to get 2692 kB of archives.<br>After this operation, 62.0 MB of additional disk space will be used.<br>Get:1 <a href="http://us-east-1.ec2.archive.ubuntu.com/ubuntu">http://us-east-1.ec2.archive.ubuntu.com/ubuntu</a> jammy-updates/main amd64 mysql-client-core-8.0 amd64 8.0.36–0ubuntu0.22.04.1 [2692 kB]<br>Fetched 2692 kB in 0s (18.2 MB/s)<br>Selecting previously unselected package mysql-client-core-8.0.<br>(Reading database … 137569 files and directories currently installed.)<br>Preparing to unpack …/mysql-client-core-8.0_8.0.36–0ubuntu0.22.04.1_amd64.deb …<br>Unpacking mysql-client-core-8.0 (8.0.36–0ubuntu0.22.04.1) …<br>dpkg: error processing archive /var/cache/apt/archives/mysql-client-core-8.0_8.0.36–0ubuntu0.22.04.1_amd64.deb ( — unpack):<br> cannot copy extracted data for ‘./usr/bin/mysqlpump’ to ‘/usr/bin/mysqlpump.dpkg-new’: failed to write (No space left on device)<br>No apport report written because the error message indicates a disk full error<br> dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)<br>Errors were encountered while processing:<br> /var/cache/apt/archives/mysql-client-core-8.0_8.0.36–0ubuntu0.22.04.1_amd64.deb<br>E: Sub-process /usr/bin/dpkg returned an error code (1)</p><p>Not enough space use <strong>sudo apt clean and sudo apt remove.</strong></p><p>8. Reading package lists… Error!<br>E: Write error — write (28: No space left on device)<br>E: Write error — write (28: No space left on device)<br>E: The package lists or status file could not be parsed or opened.</p><p>Not enough space use <strong>sudo apt clean and sudo apt remove. Or use docker system prune (Use with caution it will delete a lot of files)</strong></p><p>9. Error response from daemon: This node is already part of a swarm. Use “docker swarm leave” to leave this swarm and join another one.<strong> Leave the swarm using docker swarm leave</strong>.</p><p>10. To get your docker swarm token again use<strong> docker swarm join-token worker.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29b38155cc05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Scalable & Secure Web Hosting With Terraform!]]></title>
            <link>https://medium.com/@babatunde.aborisade1/creating-scalable-and-secure-web-hosting-with-terraform-50f7cf5b1f50?source=rss-a5a8b319b1ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/50f7cf5b1f50</guid>
            <category><![CDATA[dynamodb]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[autoscaling]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Babatunde Aborisade]]></dc:creator>
            <pubDate>Sat, 23 Mar 2024 18:15:33 GMT</pubDate>
            <atom:updated>2024-03-23T19:30:16.176Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*JETPeLXidaqOMPOgEnT3NQ.png" /></figure><p>Autoscaling groups are crucial for managing applications with fluctuating traffic. In this project, we will create an Auto-Scaling Group for our EC2 Instances, a Security Group, and an S3 Backend for our Apache Webserver using Terraform, providing a scalable, secure, and reliable web hosting solution.</p><h3>Key Terms To Remember:</h3><p><strong>Terraform:</strong> An<strong> </strong>IAC tool, used primarily by DevOps teams to automate various infrastructure tasks.</p><p><strong>Infrastructure as Code(IaC): </strong>The process of managing and provisioning computer data center resources through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools.</p><p><strong>.tf: </strong>Code in the Terraform language is stored in plain text files with the . tf file extension.</p><p><strong>CI/CD: </strong>The combined practices of continuous integration and continuous delivery or, less often, continuous deployment.</p><p><strong>Provider: </strong>A plugin that enables interaction with an API. This includes Cloud providers and Software-as-a-service providers.</p><p><strong>EC2: </strong>Amazon Elastic Compute Cloud is a web service that provides secure, resizable compute capacity in the cloud.</p><p><strong>AMI: </strong>A<strong> </strong>special type of virtual appliance used to create a virtual machine within the Amazon Elastic Compute Cloud. It serves as the basic unit of deployment for services delivered using EC2.</p><p><strong>Subnet: </strong>The practice of dividing a network into two or more networks.</p><p><strong>Security Groups: </strong>Controls the traffic that is allowed to reach and leave the resources that it is associated with.</p><p><strong>Key Pair: </strong>A<strong> </strong>public key that is used to encrypt data and a private key that is used to decrypt data.</p><p><strong>VPC: </strong>A virtual network that closely resembles a traditional network that you’d operate in your own data center.</p><p><strong>Bootstrap: </strong>A<strong> </strong>tool in the AWS CDK command-line interface responsible for populating a given environment (that is, a combination of AWS account and region) with resources required by the CDK to perform deployments into that environment.</p><p><strong>Ubuntu: </strong>An<strong> </strong>operating system designed and engineered as a backbone for the internet.</p><p><strong>Autoscaling Group: </strong>A<strong> </strong>collection of EC2 instances that are treated as a logical grouping for the purposes of automatic scaling and management.</p><p><strong>S3 Bucket:</strong> An object storage service.</p><p><strong>SSH: </strong>Secure Shell or Secure Socket Shell, is a network protocol that gives users, particularly system administrators, a secure way to access a computer over an unsecured network.</p><p><strong>IP Address: </strong>a unique string of characters that identifies each computer using the Internet Protocol to communicate over a network.</p><p><strong>Variables: </strong>Used to pass certain values from outside of the configuration or module.</p><p><strong>DynamoDB:</strong> A fully managed, serverless, NoSQL database built for high-performance apps. DynamoDB features built-in security, continuous backups, automated multi-region replication, in-memory caching, and data import/export tools.</p><p><strong>Module: </strong>A<strong> </strong>set of Terraform configuration files in a single directory.</p><p><strong>User Data: </strong>The commands/data you can provide to an instance at launch time. You can use instance user data to customize your instances. When you launch an instance, you can store parameters or scripts as<strong> </strong>user data.</p><p><strong>Cloud 9: </strong>A<strong> </strong>cloud-based IDE that lets you code with a browser. It includes a code editor, debugger, and terminal, and comes with essential tools for popular programming languages like Python and JavaScript.</p><h3>Terraform Commands:</h3><p><strong>terraform init: </strong>Initializes a working directory and downloads the necessary provider plugins and modules and setting up the backend for storing your infrastructure’s state.</p><p><strong>terraform fmt: </strong>Used to rewrite Terraform configuration files to a canonical format and style.</p><p><strong>terraform validate: </strong>Validates the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc.</p><p><strong>terraform plan: </strong>Creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure.</p><p><strong>terraform apply: </strong>Executes the actions proposed in a terraform plan . It is used to deploy your infrastructure.</p><p><strong>terraform destroy: </strong>Terminates resources defined in your Terraform configuration.</p><h3>Things to know before starting:</h3><ol><li>You will frequently use these Terraform commands when testing your code.</li><li>It is important to test your code as you go so you can make changes and identify errors early on and avoid spending too much time backtracking.</li><li>Use the offical documentation from <a href="https://developer.hashicorp.com/terraform/docs">https://developer.hashicorp.com/terraform/docs</a> &amp; <a href="https://registry.terraform.io/">https://registry.terraform.io/</a> to reference your code.</li></ol><h3>Module</h3><p>Let’s get started; we will need to choose an <strong>IDE</strong> in order to use Terraform; for this tutorial, I will be using <strong>AWS Cloud 9</strong>.</p><p>Creating a<strong> module </strong>helps keep all of our terraform files together. We are naming our module <strong>ba-module.</strong></p><pre>mkdir ba-module<br></pre><p><strong>CD</strong> into your module and create multiple files and name them <strong>main.tf, provider.tf, asg.tf, s3backend.tf, sg.tf, and apache.sh </strong>this will be the files we will be putting all of our code in.</p><pre>touch main.tf, provider.tf, asg.tf, s3backend.tf, sg.tf, apache.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*DaHgDNDU-wHlPkcdbqEVnA.png" /></figure><h3>AWS Provider</h3><p>We need to identify our <strong>provider</strong>, which will be <strong>AWS</strong>. This will let Terraform know that we will be using AWS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/0*PuwyO5UbQiOGRaKK.png" /></figure><p><strong>AWS Provider Code:</strong></p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 5.0&quot;<br>    }<br>  }<br>}</pre><p><strong>Code Breakdown:</strong></p><ol><li>The <strong>required provider’s </strong>tag tells Terraform which providers we will be using.</li><li>The <strong>region</strong> tag tells the location where the code is.</li><li><strong>Version</strong> is the current version of the terraform application.</li></ol><h3>Terraform Init</h3><p>Now that we have selected our provider run the command <strong>terraform init. </strong>Terraform init allows Terraform to run its program, allowing us to deploy our code.</p><pre>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*Ybb_cZkxqWDok99CDEtZVA.png" /></figure><h3>Autoscaling Group</h3><p><strong>Objective 1:</strong> Launch an Auto Scaling group that spans 2 subnets in your default vpc.</p><pre><br># Launch template<br><br>resource &quot;aws_launch_template&quot; &quot;ba-asg-launch-template&quot; {<br>  name_prefix   = &quot;ba-asg-ec2&quot;<br>  image_id      = &quot;ami-07d9b9ddc6cd8dd30&quot;<br>  instance_type = &quot;t2.micro&quot;<br>  key_name      = &quot;BA_KeyPair&quot;<br><br>  vpc_security_group_ids = [aws_security_group.ba-sg.id] # Associate security group to instances<br>}<br><br># auto-scaling-group<br><br>resource &quot;aws_autoscaling_group&quot; &quot;ba-asg&quot; {<br>  name                = &quot;ba-autoscaling-group&quot;<br>  vpc_zone_identifier = [&quot;subnet-0ce7cc7c5e0dd2f3f&quot;, &quot;subnet-05c016e9f032e0f14&quot;]<br>  min_size            = 2<br>  max_size            = 5<br>  desired_capacity    = 2<br><br>  launch_template {<br>    id      = aws_launch_template.ba-asg-launch-template.id<br>    version = &quot;$Latest&quot;<br>  }<br><br><br>}<br><br>#BA</pre><p><strong>Code Breakdown:</strong></p><ol><li><strong>Launch Template: </strong>Specifies configurations for launching EC2 instances.</li><li><strong>Image_id:</strong> References the AMI going to be used for the EC2 instance.</li><li><strong>Instance_type:</strong> Defines the type of EC2 instance.</li><li><strong>Auto Scaling Group:</strong> The name of the auto scaling group.</li><li><strong>VPC_zone_identifier: </strong>identifiying the subnets in the VPC.</li><li><strong>Min_size:</strong> Minimun of EC2 instances.</li><li><strong>Max_size:</strong> Maximun number of EC2 instances.</li><li><strong>$Latest:</strong> Curent version of the launch template.</li></ol><p>After running <strong>terraform validate, terraform fmt and terraform apply</strong> our autoscaling group and launch template is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*lf9Uta910wrq8CdmmBdxfQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YV3PBJ1-z-bIX6Zk0yUC6w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E7kKelFUwClVcdr7hjf-NA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g69Z7uSzVwUzHrn28clijw.png" /></figure><h3>Security Group</h3><p><strong>Objective 2:</strong> Create a security group that allows traffic from the internet and associate it with the Auto Scaling group instances.</p><pre># Security Group<br><br>resource &quot;aws_security_group&quot; &quot;ba-sg&quot; {<br>  name        = &quot;ba-security-group&quot;<br>  description = &quot;Allow  inbound traffic and all outbound traffic&quot;<br>  vpc_id      = &quot;vpc-05c4f27c6e9976755&quot;<br><br>  tags = {<br>    Name = &quot;ba-sg&quot;<br>  }<br>}<br><br>#Ingress HTTPS<br>resource &quot;aws_security_group_rule&quot; &quot;ba-allow_inbound_443&quot; {<br>  security_group_id = aws_security_group.ba-sg.id<br>  type              = &quot;ingress&quot;<br>  from_port         = 443<br>  to_port           = 443<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br><br># Ingress Port 80<br>resource &quot;aws_security_group_rule&quot; &quot;ba-allowiInbound_80&quot; {<br>  security_group_id = aws_security_group.ba-sg.id<br>  type              = &quot;ingress&quot;<br>  from_port         = 80<br>  to_port           = 80<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br><br># Ingress SSH<br>resource &quot;aws_security_group_rule&quot; &quot;ba-allowiInbound_SSH&quot; {<br>  security_group_id = aws_security_group.ba-sg.id<br>  type              = &quot;ingress&quot;<br>  from_port         = 22<br>  to_port           = 22<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br><br>#Egress Allow <br><br>resource &quot;aws_security_group_rule&quot; &quot;ba-allow_outbound&quot; {<br>  security_group_id = aws_security_group.ba-sg.id<br>  type              = &quot;egress&quot;<br>  from_port         = 0<br>  to_port           = 0<br>  protocol          = &quot;-1&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br><br>}<br></pre><p><strong>Code Breakdown:</strong></p><ol><li><strong>Seecurity Group:</strong> Allows inbound and outbound traffic.</li><li><strong>Ingress HTTPS</strong>: Allows inbound traffic to Port 443.</li><li><strong>Ingress SSH:</strong> Allows inbound traffic to Port 22.</li><li><strong>Ingress 80:</strong> Allows inbound traffic for Port 80.</li><li><strong>Egress: </strong>Allows all outbound traffic from the internet.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*POi5SZ31h8VvfjnkXZdiIA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ry75FLhMpV88BfEoE-BsjQ.png" /></figure><p>After running <strong>terraform validate, terraform fmt and terraform apply</strong> our security group was with inbound and outbound rules was created.</p><h3>User Data</h3><p><strong>Objective 3:</strong> Include a script in your user data to launch an apache webserver. The Auto Scaling group should have a min of 2 and max of 5.</p><pre> # Apache user data <br>  user_data = base64encode(&lt;&lt;EOF<br>            #!/bin/bash<br>            sudo apt-get update -y<br>            sudo apt install -y apache2<br>            systemctl start apache2<br>            systemctl enable apache2<br>            EOF<br>  )<br><br><br># auto-scaling-group<br><br>resource &quot;aws_autoscaling_group&quot; &quot;ba-asg&quot; {<br>  name                = &quot;ba-autoscaling-group&quot;<br>  vpc_zone_identifier = [&quot;subnet-0ce7cc7c5e0dd2f3f&quot;, &quot;subnet-05c016e9f032e0f14&quot;]<br>  min_size            = 2<br>  max_size            = 5<br>  desired_capacity    = 2<br>}</pre><p><strong>Code Breakdown:</strong></p><ol><li><strong>User_Data: </strong>The script used to install Apache Webserver.</li><li><strong>Autoscaling Group:</strong> Defines the Autoscaling Group being created.</li><li><strong>VPC_Zone_Identifier:</strong> Lists the subnets that will be launched.</li><li><strong>Min_Size:</strong> The minimum number of intances in the Autoscaling Group.</li><li><strong>Max_Size:</strong> The maximum number of intances in the Autoscaling Group.</li><li><strong>Desired_Capactity</strong>: The desired number of intances in the Autoscaling Group.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hRRCrtddJHTg3sqbb4cmqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OgInqWD0j1c_ccGyUlqyZQ.png" /></figure><h3><strong>Public IP Addresses</strong></h3><p><strong>Objective 4: </strong>To verify everything is working check the public ip addresses of the two instances. Manually terminate one of the instances to verify that another one spins up to meet the minimum requirement of 2 instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n66-pcKSXJ760b3Wkn50Nw.png" /></figure><p>Copy the <strong>public IPV4 Address</strong> and paste it into your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mlQZGGsw-WlN0blu5Dcfww.png" /></figure><p>Now we are going to delete a EC2 Instance to confirm our Auto-Scaling Group will create another one to replace it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7fxi5thjG4PVcVxW2kib0g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QVM5X869jaU6dL7u4trMxQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FcxwraABNpUBjrx16_SOHw.png" /></figure><p><strong>EC2–3 Instance</strong> was created successfully.</p><h3>S3 Bucket</h3><p><strong>Objective 5: </strong>Create an S3 bucket and set it as your remote backend.</p><pre>#s3 bucket backend<br><br>resource &quot;aws_s3_bucket&quot; &quot;ba-s3-backend&quot; {<br>  bucket = &quot;ba-s3-backend&quot;<br>  acl    = &quot;private&quot;<br><br>  versioning {<br>    enabled = true<br>  }<br><br>  server_side_encryption_configuration {<br>    rule {<br>      apply_server_side_encryption_by_default {<br>        sse_algorithm = &quot;AES256&quot;<br>      }<br>    }<br>  }<br><br>  tags = {<br>    Name        = &quot;ba_s3-backend&quot;<br>    Environment = &quot;Dev&quot;<br>  }<br>}<br><br># dynamodb table for backend<br><br>resource &quot;aws_dynamodb_table&quot; &quot;ba-statelock&quot; {<br>  name         = &quot;state-lock&quot;<br>  billing_mode = &quot;PAY_PER_REQUEST&quot;<br>  hash_key     = &quot;LockID&quot;<br><br>  attribute {<br>    name = &quot;LockID&quot;<br>    type = &quot;S&quot;<br>  }<br>}</pre><p><strong>Code Breakdown:</strong></p><p><strong>S3 bucket</strong> created and is set to be private with versioning enabled with <strong>server side encryption with AES256.</strong></p><p><strong>DynamoDB </strong>sets a<strong> state-lock</strong> on the data preventing any modifications and PAY_PER_REQUEST sets the price for the read and write capacity you consume.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*nMHSjzYi87Z2r3N4TXud-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/182/1*lmgqyQXM_wvQ2kK5W1s_ZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*46pN6vYOaTT5gpGG2Yz0HA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*a5ZTNg0En_qTfY_3ry1TQA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-efwuRMPtPo36_xEjU1ZQw.png" /></figure><p>The<strong> S3 Bucket backend</strong> and the <strong>DynamoDB state-lock </strong>table was created with added security.</p><p><strong>Full Code:</strong></p><pre># Launch template<br><br>resource &quot;aws_launch_template&quot; &quot;ba-asg-launch-template&quot; {<br>  name_prefix   = &quot;ba-asg-ec2&quot;<br>  image_id      = &quot;ami-07d9b9ddc6cd8dd30&quot;<br>  instance_type = &quot;t2.micro&quot;<br>  key_name      = &quot;BA_KeyPair&quot;<br><br>  vpc_security_group_ids = [aws_security_group.ba-sg.id] # Associate security group to instances<br><br>  # Apache user data <br>  user_data = base64encode(&lt;&lt;EOF<br>            #!/bin/bash<br>            sudo apt-get update -y<br>            sudo apt install -y apache2<br>            systemctl start apache2<br>            systemctl enable apache2<br>            EOF<br>  )<br>}<br><br># auto-scaling-group<br><br>resource &quot;aws_autoscaling_group&quot; &quot;ba-asg&quot; {<br>  name                = &quot;ba-autoscaling-group&quot;<br>  vpc_zone_identifier = [&quot;subnet-0ce7cc7c5e0dd2f3f&quot;, &quot;subnet-05c016e9f032e0f14&quot;]<br>  min_size            = 2<br>  max_size            = 5<br>  desired_capacity    = 2<br><br>  launch_template {<br>    id      = aws_launch_template.ba-asg-launch-template.id<br>    version = &quot;$Latest&quot;<br>  }<br><br><br>}<br><br><br># Security Group<br><br>resource &quot;aws_security_group&quot; &quot;ba-sg&quot; {<br>  name        = &quot;ba-security-group&quot;<br>  description = &quot;Allow  inbound traffic and all outbound traffic&quot;<br>  vpc_id      = &quot;vpc-05c4f27c6e9976755&quot;<br><br>  tags = {<br>    Name = &quot;ba-sg&quot;<br>  }<br>}<br><br>#Ingress Port 443 HTTPS<br>resource &quot;aws_security_group_rule&quot; &quot;ba-allow_inbound_443&quot; {<br>  security_group_id = aws_security_group.ba-sg.id<br>  type              = &quot;ingress&quot;<br>  from_port         = 443<br>  to_port           = 443<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br><br># Ingress Port 80 HTTP<br>resource &quot;aws_security_group_rule&quot; &quot;ba-allowiInbound_80&quot; {<br>  security_group_id = aws_security_group.ba-sg.id<br>  type              = &quot;ingress&quot;<br>  from_port         = 80<br>  to_port           = 80<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br><br># Ingress SSH<br>resource &quot;aws_security_group_rule&quot; &quot;ba-allow_inbound_SSH&quot; {<br>  security_group_id = aws_security_group.ba-sg.id<br>  type              = &quot;ingress&quot;<br>  from_port         = 22<br>  to_port           = 22<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br><br>#Egress Allow <br><br>resource &quot;aws_security_group_rule&quot; &quot;ba-allow_outbound&quot; {<br>  security_group_id = aws_security_group.ba-sg.id<br>  type              = &quot;egress&quot;<br>  from_port         = 0<br>  to_port           = 0<br>  protocol          = &quot;-1&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br><br>}<br><br>#s3 bucket backend<br><br>resource &quot;aws_s3_bucket&quot; &quot;ba-s3-backend&quot; {<br>  bucket = &quot;ba-s3-backend&quot;<br>  acl    = &quot;private&quot;<br><br>  versioning {<br>    enabled = true<br>  }<br><br>  server_side_encryption_configuration {<br>    rule {<br>      apply_server_side_encryption_by_default {<br>        sse_algorithm = &quot;AES256&quot;<br>      }<br>    }<br>  }<br><br>  tags = {<br>    Name        = &quot;ba_s3-backend&quot;<br>    Environment = &quot;Dev&quot;<br>  }<br>}<br><br><br><br># dynamodb table for backend<br><br>resource &quot;aws_dynamodb_table&quot; &quot;ba-statelock&quot; {<br>  name         = &quot;state-lock&quot;<br>  billing_mode = &quot;PAY_PER_REQUEST&quot;<br>  hash_key     = &quot;LockID&quot;<br><br>  attribute {<br>    name = &quot;LockID&quot;<br>    type = &quot;S&quot;<br>  }<br>}<br><br><br><br></pre><h3>Github</h3><p><a href="https://github.com/NBTOONS45/Terraform-BA-Projects">GitHub - NBTOONS45/Terraform-BA-Projects</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*glfBNIsYKwM0Hq23c4ZzQA.png" /></figure><h3>Conclusion:</h3><p>To ensure the safety and scalability of our web server, we implemented Autoscaling Groups to adjust the number of instances based on traffic, used Security Groups to control inbound and outbound traffic, and leveraged S3 backend with DynamoDB state locks to store server state securely. These measures enabled us to have a highly secure and scalable web server that could handle traffic fluctuations.</p><p>Follow me on Medium for more cloud blogs and add me on LinkedIn.</p><p>LinkedIn: <a href="https://www.linkedin.com/in/babatundeaborisade/">https://www.linkedin.com/in/babatundeaborisade/</a></p><h3>References:</h3><ul><li><a href="https://developer.hashicorp.com/terraform/docs?source=post_page-----138bf488ca27--------------------------------">Documentation | Terraform | HashiCorp Developer</a></li><li><a href="https://registry.terraform.io/?source=post_page-----138bf488ca27--------------------------------">Terraform Registry</a></li></ul><h3>Errors/Fixes:</h3><ol><li>terraform fmt<br>│ Error: Missing newline after argument<br>│ on main.tf line 1:<br>│ 1: resource = “aws_autoscaling_group” “ba-autoscaling-group” {<br>│ An argument definition must end with a newline.</li></ol><p><strong>Add a { after ba-auto-scaling group and a } on the next line of launch_configuration.</strong></p><p>2. Error: Reference to undeclared resource<br>│ on main.tf line 7, in resource “aws_autoscaling_group” “ba-autoscaling-group”:<br>│ 7: launch_configuration = aws_launch_configuration.ba-autoscaling-group.name<br>│ A managed resource “aws_launch_configuration” “ba-autoscaling-group” has not been declared in the root module.</p><p><strong>add a .name to ba-autoscaling-group.</strong></p><p>3. <br>│ Error: Reference to undeclared resource<br>│ on main.tf line 7, in resource “aws_autoscaling_group” “ba-autoscaling-group”:<br>│ 7: launch_configuration = aws_launch_configuration.ba-autoscaling-group.name<br>│ A managed resource “aws_launch_configuration” “ba-autoscaling-group” has not been declared in the root module.</p><p><strong>Launch configuration not defined, resouce not found, create resource for aws launch configuration.</strong></p><p>4. Error: Reference to undeclared resource<br>│ on main.tf line 7, in resource “aws_autoscaling_group” “ba-autoscaling-group”:<br>│ 7: launch_configuration = aws_launch_configuration.ba-autoscaling-group.name <br>│ A managed resource “aws_launch_configuration” “ba-autoscaling-group” has not been declared in the root module.<br><strong>Use aws_launch_template instead of aws_launch_configuration.</strong></p><p>5. Error: Unsupported block type<br>│ on main.tf line 6, in resource “aws_launch_template” “ba-asg-launch-template”:<br>│ 6: launch_template {<br>│ Blocks of type “launch_template” are not expected here.<br>│ Error: Reference to undeclared resource<br>│ on main.tf line 18, in resource “aws_autoscaling_group” “ba-autoscaling-group”:<br>│ 18: launch_configuration = aws_launch_configuration.ba-asg-launch-template.name<br>│ A managed resource “aws_launch_configuration” “ba-asg-launch-template” has not been declared in the root module.</p><p>6. <br>│ Error: Attribute redefined<br>│ on main.tf line 42, in resource “aws_vpc_security_group_ingress_rule” “ba-allow_Inbound”:<br>│ 42: cidr_ipv4 = “0.0.0.0/0”<br>│ The argument “cidr_ipv4” was already set at main.tf:38,3–12. Each argument may be set only once.</p><p><strong>Removed the second cidr_ipv4 and replaced it with cidr_blocks.</strong></p><p>7. Error: Invalid reference<br>│ on main.tf line 50, in resource “aws_vpc_security_group_egress_rule” “ba-allow_all_traffic”:<br>│ 50: security_group_id = sg-061cdc466d0603073<br>│ A reference to a resource type must be followed by at least one attribute access, specifying the resource name.</p><p><strong>Swaped the security grup id with aws_security_group.ba-sg.id</strong></p><p>8. Error: Invalid reference<br>│ on main.tf line 29, in resource “aws_security_group” “ba-sg”:<br>│ 29: vpc_id = vpc-05c4f27c6e9976755<br>│ A reference to a resource type must be followed by at least one attribute access, specifying the resource name.</p><p><strong>vpc_id = vpc-05c4f27c6e9976755 needed quotes. vpc_id = “vpc-05c4f27c6e9976755”</strong></p><p>9. Error: Unsupported argument<br>│ on main.tf line 55, in resource “aws_vpc_security_group_egress_rule” “ba-allow_outbound”:<br>│ 55: protocol = “-1” # semantically equivalent to all ports<br>│ An argument named “protocol” is not expected here.</p><p><strong>Remove protocol = “-1”</strong></p><p>10. Error: Missing required argument <br>│ on main.tf line 38, in resource “aws_vpc_security_group_ingress_rule” “ba-allow_Inbound”:<br>│ 38: resource “aws_vpc_security_group_ingress_rule” “ba-allow_Inbound” {<br>│ The argument “ip_protocol” is required, but no definition was found.<br>│ Error: Unsupported argument <br>│ on main.tf line 40, in resource “aws_vpc_security_group_ingress_rule” “ba-allow_Inbound”:<br>│ 40: type = “ingress”<br>│ An argument named “type” is not expected here.<br>│ Error: Unsupported argument<br>│ on main.tf line 43, in resource “aws_vpc_security_group_ingress_rule” “ba-allow_Inbound”:<br>│ 43: protocol = “tcp”<br>│ An argument named “protocol” is not expected here.<br>│ Error: Unsupported argument<br>│ on main.tf line 44, in resource “aws_vpc_security_group_ingress_rule” “ba-allow_Inbound”:<br>│ 44: cidr_blocks = [“0.0.0.0/0”]<br>│ An argument named “cidr_blocks” is not expected here.<br>│ Error: Missing required argument <br>│ on main.tf line 49, in resource “aws_vpc_security_group_egress_rule” “ba-allow_outbound”:<br>│ 49: resource “aws_vpc_security_group_egress_rule” “ba-allow_outbound” {<br>│ The argument “ip_protocol” is required, but no definition was found.<br>│ Error: Unsupported argument<br>│ on main.tf line 51, in resource “aws_vpc_security_group_egress_rule” “ba-allow_outbound”:<br>│ 51: type = “egress”<br>│ An argument named “type” is not expected here.<br>│ Error: Unsupported argument<br>│ on main.tf line 54, in resource “aws_vpc_security_group_egress_rule” “ba-allow_outbound”:<br>│ 54: cidr_blocks = [“0.0.0.0/0”]<br>│ An argument named “cidr_blocks” is not expected here.</p><p><strong>Add protocol “-1”</strong></p><p>11. Error: Missing required argument <br>│ on main.tf line 38, in resource “aws_vpc_security_group_ingress_rule” “ba-allow_Inbound”:<br>│ 38: resource “aws_vpc_security_group_ingress_rule” “ba-allow_Inbound” { <br>│ The argument “ip_protocol” is required, but no definition was found.<br>│ Error: Unsupported argument<br>│ on main.tf line 40, in resource “aws_vpc_security_group_ingress_rule” “ba-allow_Inbound”:<br>│ 40: type = “ingress” <br>│ An argument named “type” is not expected here.<br>│ Error: Unsupported argument<br>│ on main.tf line 43, in resource “aws_vpc_security_group_ingress_rule” “ba-allow_Inbound”:<br>│ 43: protocol = “tcp”<br>│ An argument named “protocol” is not expected here.<br>│ Error: Unsupported argument<br>│ on main.tf line 44, in resource “aws_vpc_security_group_ingress_rule” “ba-allow_Inbound”:<br>│ 44: cidr_blocks = [“0.0.0.0/0”]<br>│ An argument named “cidr_blocks” is not expected here.<br>│ Error: Missing required argument <br>│ on main.tf line 49, in resource “aws_vpc_security_group_egress_rule” “ba-allow_outbound”:<br>│ 49: resource “aws_vpc_security_group_egress_rule” “ba-allow_outbound” { <br>│ The argument “ip_protocol” is required, but no definition was found.<br>│ Error: Unsupported argument<br>│ on main.tf line 51, in resource “aws_vpc_security_group_egress_rule” “ba-allow_outbound”:<br>│ 51: type = “egress”<br>│ An argument named “type” is not expected here.<br>│ Error: Unsupported argument<br>│ on main.tf line 54, in resource “aws_vpc_security_group_egress_rule” “ba-allow_outbound”:<br>│ 54: protocol = “-1”<br>│ An argument named “protocol” is not expected here.<br>│ Error: Unsupported argument<br>│ on main.tf line 55, in resource “aws_vpc_security_group_egress_rule” “ba-allow_outbound”:<br>│ 55: cidr_blocks = [“0.0.0.0/0”]<br>│ An argument named “cidr_blocks” is not expected here.</p><p><strong>aws_vpc_security_group_ingress_rule and aws_vpc_security_group_egress_rule changed to aws_security_group_rule.</strong></p><p>12. Error: Duplicate resource “aws_security_group_rule” configuration<br>│ on main.tf line 54:<br>│ 54: resource “aws_security_group_rule” “ba-allow_Inbound” {<br>│ A aws_security_group_rule resource named “ba-allow_Inbound” was already declared at main.tf:44,1–54. Resource names must be unique per type in each module.</p><p><strong>Changed my names becaused their was a duplicate of the inbound rules.</strong></p><p>13. Error: creating EC2 Launch Template (lt-0ff017e7392a9b3a2) Version: InvalidUserData.Malformed: Invalid BASE64 encoding of user data.<br>│ status code: 400, request id: aead699b-24a8–4bbb-bffa-07702540dc29<br>│ with aws_launch_template.ba-asg-launch-template,<br>│ on main.tf line 3, in resource “aws_launch_template” “ba-asg-launch-template”:<br>│ 3: resource “aws_launch_template” “ba-asg-launch-template” {</p><p>T<strong>he user data needs to be encoded in base64.</strong></p><pre>user_data = base64encode(&lt;&lt;EOF<br>            #!/bin/bash<br>            sudo apt-get update -y<br>            sudo apt install -y apache2<br>            systemctl start apache2<br>            systemctl enable apache2<br>            EOF<br>)</pre><p>14. ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units === Authentication is required to start ‘apache2.service’. Authenticating as: Ubuntu (ubuntu) Password: polkit-agent-helper-1: pam_authenticate failed: Authentication failure</p><p>Restart your apache server. sudo systemctl restart apache2</p><p>15.<br>│ Error: Unsupported argument<br>│ on main.tf line 125, in resource “aws_dynamodb_table” “ba-statelock”:<br>│ 125: hah_key = “LockID”<br>│ An argument named “hah_key” is not expected here. Did you mean “hash_key”?</p><p><strong>Typo error changed to hash_key.</strong></p><p>16.<br>│ Error: creating S3 Bucket (ba_s3-backend): operation error S3: CreateBucket, https response error StatusCode: 400, RequestID: QMH1V24DGJNPBVZG, HostID: ufVsv5IXaTrSslu+OtaLNo4lwxvR0BGRUbCOy3w8qk++ViZV0iTlxWA+7RIfiCj7scK+VXFXRNQ=, api error InvalidBucketName: The specified bucket is not valid.<br>│ with aws_s3_bucket.ba_s3-backend,<br>│ on main.tf line 96, in resource “aws_s3_bucket” “ba_s3-backend”:<br>│ 96: resource “aws_s3_bucket” “ba_s3-backend” {</p><p><strong>The buckect name was not valid, changed the bucket name to ba-s3-backend.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50f7cf5b1f50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up A Docker Swarm!]]></title>
            <link>https://medium.com/@babatunde.aborisade1/setting-up-a-docker-swarm-6a33ff0f3e4b?source=rss-a5a8b319b1ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a33ff0f3e4b</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[container-orchestration]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Babatunde Aborisade]]></dc:creator>
            <pubDate>Wed, 20 Mar 2024 19:13:11 GMT</pubDate>
            <atom:updated>2024-03-20T20:17:05.256Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*ETnjFNzB18ql1rcuHLe4Cg.jpeg" /></figure><p>Do you need to work on your code or applications in multiple environments? Docker Swarm is the tool to use. With Docker Swarm, you can simplify the deployment, scaling, and containerization of applications across multiple Docker hosts. In this tutorial, we will create a Docker Swarm, manager and worker nodes, and replicas of the nodes.</p><h3>Key Terms to remember:</h3><p><strong>Docker: </strong>A set of platform as a service products that use OS-level virtualization to deliver software in packages called containers.</p><p><strong>Docker Swarm: </strong>A<strong> </strong>container orchestration tool for clustering and scheduling Docker containers.</p><p><strong>Container:</strong> A standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.</p><p><strong>Linux:</strong> A family of open-source unix-like operating systems based on the Linux kernel.</p><p><strong>Visual Studio Code: </strong>A<strong> </strong>source-code editor developed by Microsoft for Windows, Linux and macOS.</p><p><strong>EC2: </strong>Amazon Elastic Compute Cloud is a web service that provides secure, resizable compute capacity in the cloud.</p><p><strong>Ubuntu:</strong> A Linux distribution based on Debian and composed mostly of free and open-source software.</p><p><strong>Bash:</strong> A Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell.</p><p><strong>Hostname:</strong> The name of the hosted Docker Nodes.</p><p><strong>Docker Hub:</strong> Acontainer registry built for developers and open source contributors to find, use, and share their container images.</p><p><strong>Replicas: </strong>Multiple Docker Nodes.</p><h3>Docker Commands:</h3><p><strong>Docker Run: </strong>Used to create and start a Docker container based on a specified Docker Image.</p><p><strong>Docker Version: </strong>The version of Docker installed on your System.</p><p><strong>Docker Images:</strong> Lists the Docker images that are currently on your system.</p><p><strong>Docker PS: </strong>Used to list the current running Docker containers.</p><p><strong>Docker Pull: </strong>Downloads Docker images from the internet.</p><p><strong>Docker Push: </strong>A<strong> </strong>command that is used to push or share a local Docker image or a repository to a repository.</p><p><strong>Docker Start: </strong>Used to start any stopped container.</p><p><strong>Docker Container ls:</strong> Lists the docker containers.</p><p><strong>Docker Swarm Init:</strong> Starts the Docker Swarm.</p><p><strong>Docker Swam Join:</strong> Joins the manager(leader) node to the worker nodes.</p><p><strong>Docker Service Create:</strong> Creates the Docker service.</p><p><strong>Docker Node ls: </strong>Lists the Docker Nodes.</p><p><strong>Docker Service ls</strong>: Lists all Docker services.</p><p><strong>Docker Service Scale: </strong>Adds or removes Docker Replicas.</p><h3>Setting up Docker</h3><p>First, we need to set it up to use Docker. In this tutorial, we will use an EC2&#39;s named <strong>BA-Docker-Node-1, BA-Docker-Node-2, and BA-Docker-Node-3 </strong>to host our Docker environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5sjxfGHYo0ascuHsxBUKYQ.png" /></figure><p><strong>Keypair:</strong> DockerKeyPair.pem</p><p><strong>Security Group: </strong>DockerDemoSG</p><p>Now, let’s open Visual Studio Code.</p><p>You must open a new folder, log in as the root user, go to your <strong>.ssh</strong> folder, and create a config file.</p><p>Path:</p><pre>C:\Users\Babor\.ssh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*j_gL06QKvXrCshHp.png" /></figure><p>Open the config file in Visual Studio Code and type this information:</p><pre># Docker EC2 1</pre><pre>Host Manager</pre><pre>#IPV4 Address will change every time.</pre><pre>HostName  34.203.237.176</pre><pre>User ubuntu</pre><pre>IdentityFile C:\Users\Babor\Documents\AWS\LevelUpInTech\Docker\DockerKeyPair.pem</pre><pre># Docker EC2 2</pre><pre>Host WorkerNode1</pre><pre>#IPV4 Address will change every time.</pre><pre>HostName  54.197.175.222</pre><pre>User ubuntu</pre><pre>IdentityFile C:\Users\Babor\Documents\AWS\LevelUpInTech\Docker\DockerKeyPair.pem</pre><pre># Docker EC2 3</pre><pre>Host WorkerNode2</pre><pre>#IPV4 Address will change every time.</pre><pre>HostName 54.237.222.199</pre><pre>User ubuntu</pre><pre>IdentityFile C:\Users\Babor\Documents\AWS\LevelUpInTech\Docker\DockerKeyPair.pem</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FT92WLXrY__zhdM1Lt-8OA.png" /></figure><p>This allows our Docker file to communicate with our EC2 instances. (Note: your public IP address will change each time you stop or shut down your EC2, so you must update your config file every time.)</p><p>Create a dockerfile and name it <strong>dockerswarm</strong>.</p><p><strong>New File -&gt; Text File -&gt; Select a language-&gt;Docker File.</strong></p><p>Open up the command terminal in Visual Studio Code and SSH into <strong>all</strong> 3 of the EC2&#39;s.</p><h3>SSH</h3><p>In order for us to interact with the EC2 instances we need to SSH into them.</p><p><strong>SSH:</strong></p><pre>ssh Manager<br>ssh WorkerNode1<br>ssh WorkerNode2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WIY9u1j2pSnDBq393d7thA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*egLZ0BxaBhTyqPpPjKkw1A.png" /></figure><p>For us to run docker commands, we need to grant permissions using this command:</p><pre>sudo chmod 666 /var/run/docker.sock</pre><h3>Installing Docker</h3><p><strong>Objective 1:</strong> Installing docker on all hosts.</p><p>Next, we need to install Docker into each instance with this command:</p><pre>curl -fsSL https://get.docker.com -o get-docker.sh <br>sh get-docker.sh</pre><p>To verify the version of Docker type <strong>docker version.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cHpRtmtw8isVXMaSCK3cVw.png" /></figure><h3>Docker Active State</h3><p><strong>Objective 2: </strong>Verifying that docker is in an active state.</p><p>In order to check the active state of docker we need to run the <strong>status</strong> command.</p><pre>sudo systemctl status docker</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uab14I7QuPBTSaYJvBMmqw.png" /></figure><p>Press <strong>q to </strong>exit.</p><h3>Hostname</h3><p><strong>Objective 3:</strong> Change the hostname on each node to identify the master node and the two worker nodes.</p><p>First we need to identify which host is the master node, which is the <strong>Manager </strong>and the worker nodes are <strong>WorkerNode1</strong> &amp;<strong> WorkerNode2. </strong>The master node managers the clusters, the worker nodes executes them.</p><pre>sudo hostnamectl set-hostname master<br>sudo hostnamectl set-hostname worker1<br>sudo hostnamectl set-hostname worker2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WFvYXRuW0FyGtFO8cnwj_g.png" /></figure><p>Let’s verify.</p><pre>hostnamectl</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IuV-8ke_BdRTM5sByfwdqw.png" /></figure><p>The host names were successfully changed.</p><h3>Validating Security Groups</h3><p><strong>Objective 4:</strong> Validating the worker nodes all share the same security group as the master node.</p><p>We will be using the CLI to check the security groups, you can also use the AWS console.</p><pre>aws ec2 describe-instances --query &#39;Reservations[*].Instances[*].SecurityGroups[*]&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WR9onYdOetY8WfFTIp29_g.png" /></figure><p>All of the nodes are in the same security groups.</p><p>(Note if your security groups dont match the master node, you can change the security group in the ec2 section under the security tab in the console.)</p><h3>SSH Keys in Nodes</h3><p><strong>Objective 5: </strong>Be sure to add your ssh key to each node.</p><p>We already created our SSH keys in the inital creation phase of our EC2 instances but lets verify that they are in our nodes.</p><p>Make sure you <strong>cd </strong>into your .ssh directory.</p><pre>cd ~/.ssh</pre><p>Then use <strong>ls </strong>to view all of the keys in the node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*rTIm0L_MQJsf_vycDs018A.png" /></figure><p>To see the exact details of the autherized keys use<strong> cat</strong>.</p><pre>cat authorized_keys</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*SpmX48WsnjKHW9xzjGdTVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*EiizpRH2Fcv3E5EwqSdV2g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*OYmHmFfQ7uDylNirrtI4nQ.png" /></figure><p>All the nodes have the same SSH Keys.</p><h3>Creating Containers</h3><p><strong>Objective 6: </strong>Running the necessary containers using the CLI.</p><p>Use <strong>docker container ls </strong>to view if any containers were created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2yZhGBYHpD7uIQymp_1pzQ.png" /></figure><p>Since their are no containers let’s create some containers, first we need to <strong>pull </strong>an image we will be pulling an <strong>nginx</strong> image this time.</p><pre>docker pull nginx:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PL3jOVzTGVGefB-maM0vqA.png" /></figure><p>verify the image by using <strong>docker images.</strong></p><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*K8oeTCIeX-ECH7IPRrmEWQ.png" /></figure><p>Now create the containers.</p><pre>docker run -t -d -p 8080:80 --name BA-Nginx-Container nginx:latest </pre><p>( <strong>-d</strong> deteaches the container and <strong>-t </strong>and runs it in the background, <strong>-p </strong>maps the ports 80 to the container and port 8080 to the local host.)</p><pre># master<br><br>c1a0f184a29bc54d860747a9d89869507af8d84fe9ea88495ca881512e2ed66c<br><br># worker1<br><br>d6d4791db64acbb83209618c53ec2537fa9769d2091b5f9f71e1915010ec9627<br><br># worker2<br><br>500fc6b000059c9c0a166e8f429cfa9e399ae306bcb6fb46deb1df7895a0e3e8<br><br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1YStAhZR_r13Teoq7Casqg.png" /></figure><p>Lets verify with <strong>docker ps</strong>.</p><pre>docker ps </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lfywOkysC22hMiXghI-9jg.png" /></figure><p>The <strong>Nginx</strong> containers were successfully created.</p><p>Copy and paste the public IP address from the master node instance to verify it is running on port 8080.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S7Y3UIGssO60DegphEg21g.png" /></figure><h3>Creating A Swarm</h3><p><strong>Objective 7: </strong>Creating the Swarm using one master node and two worker nodes.</p><p>To create a docker swarm you need to initialize the master node also you have to use your master nodes <strong>private IP address.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ecMH9wxf2D9iTL-l0CTLdw.png" /></figure><pre>docker swarm init --advertise-addr 172.31.36.179</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*Rst7Rs6VqhsH9AGH4u_Cyw.png" /></figure><pre> docker swarm join --token SWMTKN-1-64mval5iw3v113jt4h9z8pn3tz4905vjkh3vo9ef93949uymzn-7ihig8nzvimlaax70dxmnprxm 172.31.36.179:2377</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0tCr5uMpd8YVETOLCwLN8g.png" /></figure><h3>Node Status</h3><p><strong>Objective 8:</strong> Show your team members the status of the docker nodes</p><p>Verify by using <strong>docker node ls:</strong></p><pre>docker node ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*j3JSLxA2C2nCPgYswdSelg.png" /></figure><p>The worker nodes are active and attached to the master node completing the swarm.</p><h3>Creating A Replica</h3><p><strong>Objective 9:</strong> Create a replica.</p><p>In order to create a replica you will have to use the master node and use <strong>docker service create.</strong></p><pre> docker service create --name nginx-replica --replicas 1 --publish published=8080,target=80 nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*ZgsYu_vrLN5ObygIehJz4A.png" /></figure><p>To check that the replica was created use<strong> docker service ls</strong>.</p><pre>docker service ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*uKZ8zDHJbyKy10TfdZRxrw.png" /></figure><p>Now let’s create 3 more using <strong>docker scale.</strong></p><pre>docker service scale nginx-replica=3</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*PviqU1CxtWUGBcHLDqWasA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*Vv_gQg8Sgk6T9dYa4va3Tw.png" /></figure><p>Success we scaled our replica from 1 to 3 within our master node!</p><p><strong>Docker Compose YAML:</strong></p><pre>version: &#39;3.8&#39;<br><br>services:<br>  manager:<br>    image: ubuntu<br>    ports:<br>      - &quot;8080:8080&quot;<br>    container_name: BA-Docker-Node-1<br>    hostname: manager<br>    volumes:<br>    - /var/run/docker.sock:/var/run/docker.sock<br><br>  worker1:<br>    image: ubuntu<br>    container_name: BA-Docker-Node-2<br>    hostname: WorkerNode1<br>    volumes: <br>    - /var/run/docker.sock:/var/run/docker.sock<br>    <br>  worker2: <br>    image: ubuntu<br>    container_name: BA-Docker-Node-3<br>    hostname: WorkerNode2<br>    volumes:<br>    - /var/run/docker.sock:/var/run/docker.sock<br><br>master:<br>    image: nginx<br>    ports:<br>      - &quot;8080:8080&quot;<br>    container_name: BA-Docker-Node-1<br>    hostname: master<br>    volumes:<br>    - /var/run/docker.sock:/var/run/docker.sock<br><br>  worker1:<br>    image: nginx<br>    container_name: BA-Docker-Node-2<br>    hostname: worker1<br>    volumes: <br>    - /var/run/docker.sock:/var/run/docker.sock<br>    <br>  worker2: <br>    image: nginx<br>    container_name: BA-Docker-Node-3<br>    hostname: worker2<br>    volumes:<br>    - /var/run/docker.sock:/var/run/docker.sock</pre><p><strong>New Host Docker Compose YAML:</strong></p><pre>version: &#39;3.8&#39;<br><br>services:<br>  master:<br>    image: nginx<br>    ports:<br>      - &quot;8080:8080&quot;<br>    container_name: BA-Docker-Node-1<br>    hostname: master<br>    volumes:<br>    - /var/run/docker.sock:/var/run/docker.sock<br><br>  worker1:<br>    image: nginx<br>    container_name: BA-Docker-Node-2<br>    hostname: worker1<br>    volumes: <br>    - /var/run/docker.sock:/var/run/docker.sock<br>    <br>  worker2: <br>    image: nginx<br>    container_name: BA-Docker-Node-3<br>    hostname: worker2<br>    volumes:<br>    - /var/run/docker.sock:/var/run/docker.sock</pre><h3>Conclusion:</h3><p>By creating a Docker Swarm, we can easily configure multiple applications in different environments. Using Swarm provides several benefits including decreased deployment time, increased productivity, and the ability to distribute workloads and achieve high availability with fault tolerance in case a replica becomes unavailable.</p><p>Follow me on Medium for more cloud blogs and add me on LinkedIn.</p><p>LinkedIn: <a href="https://www.linkedin.com/in/babatundeaborisade/">https://www.linkedin.com/in/babatundeaborisade/</a></p><h3>References:</h3><ul><li><a href="https://hub.docker.com/">Docker Hub Container Image Library | App Containerization</a></li><li><a href="https://docs.docker.com/"></a></li></ul><h3>Errors/Fixes:</h3><ol><li>permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get “<a href="http://%2Fvar%2Frun%2Fdocker.sock/v1.44/version">http://%2Fvar%2Frun%2Fdocker.sock/v1.44/version</a>&quot;: dial unix /var/run/docker.sock: connect: permission denied</li></ol><p><strong>Use this code in the command terminal:</strong></p><pre>sudo ls -l /var/run/docker.sock<br>sudo chmod 666 /var/run/docker.sock</pre><p>2. Command ‘aws’ not found, but can be installed with:<br>sudo snap install aws-cli # version 1.15.58, or<br>sudo apt install awscli # version 1.22.34–1<br>See ‘snap info aws-cli’ for additional versions.</p><p><strong>Run the install command:</strong></p><pre>sudo apt update<br>sudo apt install awscli</pre><p>3. <strong>If your not able to view your security group information in the CLI, you need to update your IAM Role permissions for the EC2 instance. AllowEC2AllAccess</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*fvmAjhKb0w8LjjYnU7llzg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*6x7cCv0Usf9f9ksWvomUKw.png" /></figure><p>4. Error response from daemon: This node is not a swarm manager. Worker nodes can’t be used to view or modify cluster state. Please run this command on a manager node or promote the current node to a manager.</p><p><strong>Only the manager(master) node can use the docker node ls command.</strong></p><p>5. docker service create — name nginx-replica — replicas 1 — publish published=8080, target=80 ngnix:latest<br>invalid argument “published=8080,” for “-p, — publish” flag: invalid field <br>See ‘docker service create — help’.</p><p>5. In case a replica is not successfully deployed and you want to remove it use <strong>docker service rm nginx-replica</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a33ff0f3e4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Compose & Jenkins!]]></title>
            <link>https://medium.com/@babatunde.aborisade1/docker-compose-jenkins-3507ad39a33e?source=rss-a5a8b319b1ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/3507ad39a33e</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Babatunde Aborisade]]></dc:creator>
            <pubDate>Tue, 19 Mar 2024 18:34:18 GMT</pubDate>
            <atom:updated>2024-03-19T18:34:18.553Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*xGMOtATQn3bV4NdMTiCxPg.jpeg" /></figure><p>Level Up Solutions needs help creating a highly robust solution for their CI/CD pipelines. We can provide this solution by using Docker and Jenkins. In this tutorial, we will create a Docker volume, attach it to a container, install Jenkins, create a user, and create a Docker Compose file for our code.</p><h3>Key Terms to remember:</h3><p><strong>Docker: </strong>A set of platform as a service products that use OS-level virtualization to deliver software in packages called containers.</p><p><strong>Container:</strong> A standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.</p><p><strong>Linux:</strong> A family of open-source unix-like operating systems based on the Linux kernel.</p><p><strong>Visual Studio Code: </strong>A<strong> </strong>source-code editor developed by Microsoft for Windows, Linux and macOS.</p><p><strong>EC2: </strong>Amazon Elastic Compute Cloud is a web service that provides secure, resizable compute capacity in the cloud.</p><p><strong>Ubuntu:</strong> A Linux distribution based on Debian and composed mostly of free and open-source software.</p><p><strong>Bash:</strong> A Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell.</p><p><strong>Docker Hub:</strong> Acontainer registry built for developers and open source contributors to find, use, and share their container images.</p><p><strong>Jenkins: </strong>An open source continuous integration/continuous delivery and deployment (CI/CD) automation software DevOps tool written in the Java programming language. It is used to implement CI/CD workflows, called pipelines.</p><h3>Docker Commands:</h3><p><strong>Docker Run: </strong>Used to create and start a Docker container based on a specified Docker Image.</p><p><strong>Docker Version: </strong>The version of Docker installed on your System.</p><p><strong>Docker Images:</strong> Lists the Docker images that are currently on your system.</p><p><strong>Docker PS: </strong>Used to list the current running Docker containers.</p><p><strong>Docker Pull: </strong>Downloads Docker images from the internet.</p><p><strong>Docker Push: </strong>A<strong> </strong>command that is used to push or share a local Docker image or a repository to a repository.</p><p><strong>Docker Start: </strong>Used to start any stopped container.</p><p><strong>Docker Login: </strong>Log in to any public or private repository for which you have credentials.</p><p><strong>Docker Volume</strong>: An independent file system entirely managed by Docker and exists as a normal file or directory on the host, where data is persisted.</p><p><strong>Docker Compose:</strong> A tool for defining and running multi-container applications.</p><h3>Setting up Docker</h3><p>In order for us to use Docker we need to set it up first. We will be using an EC2 named <strong>BADockerEC2 </strong>to host our Docker environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*LYazY7UHjztT_owr7q5bGg.png" /></figure><p>Open up the command terminal and SSH into <strong>BADockerEC2</strong></p><p>Keypair for <strong>BADockerEC2</strong>:</p><pre>ssh -i &quot;DockerKeyPair.pem&quot; ubuntu@ec2-54-210-77-166.compute-1.amazonaws.com</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CpEwv8CdpxExPEYkT8RagQ.png" /></figure><p>Next we need to install Docker into the instance with this command:</p><pre>curl -fsSL https://get.docker.com -o get-docker.sh <br>sh get-docker.sh</pre><p>To verify the version of Docker type <strong>docker version.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*ItZHgADTMYlZqx-pEKo6PQ.png" /></figure><p>Now let’s open Visual Studio Code.</p><p>You will need to open a new folder, log in as the root user, go to your <strong>.ssh</strong> folder, and create a config file.</p><p>Path:</p><pre>C:\Users\Babor\.ssh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*AZveWSz6rWHrLji7aCvy7w.png" /></figure><p>Open the config file in Visual Studio Code and type this information:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CXwOWowMi7yWlYaPtV8U5g.png" /></figure><pre># Docker EC2 <br>Host Docker<br>  #IPV4 Address will change every time.<br>   HostName  18.212.149.38<br>   User ubuntu<br>   IdentityFile C:\Users\Babor\Documents\AWS\LevelUpInTech\Docker\DockerKeyPair.pem</pre><p>This allows our Docker file to communicate with our EC2 instance. (Note: each time you stop or shut down your EC2, your Public IP Address will change, so you must update your config file every time.)</p><p>Click <strong>open the remote window </strong>button on the bottom left of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/75/1*k4m7yMkGWlwRbk8lXyis4Q.png" /></figure><p>Click on<strong> Connect to Host.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ZYc-xI-9ISItbwACFjBvw.png" /></figure><p>Click <strong>Docker.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cmMAgw_ZQ3NgwVt96cFdZA.png" /></figure><p>You will see an <strong>SSH: Docker</strong> on the bottom left, meaning you have successfully connected to your Docker EC2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*kE1hzyeUSL_CO-RKYAvWzA.png" /></figure><p>Now that we got the configurations setup lets create a new docker file.</p><h3>Creating the Docker File</h3><p><strong>New File -&gt; Text File -&gt; Select a language-&gt;Docker File.</strong></p><p>We will create a new directory in the terminal to keep our files in the same directory.</p><pre>mkdir LUIT-BA-Docker</pre><p>For us to run docker commands, we need to grant permissions using this command:</p><pre>sudo chmod 666 /var/run/docker.sock</pre><h3>Pulling an Jenkins Image from Dockerhub</h3><p><strong>Objective 1:</strong> Pull the Jenkins LTS image from Docker Hub.</p><p>Use the <strong>docker pull </strong>command.</p><pre>docker pull jenkins/jenkins:latest</pre><p>Run<strong> docker pull </strong>to check Jenkins was downloaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*cpTdg5ibbisuPRbIBsu9uQ.png" /></figure><h3>Creating a Docker Volume</h3><p><strong>Objective 2:</strong>Create a Docker volume for Jenkins to persist its data.</p><p>To create a docker volume you will use the <strong>docker volume create</strong> command:</p><pre>docker volume create ba-jenkins-data-volume</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j177n0k2m8sYnaYrmbgsTw.png" /></figure><p><strong>Objective 3:</strong> Run the container with the volume and correct port mapped to the container.</p><pre>docker run -d -p 8080:8080 -p 5000:5000 -v ba-jenkins-data-volume:/var/jenkins_home --name ba-jenkins-container jenkins/jenkins:latest</pre><p>This allows the docker container to run with a volume attached to it and set the ports 8080 to the host machine and port 5000 of the host machine to the container.<strong> -d </strong>detaches the container and runs it in the background &amp; -p assigns the port.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GIERBOqKymu8DltPP_JaTA.png" /></figure><p>Run<strong> docker ps</strong> to confirm the container was created.</p><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZbWz00bgB7pGs3iXrFvw-g.png" /></figure><h3>Admin Password</h3><p><strong>Objective 4:</strong> Retrieve the Admin password.</p><p>In order to get the admin password you need to look at the <strong>logs</strong> of the container.</p><pre>docker logs ba-jenkins-container</pre><p>Password:</p><pre>1a5bb66ebb9e481b8e1d5d0556850f71</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1CjVl45O3Y2O2QBfZQ5lFg.png" /></figure><h3>Creating A New User</h3><p><strong>Objective 5: </strong>Login and create a new user.</p><p>We need to grab our <strong>public IPV4 address </strong>from our EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*grv9xZFePYSTnpZO3AQPyg.png" /></figure><p>Paste the IP URL to your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vOzQPAjGHYZaDyhlmeZ7nQ.png" /></figure><p>Use your admin password and sign in.</p><p>Install suggested plugins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s9khIqpfI8Bh2G8YZyONVQ.png" /></figure><p>Create a user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xqQtQRyx96pPqjdLtX952g.png" /></figure><p>Click save and continue.</p><p>Jenkins instance URL:</p><pre>http://54.173.28.54:8080/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_EHeEuj5rNvUGKuAA-rWuQ.png" /></figure><p>Save and finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jd_Xvtmf_czRfz-geRzDVA.png" /></figure><p>Create a new user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*n0GWl1_oQT64Hc6TNzqLBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JldYhPTj1XYrrAYmocIY_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SugL_RLAgY31bYX0bv0wMw.png" /></figure><h3>Running A Container With A Volume</h3><p><strong>Objective 6: </strong>Launch a new Jenkins container using the same volume and verify that the data has persisted by logging in as the newly created user.</p><p>Run a new container with the<strong> volume</strong> attached.</p><pre>docker run -d -p 8080:8080 -p 5000:5000 -v ba-jenkins-data-volume:/var/jenkins_home --name ba-jenkins-container_NEW jenkins/jenkins:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BMkwmBuL4QTjf9o7Q260GA.png" /></figure><p>Paste your <strong>public IPV4 address</strong> again in your browser and log in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KHREig-GT8mSKfh5G7uECQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_f_xHJgMTP2OWAoAy3AT-w.png" /></figure><p>Success our data has persisted by logging in as the newly created user.</p><h3><strong>Docker Compose</strong></h3><p><strong>Objective 7:</strong> Create everything using Docker Compose.</p><p>Create a<strong> YAML</strong> file using the touch command.</p><pre>touch docker-compose.yml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*8h_GeOUs9JG8Ixo4TJQMhg.png" /></figure><p>Open your <strong>docker-compose yaml</strong> file and type in this script:</p><pre>version: &#39;3.8&#39;<br><br>services:<br>  jenkins:<br>    image: jenkins/jenkins:latest<br>    ports: <br>    - &quot;8080:8080&quot;<br>    - &quot;5000:5000&quot;<br>    volumes:<br>      - ba-jenkins-data-volume:/var/jenkins_home<br><br>volumes:<br>  ba-jenkins-data-volume: </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*2EgjeFCMkC1m-UTw64Z0UQ.png" /></figure><p>Run<strong> docker compose.</strong></p><pre>docker compose up -d</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*plmt6scwcuAT02zk5d2_IA.png" /></figure><p>Success our docker compose script works!</p><h3><strong>Conclusion:</strong></h3><p>Level Up Solutions has optimized its software development and deployment with Docker Compose and Jenkins. By using Docker containers and Jenkin’s CI/CD tools, productivity has improved for their operations, and using Docker Volumes has caused their data to be more persistent in case a failure were to occur, allowing them to retrieve their data and applications.</p><p>Follow me on Medium for more cloud blogs and add me on LinkedIn.</p><p>LinkedIn: <a href="https://www.linkedin.com/in/babatundeaborisade/">https://www.linkedin.com/in/babatundeaborisade/</a></p><h3>References:</h3><ul><li><a href="https://www.jenkins.io/doc/book/installing/docker/">Docker</a></li><li><a href="https://hub.docker.com/">Docker Hub Container Image Library | App Containerization</a></li><li><a href="https://docs.docker.com/"></a></li></ul><h3><strong>Errors/Fixes:</strong></h3><ol><li>docker pull jenkins<br>Using default tag: latest<br>Error response from daemon: manifest for jenkins:latest not found: manifest unknown: manifest unknown</li></ol><p><strong>Depreciated, use pull jenkins/jenkins:latest instead.</strong></p><p>2. docker-compose up <br>Command ‘docker-compose’ not found, but can be installed with:<br>sudo snap install docker # version 24.0.5, or<br>sudo apt install docker-compose # version 1.29.2–1<br>See ‘snap info docker’ for additional versions.</p><p><strong>sudo apt install docker-compose</strong></p><p>3. ERROR: <br> Can’t find a suitable configuration file in this directory or any<br> parent. Are you in the right directory?</p><p>Supported filenames: docker-compose.yml, docker-compose.yaml, compose.yml, compose.yaml</p><p><strong>Needed to change my yaml name to docker-compose.</strong></p><p>4. ERROR: In file ‘./docker-compose.yml’, service must be a mapping, not a NoneType.</p><p><strong>Needed to add a colon to my volumes section in my docker-compose.yml after data-volume.</strong></p><p>5. Traceback (most recent call last):<br> File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 700, in urlopen<br> httplib_response = self._make_request(<br> File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 395, in _make_request<br> conn.request(method, url, **httplib_request_kw)<br> File “/usr/lib/python3.10/http/client.py”, line 1283, in request<br> self._send_request(method, url, body, headers, encode_chunked)<br> File “/usr/lib/python3.10/http/client.py”, line 1329, in _send_request<br> self.endheaders(body, encode_chunked=encode_chunked)<br> File “/usr/lib/python3.10/http/client.py”, line 1278, in endheaders<br> self._send_output(message_body, encode_chunked=encode_chunked)<br> File “/usr/lib/python3.10/http/client.py”, line 1038, in _send_output<br> self.send(msg)<br> File “/usr/lib/python3.10/http/client.py”, line 976, in send<br> self.connect()<br> File “/usr/lib/python3/dist-packages/docker/transport/unixconn.py”, line 30, in connect<br> sock.connect(self.unix_socket)<br>PermissionError: [Errno 13] Permission denied</p><p>During handling of the above exception, another exception occurred:</p><p>Traceback (most recent call last):<br> File “/usr/lib/python3/dist-packages/requests/adapters.py”, line 439, in send<br> resp = conn.urlopen(<br> File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 756, in urlopen<br> retries = retries.increment(<br> File “/usr/lib/python3/dist-packages/urllib3/util/retry.py”, line 532, in increment<br> raise six.reraise(type(error), error, _stacktrace)<br> File “/usr/lib/python3/dist-packages/six.py”, line 718, in reraise<br> raise value.with_traceback(tb)<br> File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 700, in urlopen<br> httplib_response = self._make_request(<br> File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 395, in _make_request<br> conn.request(method, url, **httplib_request_kw)<br> File “/usr/lib/python3.10/http/client.py”, line 1283, in request<br> self._send_request(method, url, body, headers, encode_chunked)<br> File “/usr/lib/python3.10/http/client.py”, line 1329, in _send_request<br> self.endheaders(body, encode_chunked=encode_chunked)<br> File “/usr/lib/python3.10/http/client.py”, line 1278, in endheaders<br> self._send_output(message_body, encode_chunked=encode_chunked)<br> File “/usr/lib/python3.10/http/client.py”, line 1038, in _send_output<br> self.send(msg)<br> File “/usr/lib/python3.10/http/client.py”, line 976, in send<br> self.connect()<br> File “/usr/lib/python3/dist-packages/docker/transport/unixconn.py”, line 30, in connect<br> sock.connect(self.unix_socket)<br>urllib3.exceptions.ProtocolError: (‘Connection aborted.’, PermissionError(13, ‘Permission denied’))</p><p>During handling of the above exception, another exception occurred:</p><p>Traceback (most recent call last):<br> File “/usr/lib/python3/dist-packages/docker/api/client.py”, line 214, in _retrieve_server_version<br> return self.version(api_version=False)[“ApiVersion”]<br> File “/usr/lib/python3/dist-packages/docker/api/daemon.py”, line 181, in version<br> return self._result(self._get(url), json=True)<br> File “/usr/lib/python3/dist-packages/docker/utils/decorators.py”, line 46, in inner<br> return f(self, *args, **kwargs)<br> File “/usr/lib/python3/dist-packages/docker/api/client.py”, line 237, in _get<br> return self.get(url, **self._set_request_timeout(kwargs))<br> File “/usr/lib/python3/dist-packages/requests/sessions.py”, line 557, in get<br> return self.request(‘GET’, url, **kwargs)<br> File “/usr/lib/python3/dist-packages/requests/sessions.py”, line 544, in request<br> resp = self.send(prep, **send_kwargs)<br> File “/usr/lib/python3/dist-packages/requests/sessions.py”, line 657, in send<br> r = adapter.send(request, **kwargs)<br> File “/usr/lib/python3/dist-packages/requests/adapters.py”, line 498, in send<br> raise ConnectionError(err, request=request)<br>requests.exceptions.ConnectionError: (‘Connection aborted.’, PermissionError(13, ‘Permission denied’))</p><p>During handling of the above exception, another exception occurred:</p><p>Traceback (most recent call last):<br> File “/usr/bin/docker-compose”, line 33, in &lt;module&gt;<br> sys.exit(load_entry_point(‘docker-compose==1.29.2’, ‘console_scripts’, ‘docker-compose’)())<br> File “/usr/lib/python3/dist-packages/compose/cli/main.py”, line 81, in main<br> command_func()<br> File “/usr/lib/python3/dist-packages/compose/cli/main.py”, line 200, in perform_command<br> project = project_from_options(‘.’, options)<br> File “/usr/lib/python3/dist-packages/compose/cli/command.py”, line 60, in project_from_options<br> return get_project(<br> File “/usr/lib/python3/dist-packages/compose/cli/command.py”, line 152, in get_project<br> client = get_client(<br> File “/usr/lib/python3/dist-packages/compose/cli/docker_client.py”, line 41, in get_client<br> client = docker_client(<br> File “/usr/lib/python3/dist-packages/compose/cli/docker_client.py”, line 170, in docker_client<br> client = APIClient(use_ssh_client=not use_paramiko_ssh, **kwargs)<br> File “/usr/lib/python3/dist-packages/docker/api/client.py”, line 197, in __init__<br> self._version = self._retrieve_server_version()<br> File “/usr/lib/python3/dist-packages/docker/api/client.py”, line 221, in _retrieve_server_version<br> raise DockerException(<br>docker.errors.DockerException: Error while fetching server API version: (‘Connection aborted.’, PermissionError(13, ‘Permission denied’))</p><p><strong>Permission errors use sudo chmod 666 /var/run/docker.sock and docker compose up -d.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3507ad39a33e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Package, Ship & Sail With Docker And Containerization!]]></title>
            <link>https://medium.com/@babatunde.aborisade1/package-ship-sail-with-docker-and-containerization-d4c02fcade14?source=rss-a5a8b319b1ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4c02fcade14</guid>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Babatunde Aborisade]]></dc:creator>
            <pubDate>Sat, 16 Mar 2024 16:23:03 GMT</pubDate>
            <atom:updated>2024-03-17T17:16:43.876Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j4AQo2lTZ6cEX63QshWf_Q.png" /></figure><p>Packaging and moving around your code could be challenging if not done right. With Docker Containers, you can ensure your code is accessible on any platform. In this tutorial, we will help our client, Level Up Solutions, containerize their web application.</p><h3>Key Terms to remember:</h3><p><strong>Docker: </strong>A set of platform as a service products that use OS-level virtualization to deliver software in packages called containers.</p><p><strong>Container:</strong> A standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.</p><p><strong>Linux:</strong> A family of open-source unix-like operating systems based on the Linux kernel.</p><p><strong>Visual Studio Code: </strong>A<strong> </strong>source-code editor developed by Microsoft for Windows, Linux and macOS.</p><p><strong>EC2: </strong>Amazon Elastic Compute Cloud is a web service that provides secure, resizable compute capacity in the cloud.</p><p><strong>Ubuntu:</strong> A Linux distribution based on Debian and composed mostly of free and open-source software.</p><p><strong>Bash:</strong> A Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell.</p><p><strong>Apache:</strong> A software that is both a free and open-source. The software assist users with deploying their websites online.</p><p><strong>HTML:</strong> HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content.</p><p><strong>Port 80:</strong> Serves as the communication gateway for HTTP requests and responses between client computers and servers.</p><p><strong>Port 8080: </strong>Serves as the communication gateway for HTTPS requests and responses between client computers and servers.</p><p><strong>Docker Hub:</strong> Acontainer registry built for developers and open source contributors to find, use, and share their container images</p><h3><strong>Docker Commands:</strong></h3><p><strong>Docker Run: </strong>Used to create and start a Docker container based on a specified Docker Image.</p><p><strong>Docker Version: </strong>The version of Docker installed on your System.</p><p><strong>Docker Images:</strong> Lists the Docker images that are currently on your system.</p><p><strong>Docker PS: </strong>Used to list the current running Docker containers.</p><p><strong>Docker Pull: </strong>Downloads Docker images from the internet.</p><p><strong>Docker Push: </strong>A<strong> </strong>command that is used to push or share a local Docker image or a repository to a repository.</p><p><strong>Docker Start: </strong>Used to start any stopped container.</p><p><strong>Docker Login: </strong>Log in to any public or private repository for which you have credentials.</p><h3><strong>Setting up Docker</strong></h3><p><strong>Objective 1:</strong> Run a Docker Ubuntu container running detached and on port 80.</p><p>First, we need to set it up to use Docker. In this tutorial, we will use an EC2 named <strong>BADockerEC2 </strong>to host our Docker environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*LYazY7UHjztT_owr7q5bGg.png" /></figure><p>Open up the command terminal and SSH into <strong>BADockerEC2.</strong></p><p>Keypair for <strong>BADockerEC2</strong>:</p><pre>ssh -i &quot;DockerKeyPair.pem&quot; ubuntu@ec2-54-210-77-166.compute-1.amazonaws.com</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CpEwv8CdpxExPEYkT8RagQ.png" /></figure><p>Next, we need to install Docker into the instance with this command:</p><pre>curl -fsSL https://get.docker.com -o get-docker.sh <br>sh get-docker.sh</pre><p>To verify the version of Docker type <strong>docker version.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*ItZHgADTMYlZqx-pEKo6PQ.png" /></figure><p>Now, let’s open Visual Studio Code.</p><p>You must open a new folder, log in as the root user, go to your <strong>.ssh</strong> folder, and create a config file.</p><p>Path:</p><pre>C:\Users\Babor\.ssh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*AZveWSz6rWHrLji7aCvy7w.png" /></figure><p>Open the config file in Visual Studio Code and type this information:</p><pre># Docker EC2 <br>Host Docker<br>  #IPV4 Address will change every time.<br>   HostName  18.212.149.38<br>   User ubuntu<br>   IdentityFile C:\Users\Babor\Documents\AWS\LevelUpInTech\Docker\DockerKeyPair.pem</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CXwOWowMi7yWlYaPtV8U5g.png" /></figure><p>This allows our Docker file to communicate with our EC2 instance. (Note: your public IP address will change each time you stop or shut down your EC2, so you must update your config file every time.)</p><p>Click <strong>open the remote window </strong>button on the bottom left of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/75/1*k4m7yMkGWlwRbk8lXyis4Q.png" /></figure><p>Click on<strong> Connect to Host.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ZYc-xI-9ISItbwACFjBvw.png" /></figure><p>Click <strong>Docker.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cmMAgw_ZQ3NgwVt96cFdZA.png" /></figure><p>You will see an <strong>SSH: Docker</strong> on the bottom left, meaning you have successfully connected to your Docker EC2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*kE1hzyeUSL_CO-RKYAvWzA.png" /></figure><p>Now that we got the configurations setup lets create a new docker file.</p><h3>Creating the Docker File</h3><p><strong>New File -&gt; Text File -&gt; Select a language-&gt;Docker File.</strong></p><p>We will create a new directory in the terminal to keep our files in the same directory.</p><pre>mkdir LUIT-BA-Docker</pre><p>For us to run docker commands, we need to grant permissions using this command:</p><pre>sudo chmod 666 /var/run/docker.sock</pre><p>Now that we have all the configurations, let’s create an Ubuntu image and attach it to port 80.</p><h3>Creating a Docker Container and Image</h3><p>To create a Docker Container use <strong>docker run.</strong></p><pre>docker run -t -d -p 8080:80 --name LUIT-BA-Docker-Container ubuntu:latest </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KuTomSmWQV65hGnQ3Hv9kA.png" /></figure><p>( <strong>-d</strong> deteaches the container and <strong>-t </strong>and runs it in the background, <strong>-p </strong>maps the ports 80 to the container and port 8080 to the local host.)</p><p>To view your container use<strong> docker ps.</strong></p><pre>docker ps </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yIryftp4tbw9YgjVc7ssYw.png" /></figure><p>First, we need to pull our <strong>Ubuntu image</strong> from the docker hub using this <strong>docker pull</strong>.</p><pre>docker pull ubuntu:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ne0QYS6EKLu_FPP35EZQiQ.png" /></figure><p>To start the Docker image, use the <strong>docker run.</strong></p><pre>docker run ubuntu:latest</pre><p>To view your image, run the <strong>docker images.</strong></p><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*NZvYuEqVRkqWPZTu1WN0RA.png" /></figure><p>Use the<strong> docker start</strong> command to start your container.</p><pre>docker start LUIT-BA-Docker-Container</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z3Zb3ke2_C_5uMIN1jZMog.png" /></figure><p>Success: The<strong> LUIT-BA-Docker container </strong>runs in the background on port 80, and the local host is set to port 8080, and we pulled the latest Docker image from Docker Hub.</p><h3>Using BASH to update and install Apache2</h3><p><strong>Objective 2</strong>: Use BASH shell to update all packages within the container .</p><p>Lets make sure that we are only updating our docker file by using this command:</p><pre>docker exec -it LUIT-BA-Docker-Container /bin/bash</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FRLmR52Wx5lkk476Tw23hg.png" /></figure><p>In order to update our packages we will need to use the <strong>update</strong> command.</p><pre>apt-get update</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gu8QogmuLWz0eFC1LcysOQ.png" /></figure><p>After the update is complete we need to <strong>upgrade</strong> the packages.</p><pre> apt-get upgrade -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4VNUQwU_358X6Zqn93_22w.png" /></figure><p>To remove any unnecessary files use the<strong> autoremove.</strong></p><pre>apt-get autoremove</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*pLUvsKsXxlX0bvjOl7EDuQ.png" /></figure><h3>Installing Apache2</h3><p><strong>Objective 3:</strong> Using BASH install Apache2 on the Ubuntu container.</p><p>To install Apache2 onto our container we have to use the <strong>get install</strong> script:</p><pre>apt-get install Apache2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d-mYgYd2_UNAZBKRL-2hEQ.png" /></figure><p>We have successfully installed Apache2 in our docker container.</p><p>To start the Apache2 server we must use the <strong>start</strong> command:</p><pre>systemctl start apache2</pre><p>To verify Apache2 is running use the <strong>status all</strong> command :</p><pre>service --status-all</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*tlk6qnB3bZ--l3jcGAwO-Q.png" /></figure><p>Ensure Port 8080 is open on your security group and copy your public IPv4 address from your instance into your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bEk9QhXC1mFVJ8EW7_Yt2A.png" /></figure><p>Success, we can connect to the Apache2 Webserver.</p><h3><strong>Adding a HTML Page</strong></h3><p><strong>Objective 4:</strong> Add a custom webpage.</p><p>In order to create our html page we need to go into the <strong>html</strong> directory in the root.</p><pre>cd var/www/html</pre><p>To create your html page use the<strong> touch </strong>command:</p><pre>touch &quot;LUIT-Solutions.html&quot;; echo &quot;Welcome to Level Up In Tech Solutions  Team Black!&quot; &gt;&gt; LUIT-Solutions.html</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3SQVsZiRK18raQkhMppyFA.png" /></figure><h3>Verifying the Webserver</h3><p><strong>Objective 5: </strong>Verify you can reach the webserver from your browser.</p><p>To view our web server, we must return to our <strong>BADockerEC2</strong> instance and change the security group’s inbound rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gq--pWq1k2Ll0j9E3f0x3w.png" /></figure><p><strong>Inbound rules -&gt; HTTP -&gt; TCP -&gt; Port 80-&gt;Anywhere-&gt; 0.0.0.0/0 -&gt; Save rules. </strong>(We are allowing the port to be accessed anywhere for demonstration purposes only, but in real-world production, it is best practice to use a custom IP address for added security.<strong>)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oG1DLoOUj7oz77kO-m5nqg.png" /></figure><p>Let’s verify the website works by copying and pasting the public IPv4 address to our browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*18DoCot14ANfEEih04njkQ.png" /></figure><p>Success, our website is working!</p><h3><strong>Pushing to Docker Hub</strong></h3><p><strong>Objective 6:</strong> Push to Docker Hub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hSPr63Gyy1cBQL5rUUH87A.png" /></figure><p>Create a repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x6ST0eI2q0ATBodH-vm-6g.png" /></figure><p>First, we must log in to our Dockerhub.com account in the terminal using the<strong> docker login </strong>command. (Make sure you create an account on dockerhub.com)</p><pre>docker login</pre><p>Enter your username &amp; password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5_7dv9vWKItMlOmYqdmToQ.png" /></figure><p>We need to tag our <strong>docker image</strong> in order to upload it.</p><pre>docker tag ubuntu:latest bt00ns/ba-docker-repo:1.0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wrQVKJLHklm3Und3Uql3ow.png" /></figure><p>Push the image.</p><pre>docker push bt00ns/ba-docker-repo:1.0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*okf9cJbHAsWsWYl67CS7ZA.png" /></figure><p>Let’s go to our docker hub to verify it was pushed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tU38ovodhOOlRICCVQYzJw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*cSOIYkkXWuYoyJ7_ZHmIjw.png" /></figure><p>The docker image went through!</p><h3>Pulling from Docker Hub</h3><p><strong>Objective 7:</strong> Pull your new image and run on a different port than 80 while still mapping to 80 on the container. Verify you can reach the webserver using the updated port.</p><p><strong>Pull </strong>command:</p><pre>docker pull bt00ns/ba-docker-repo:1.0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4NUwxaGYPsL-rirRT85lrg.png" /></figure><p>The image was successfully pulled from the docker repository.</p><p>We will run the new image on a new port, port 443, and keep it in the background. The local host is set to port 80.</p><pre>docker run -t -d -p 443:80 --name New-LUIT-Container bt00ns/ba-docker-repo:1.0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oBtKDw2rdSTuG22QWEjQeQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iG3kn8_POd4t2wYOablfOw.png" /></figure><h3>Apache2</h3><p>Now, let’s verify that we can view the web server using <strong>port 443. (Note: Repeat the previous steps on logging into the root user of the container and installing updates, upgrades, and Apache2 from the previous container we created.)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bEk9QhXC1mFVJ8EW7_Yt2A.png" /></figure><p>Success! We are able to view the Apache2 server on port 443!</p><h3><strong>Conclusion:</strong></h3><p>Level Up Solutions has successfully employed Docker and containers to bundle their web server in a Docker image and preserve it in a Docker repository. This approach has facilitated a seamless transfer of their application to an alternative environment, completely free from any potential compatibility issues. This is this is very important because it accelerates the code deployment process while conserving valuable resources, by bundling all required elements together.</p><p>Follow me on Medium for more cloud blogs and add me on LinkedIn.</p><p>LinkedIn: <a href="https://www.linkedin.com/in/babatundeaborisade/">https://www.linkedin.com/in/babatundeaborisade/</a></p><h3>References:</h3><ul><li><a href="https://docs.docker.com/"></a></li><li><a href="https://hub.docker.com/">Docker Hub Container Image Library | App Containerization</a></li></ul><h3><strong>Errors/Fixes:</strong></h3><ol><li>Error response from daemon: conflict: unable to remove repository reference “ubuntu” (must force) — container 0f9afc51b866 is using its referenced image fd1d8f58e8ae.</li></ol><p><strong>In order to resolve this issue run this code:</strong></p><pre>docker rmi -f ubuntu</pre><p>2. Unable to find image ‘ubuntu:latest’ locally<br>latest: Pulling from library/ubuntu<br>57c139bbda7e: Already exists <br>Digest: sha256:e9569c25505f33ff72e88b2990887c9dcf230f23259da296eb814fc2b41af999<br>Status: Downloaded newer image for ubuntu:latest<br>3b6abcc70d50ff88623e9aece0f4b644a89106ac852267544b9ca9fa7bfb1ec7<br>docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: “20.04”: executable file not found in $PATH: unknown.</p><p><strong>In order to resolve this issue run this code:</strong></p><pre>docker run -it ubuntu:20.04 /bin/bash</pre><p>3. docker: Error response from daemon: Conflict. The container name “/BA-Ubuntu-Container” is already in use by container “5a8a11ccb2537d95c267e1eda2789d2dec17de202e835c7c0acd0bdd9f49632c”. You have to remove (or rename) that container to be able to reuse that name. See ‘docker run — help’.</p><p><strong>In order to resolve this issue run this code:</strong></p><pre>docker rename 5a811ccb253 new-container-name</pre><p>4. permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get “<a href="http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json">http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json</a>&quot;: dial unix /var/run/docker.sock: connect: permission denied.</p><p><strong>In order to resolve this issue run this code:</strong></p><pre>sudo chmod 666 /var/run/docker.sock</pre><p>5. Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: “20.04”: executable file not found in $PATH: unknown<br>Error: failed to start containers: 5a8a11ccb2537d95c267e1eda2789d2dec17de202e835c7c0acd0bdd9f49632c</p><p><strong>In order to resolve this issue run this code:</strong></p><pre>docker inspect 5a811ccb253</pre><pre>sudo systemctl restart docker </pre><p>6. If your Container is not showing up locally using <strong>docker ps</strong> make sure you have a<strong> -t </strong>or <strong>-i </strong>in the script. ( ex. <strong>docker run -t -d -p [port number:port number] — name [name-of-container] [image]</strong></p><p>7. If you are not able to login to your dockerhub account run this command first for permission to be granted:</p><pre>sudo chmod 666 /var/run/docker.sock</pre><p>8. The push refers to repository [LUITBADockerImage/ubuntu]<br>Get “<a href="https://luitbadockerimage/v2/">https://LUIT-BA-Docker-Image/v2/</a>&quot;: dial tcp: lookup LUITBADockerImage on 127.0.0.53:53: server misbehaving.</p><p><strong>The solution to this error is to create a repository on dockerhub.com before you push your docker image.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4c02fcade14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform: The Building Blocks To Creating Your Infrastructure With AWS & Jenkins!]]></title>
            <link>https://medium.com/@babatunde.aborisade1/terraform-the-building-blocks-to-creating-your-infrastructure-with-aws-jenkins-138bf488ca27?source=rss-a5a8b319b1ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/138bf488ca27</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Babatunde Aborisade]]></dc:creator>
            <pubDate>Thu, 07 Mar 2024 21:22:23 GMT</pubDate>
            <atom:updated>2024-03-13T22:09:13.552Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*EK32MyYV5k3WejR2FVhe-g.png" /></figure><p>Are you seeking a more efficient way to deploy your code that can save time and effort compared to manual resource configuration in the AWS Console? Terraform is the solution you need. With Terraform, you can deploy your code in minutes. This project will demonstrate how to build your infrastructure code using Terraform, set up a Jenkins server, and organize your code into separate Terraform files for better continuity.</p><h3>Key Terms To Remember:</h3><p><strong>Jenkins: </strong>An open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration, and continuous delivery.</p><p><strong>Terraform:</strong> An<strong> </strong>IAC tool, used primarily by DevOps teams to automate various infrastructure tasks.</p><p><strong>Infrastructure as Code(IaC): </strong>The process of managing and provisioning computer data center resources through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools.</p><p><strong>.tf: </strong>Code in the Terraform language is stored in plain text files with the . tf file extension.</p><p><strong>CI/CD: </strong>The combined practices of continuous integration and continuous delivery or, less often, continuous deployment.</p><p><strong>Provider: </strong>A plugin that enables interaction with an API. This includes Cloud providers and Software-as-a-service providers.</p><p><strong>EC2: </strong>Amazon Elastic Compute Cloud is a web service that provides secure, resizable compute capacity in the cloud.</p><p><strong>AMI: </strong>A<strong> </strong>special type of virtual appliance used to create a virtual machine within the Amazon Elastic Compute Cloud. It serves as the basic unit of deployment for services delivered using EC2.</p><p><strong>Subnet: </strong>The practice of dividing a network into two or more networks.</p><p><strong>Security Groups: </strong>Controls the traffic that is allowed to reach and leave the resources that it is associated with.</p><p><strong>Key Pair: </strong>A<strong> </strong>public key that is used to encrypt data and a private key that is used to decrypt data.</p><p><strong>VPC: </strong>A virtual network that closely resembles a traditional network that you’d operate in your own data center.</p><p><strong>Bootstrap: </strong>A<strong> </strong>tool in the AWS CDK command-line interface responsible for populating a given environment (that is, a combination of AWS account and region) with resources required by the CDK to perform deployments into that environment.</p><p><strong>Ubuntu: </strong>An<strong> </strong>operating system designed and engineered as a backbone for the internet.</p><p><strong>S3 Bucket:</strong> An object storage service.</p><p><strong>SSH: </strong>Secure Shell or Secure Socket Shell, is a network protocol that gives users, particularly system administrators, a secure way to access a computer over an unsecured network.</p><p><strong>IP Address: </strong>a unique string of characters that identifies each computer using the Internet Protocol to communicate over a network.</p><p><strong>Variables: </strong>Used to pass certain values from outside of the configuration or module.</p><p><strong>User Data: </strong>The commands/data you can provide to an instance at launch time. You can use instance user data to customize your instances. When you launch an instance, you can store parameters or scripts as<strong> </strong>user data.</p><p><strong>Cloud 9: </strong>A<strong> </strong>cloud-based IDE that lets you code with a browser. It includes a code editor, debugger, and terminal, and comes with essential tools for popular programming languages like Python and JavaScript.</p><h3>Terraform Commands:</h3><p><strong>terraform init: </strong>Initializes a working directory and downloads the necessary provider plugins and modules and setting up the backend for storing your infrastructure’s state.</p><p><strong>terraform fmt: </strong>Used to rewrite Terraform configuration files to a canonical format and style.</p><p><strong>terraform validate: </strong>Validates the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc.</p><p><strong>terraform plan: </strong>Creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure.</p><p><strong>terraform apply: </strong>Executes the actions proposed in a terraform plan . It is used to deploy your infrastructure.</p><p><strong>terraform destroy: </strong>Terminates resources defined in your Terraform configuration.</p><h3>Things to know before starting:</h3><ol><li>You will frequently use these Terraform commands when testing your code.</li><li>It is important to test your code as you go so you can make changes and identify errors early on and avoid spending too much time backtracking.</li><li>Use the offical documentation from <a href="https://developer.hashicorp.com/terraform/docs">https://developer.hashicorp.com/terraform/docs</a> &amp; <a href="https://registry.terraform.io/">https://registry.terraform.io/</a> to reference your code.</li></ol><h3>Terraform Main.tf Configuration</h3><p><strong>Objective 1:</strong> Deploy 1 EC2 Instances in your Default VPC.</p><p>Let’s get started; we will need to choose an <strong>IDE</strong> in order to use Terraform; for this tutorial, I will be using <strong>AWS Cloud 9</strong>.</p><p>Create a file and name it <strong>main.tf</strong> , this will be the file we will be putting all of our code in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/143/1*A-WrGgK0GQ2GpzJcHeXx2w.png" /></figure><h3>AWS Provider</h3><p>Before we create our<strong> VPC</strong> and<strong> EC2</strong>, we need to identify our <strong>provider</strong>, which will be <strong>AWS</strong>. This will let Terraform know that we will be using AWS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*N9zZCw3Tt-LmFUcabGs4dQ.png" /></figure><p><strong>AWS Provider Code:</strong></p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 5.0&quot;<br>    }<br>  }<br>}<br><br># Configure the AWS Provider<br>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}</pre><p><strong>Code breakdown:</strong></p><ol><li>The <strong>required provider’s </strong>tag tells Terraform which providers we will be using.</li><li>The <strong>region</strong> tag tells the location where the code is.</li><li><strong>Version</strong> is the current version of the terraform application.</li></ol><h3>Terraform Init</h3><p>Now that we have selected our provider run the command <strong>terraform init. </strong>Terraform init allows Terraform to run its program, allowing us to deploy our code.</p><pre>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*ERQ5o_28JXJUh8pKgWHZHw.png" /></figure><h3>EC2 Instance &amp; VPC Creation</h3><p>To create our EC2 instance, we need to use the <strong>resource</strong> tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*c-cBECW0-iwmoFhaf2z2HQ.png" /></figure><p><strong>EC2 code:</strong></p><pre># LUIT Terraform Project BA <br>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 5.0&quot;<br>    }<br>  }<br>}<br><br># Configure the AWS Provider<br>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}<br><br># Creating an EC2 Instance<br>resource &quot;aws_instance&quot; &quot;BA_Linux_EC2&quot; {<br>  instance_type = &quot;t2.micro&quot;<br>  ami           = &quot;ami-07d9b9ddc6cd8dd30&quot;<br>  subnet_id     = &quot;subnet-08d7962a011946932&quot;<br>  key_name      = &quot;BA_KeyPair&quot;<br>}</pre><p><strong>Code breakdown:</strong></p><ol><li><strong>Instance type</strong> defines the the type of EC2 instance.</li><li><strong>AMI</strong> names the Amazon Machine Image the EC2 is using.</li><li><strong>Subnet ID</strong> is the subnet that will launch with the EC2.</li><li><strong>Key Name</strong> is the key pair associated with the EC2 that will allow SSH.</li></ol><p>To find the <strong>Ubuntu AMI, </strong>search the <strong>AMI Catalog </strong>in the AWS console’s search bar and look for <strong>Ubuntu</strong> underneath <strong>AMIs.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b1MdpcWBUBceexa7_piqAQ.png" /></figure><p>To find your<strong> subnet_id</strong>, type <strong>VPC</strong> in the search box, check which VPC is your <strong>default, </strong>and look at the subnet section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pNGTDyzlyB7f8lnLDJrt2g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*g_jrBQ6sXXxzGs5--f3qJA.png" /></figure><p>Search<strong> Key Pairs </strong>in the search bar and find the key pair to which you will link your EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*985emCFR8KCNRjFiqU_kCg.png" /></figure><p>Now that we have our EC2 resource section filled out let’s use the command <strong>terraform validate </strong>so that we do not have any errors.</p><pre>terraform validate</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*2ueOqLfYm9aIjALvWlb8uA.png" /></figure><p>Using <strong>terraform fmt </strong>formats your code to make it look cleaner.</p><pre>terraform fmt </pre><p>Let’s prepare our code for deployment by using <strong>terraform plan.</strong></p><pre>terraform plan</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*bx8xo3LNrAThYCPLn5P41w.png" /></figure><p>Now, we are ready to deploy our code using <strong>terraform apply.</strong></p><pre>terraform apply</pre><p>Type <strong>yes</strong> to confirm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*wEAZC8-JkU5nkaYCK5Hb4w.png" /></figure><p>Success! Our EC2 instance was created using Terraform and placed in the default VPC.</p><p>Let’s verify in the AWS console that the EC2 instance was created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*65MJb_Rz-IxKJ63DimyVcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*kF2p-DQGVPzoxkaZBFXqGA.png" /></figure><h3>Installing Jenkins</h3><p><strong>Objective 2:</strong> Bootstrap the EC2 instance with a script that will install and start Jenkins.</p><p><strong>Jenkins code:</strong></p><pre>user_data = &lt;&lt;-EOF<br>#!/bin/bash<br>sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \<br>  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key<br>echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \<br>  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \<br>  /etc/apt/sources.list.d/jenkins.list &gt; /dev/null<br>sudo apt-get update<br>sudo apt-get install jenkins<br>EOF</pre><p><strong>Code breakdown:</strong></p><ol><li><strong>User Data</strong> contains the code that will be launched on the EC2.</li><li><strong>Wget</strong> gives privileges to download Jenkins.</li><li><strong>Echo</strong> adds the repository packages.</li><li><strong>Apt-get update</strong> updates the packages.</li><li>A<strong>pt-get install</strong> installs Jenkins.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*-hiJYjCmjtZqmxdekhh_3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*6SG7QNrIwQ7umekYkm6HJw.png" /></figure><p>Jenkins has been successfully deployed using <strong>terraform apply.</strong></p><h3>Security Group for Jenkins (Ingress &amp; Egress)</h3><p><strong>Objective 3: </strong>Create and assign a Security Group to the Jenkins Security Group that allows traffic on port 22 from your ip and allows traffic from port 8080.</p><p><strong>Security Group Code:</strong></p><pre>resource &quot;aws_security_group_rule&quot; &quot;Allow_Port_22&quot; {<br>  security_group_id = &quot;sg-005b368062d04188d&quot;<br>  type              = &quot;ingress&quot;<br>  from_port         = 22<br>  to_port           = 22<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br><br>resource &quot;aws_security_group_rule&quot; &quot;Allow_Port_8080&quot; {<br>  security_group_id = &quot;sg-005b368062d04188d&quot;<br>  type              = &quot;ingress&quot;<br>  from_port         = 8080<br>  to_port           = 8080<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br><br>resource &quot;aws_security_group_rule&quot; &quot;Allow_All_Traffic&quot; {<br>  security_group_id = &quot;sg-005b368062d04188d&quot;<br>  type              = &quot;egress&quot;<br>  from_port         = 0<br>  to_port           = 0<br>  protocol          = &quot;-1&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br></pre><p><strong>Code breakdown:</strong></p><ol><li><strong>Allow Port 8080</strong> allows inbound traffic to access port 8080.</li><li><strong>Allow Port 22 </strong>allows inbound traffic to access port 22.</li><li><strong>Allow All Traffic </strong>allows all outbound traffic to the internet.</li></ol><p>After running<strong> terraform apply </strong>the Security Group were created successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*lwwCGAJhaqggWw4GYy9sSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v_Y-4NBElS9XJd6x3T4k5Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HbVt6u0G0A10ce97i4EQjw.png" /></figure><h3>S3 Bucket for Jenkins Artifacts</h3><p><strong>Objective 4: </strong>Create a S3 bucket for your Jenkins Artifacts that is not open to the public.</p><p><strong>S3 Bucket Code:</strong></p><pre><br>resource &quot;aws_s3_bucket&quot; &quot;ba_jenkins_artifacts_bucket&quot; {<br>  bucket = &quot;ba-jenkins-artifacts-bucket&quot;<br>  acl    = &quot;private&quot;<br>  tags = {<br>    Name        = &quot;jenkins-artifacts-bucket&quot;<br>    Environment = &quot;Dev&quot;<br>  }<br>}</pre><p><strong>Code breakdown:</strong></p><ol><li><strong>Resource </strong>defines the source type of the S3 Bucket.</li><li><strong>Bucket </strong>is the name of the S3 Bucket.</li><li><strong>ACL </strong>is the Access Control List configuration that allows the S3 Bucket to be private or public.</li><li><strong>Tags </strong>are used to identify the bucket for quick search.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VPrfU4yQjtQHvm2ywAW_Hg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*Ct4m46VT35VWo3quoGTxSA.png" /></figure><ol><li>The S3 Bucket was successfully created, and the bucket’s access is private.</li></ol><h3><strong>SSH into Jenkins</strong></h3><p><strong>Objective 5:</strong> Verify that you can reach your Jenkins install via port 8080 in your browser.</p><p>To verify that Jenkins is running we will need to <strong>SSH</strong> into our EC2 instance.</p><p>Go to <strong>BA_Linux_EC2</strong> instance on the console and copy the code to SSH.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RH4gpmIFYSORKiaYTa-IQQ.png" /></figure><p>Open the command terminal, go to the folder where you placed your key pair, and paste your SSH code.</p><pre>ssh -i &quot;BA_KeyPair.pem&quot; ubuntu@ec2-34-229-247-195.compute-1.amazonaws.com</pre><p>Run<strong> systemctl status jenkins </strong>to verify Jenkins is installed.</p><pre>systemctl status jenkins</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LuQ1heWH8a6xD7sZdf0vbw.png" /></figure><p>(Note, If you do not see Jenkins, run the code below to reinstall it.).</p><pre>sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \<br>  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key<br>echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \<br>  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \<br>  /etc/apt/sources.list.d/jenkins.list &gt; /dev/null<br>sudo apt-get update<br>sudo apt-get install jenkins</pre><p>Now let’s check that we can view Jenkins by copying the <strong>public IPv4 address</strong> and pasting it to our browser.</p><p>Public IPv4 Address (Note, this will be different for your EC2 instance.)</p><pre>52.23.153.56</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Skd3vllMRkpXqJ7GX3yGQ.png" /></figure><p>Success! We can access Jenkins from port 8080!</p><h3>Github</h3><p><strong>Objective 6:</strong> Push your code to GitHub.</p><p>Using AWS Cloud 9, I pushed my code to my repository on github.com</p><p><a href="https://github.com/NBTOONS45/Terraform-BA-Projects/tree/BA-Terraform">https://github.com/NBTOONS45/Terraform-BA-Projects/tree/BA-Terraform</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9Ic9-BErgt9c4EBErzXeA.png" /></figure><p><strong>Full code:</strong></p><pre># LUIT Terraform Project BA #1<br>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 5.0&quot;<br>    }<br>  }<br>}<br><br># Configure the AWS Provider<br>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}<br><br># Creating an EC2 Instance<br>resource &quot;aws_instance&quot; &quot;BA_Linux_EC2&quot; {<br>  instance_type = &quot;t2.micro&quot;<br>  ami           = &quot;ami-07d9b9ddc6cd8dd30&quot;<br>  subnet_id     = &quot;subnet-08d7962a011946932&quot;<br>  key_name      = &quot;BA_KeyPair&quot;<br>  <br># Creating user data<br>  user_data = &lt;&lt;-EOF<br>#!/bin/bash<br>sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \<br>  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key<br>echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \<br>  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \<br>  /etc/apt/sources.list.d/jenkins.list &gt; /dev/null<br>sudo apt-get update<br>sudo apt-get install jenkins<br>EOF<br>}<br><br># Creating Ingress &amp; Egress Security Groups<br><br>resource &quot;aws_security_group&quot; &quot;BA_Jenkins_SG&quot; {<br>  name        = &quot;Jenkins Security Group&quot;<br>  description = &quot;Jenkins Security Group&quot;<br>  vpc_id      = &quot;vpc-008ad1a71fd6692bb&quot;<br><br>  tags = {<br>    Name = &quot;Jenkins SG&quot;<br>  }<br>}<br><br># Creating a Security Group <br><br>resource &quot;aws_security_group_rule&quot; &quot;Allow_Port_22&quot; {<br>  security_group_id = &quot;sg-005b368062d04188d&quot;<br>  type              = &quot;ingress&quot;<br>  from_port         = 22<br>  to_port           = 22<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br><br>resource &quot;aws_security_group_rule&quot; &quot;Allow_Port_8080&quot; {<br>  security_group_id = &quot;sg-005b368062d04188d&quot;<br>  type              = &quot;ingress&quot;<br>  from_port         = 8080<br>  to_port           = 8080<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br><br>resource &quot;aws_security_group_rule&quot; &quot;Allow_All_Traffic&quot; {<br>  security_group_id = &quot;sg-005b368062d04188d&quot;<br>  type              = &quot;egress&quot;<br>  from_port         = 0<br>  to_port           = 0<br>  protocol          = &quot;-1&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br><br># Creating a S3 Bucket Artifact for Jenkins<br><br>resource &quot;aws_s3_bucket&quot; &quot;ba_jenkins_artifacts_bucket&quot; {<br>  bucket = &quot;ba-jenkins-artifacts-bucket&quot;<br>  acl    = &quot;private&quot;<br>  tags = {<br>    Name        = &quot;jenkins-artifacts-bucket&quot;<br>    Environment = &quot;Dev&quot;<br>  }<br>}<br><br>#BA</pre><h3>Variables</h3><p><strong>Objective 7:</strong> Add a <a href="http://variables.tf/">variables.tf</a> file and make sure nothing is hardcoded in your <a href="http://main.tf/">main.tf</a>.</p><p>When working with multiple<strong> .tf </strong>files, ensure they are all nested in the same folder/repository to be referenced.</p><p>Create a file named <strong>variables.tf</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/195/1*Zos8WjqLnyeWdxQVIhdrwg.png" /></figure><p><strong>Variables.tf Code:</strong></p><pre># LUIT Terraform Project BA #1<br><br># Variable AWS Region<br><br>variable &quot;aws_region&quot; {<br>  description = &quot;This is the AWS Region.&quot;<br>  type        = string<br>  default     = &quot;us-east-1&quot;<br>}<br><br># Creating a Variable  EC2 Instance<br>variable &quot;instance_type&quot; {<br>  description = &quot;EC2 instance&quot;<br>  type        = string<br>  default     = &quot;t2.micro&quot;<br>}<br><br># Creating a Variable AMI<br><br>variable &quot;ami_id&quot; {<br>  description = &quot;AMI ID of EC2&quot;<br>  type        = string<br>  default     = &quot;ami-07d9b9ddc6cd8dd30&quot;<br>}<br><br># Creating a Variable Ingress &amp; Egress Security Groups<br><br>variable &quot;subnet_id&quot; {<br>  description = &quot;Subnet ID of EC2&quot;<br>  type        = string<br>  default     = &quot;subnet-08d7962a011946932&quot;<br>}<br><br># Creating a Variable SSH Key<br><br>variable &quot;ssh_key_name&quot; {<br>  description = &quot;Name of the Key Pair for the EC2&quot;<br>  type        = string<br>  default     = &quot;BA_KeyPair&quot;<br>}<br><br># Variable CIDR Block<br><br>variable &quot;jenkins_cidr_block&quot; {<br>  description = &quot;CIDR block to connect to Jenkins&quot;<br>  type        = list(string)<br>  default     = [&quot;0.0.0.0/0&quot;]<br>}<br><br># Variable Security Group<br><br>variable &quot;sg_id&quot; {<br>  description = &quot;Security Group for EC2&quot;<br>  type        = string<br>  default     = &quot;sg-005b368062d04188d&quot;<br>}<br><br># Variable S3 Bucket<br><br>variable &quot;s3_bucket_name&quot; {<br> # LUIT Terraform Project BA #1<br><br>  description = &quot;S3 Bucket name&quot;<br>  type        = string<br>  default     = &quot;ba-jenkins-artifacts-bucket&quot;<br>}<br><br># Variable ACL for S3 Bucket<br>variable &quot;s3_bucket_acl&quot; {<br>  description = &quot;ACL access for S3 Bucket&quot;<br>  type        = string<br>  default     = &quot;private&quot;<br>}<br><br>#BA</pre><p><strong>Main.tf Code including the Variables:</strong></p><p><strong>var.</strong> references the variables in the <strong>variables.tf</strong> file.</p><pre># LUIT Terraform Project BA #1<br><br># Creating an EC2 Instance<br>resource &quot;aws_instance&quot; &quot;BA_Linux_EC2&quot; {<br>  instance_type = var.instance_type<br>  ami           = var.ami_id<br>  subnet_id     = var.subnet_id<br>  key_name      = var.ssh_key_name<br><br><br>  # Creating user data<br><br><br><br>  user_data = &lt;&lt;-EOF<br>#!/bin/bash<br>sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \<br>  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key<br>echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \<br>  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \<br>  /etc/apt/sources.list.d/jenkins.list &gt; /dev/null<br>sudo apt-get update<br>sudo apt-get install jenkins<br>EOF<br>}<br><br># Creating Ingress &amp; Egress Security Groups<br><br>resource &quot;aws_security_group&quot; &quot;BA_Jenkins_SG&quot; {<br>  name        = &quot;Jenkins Security Group&quot;<br>  description = &quot;Jenkins Security Group&quot;<br>  vpc_id      = &quot;vpc-008ad1a71fd6692bb&quot;<br><br>  tags = {<br>    Name = &quot;Jenkins SG&quot;<br>  }<br>}<br><br>resource &quot;aws_security_group_rule&quot; &quot;Allow_Port_22&quot; {<br>  security_group_id = var.sg_id<br>  type              = &quot;ingress&quot;<br>  from_port         = 22<br>  to_port           = 22<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = var.jenkins_cidr_block<br>}<br><br>resource &quot;aws_security_group_rule&quot; &quot;Allow_Port_8080&quot; {<br>  security_group_id = var.sg_id<br>  type              = &quot;ingress&quot;<br>  from_port         = 8080<br>  to_port           = 8080<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = var.jenkins_cidr_block<br>}<br><br>resource &quot;aws_security_group_rule&quot; &quot;Allow_All_Traffic&quot; {<br>  security_group_id = var.sg_id<br>  type              = &quot;egress&quot;<br>  from_port         = 0<br>  to_port           = 0<br>  protocol          = &quot;-1&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>}<br><br># Creating a S3 Bucket Artifact for Jenkins<br><br>resource &quot;aws_s3_bucket&quot; &quot;ba-jenkins-artifacts-bucket&quot; {<br>  bucket = var.s3_bucket_name<br>  acl    = var.s3_bucket_acl<br>  tags = {<br>    Name        = &quot;jenkins-artifacts-bucket&quot;<br>    Environment = &quot;Dev&quot;<br>  }<br>}<br><br>#BA</pre><h3>Providers</h3><p>O<strong>bjective 8: </strong>Create separate file for your <a href="http://providers.tf/">providers.tf</a>.</p><p>Create a file named<strong> providers.tf.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/209/1*eCvhPeM1sm_PilCbXSbdPw.png" /></figure><p><strong>Providers.tf Code:</strong></p><pre># LUIT Terraform Project BA #1<br><br>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 5.0&quot;<br>    }<br>  }<br>}<br><br># Configure the AWS Provider<br>provider &quot;aws&quot; {<br>  region = var.aws_region<br>}<br><br>#BA</pre><p>When you are done testing with <strong>terraform destroy, </strong>ensure you destroy your code<strong> </strong>so you don’t incur any unexpected costs.</p><pre>terraform destroy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*oTFhWf1Wpe1_BkDjPvo-OQ.png" /></figure><h3>Conclusion:</h3><p>This project showcases how Terraform can be utilized to create infrastructure more efficiently than the AWS Console. The establishment of a Jenkins server and the separation of code into distinct Terraform files are notable achievements. By leveraging Terraform, the deployment process can be streamlined, and the code can be implemented across multiple environments, resulting in an increased level of efficiency.</p><p>Follow me on Medium for more cloud blogs and add me on LinkedIn.</p><p>LinkedIn: <a href="https://www.linkedin.com/in/babatundeaborisade/">https://www.linkedin.com/in/babatundeaborisade/</a></p><p>Github: <a href="https://github.com/NBTOONS45">https://github.com/NBTOONS45</a></p><h3>References:</h3><ul><li><a href="https://www.jenkins.io/doc/book/installing/linux/">Linux</a></li><li><a href="https://developer.hashicorp.com/terraform/docs">Terraform overview | Terraform | HashiCorp Developer</a></li><li><a href="https://registry.terraform.io/">Terraform Registry</a></li></ul><h3>Issues/Fixes:</h3><p><strong>1.)</strong> Your infrastructure matches the configuration.</p><p>Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.</p><p><strong>An existing instance has been created so I had to edit the instance name.</strong></p><p><strong>2.) </strong>Error: Invalid multi-line string<br>│ on main.tf line 21, in resource “aws_instance” “BA_Linux_EC2”:<br>│ 21: subnet_id = “08d7962a011946932<br>│ 22: key_name = “BA_KeyPair”<br>│ Quoted strings may not be split over multiple lines. To produce a multi-line string, either use the \n escape to represent a newline character or use the<br>│ “heredoc” multi-line template syntax.<br>│ Error: Unterminated template string<br>│ on main.tf line 21, in resource “aws_instance” “BA_Linux_EC2”:<br>│ 21: subnet_id = “08d7962a011946932<br>│ 22: key_name = “BA_KeyPair”<br>│ No closing marker was found for the string.<br>│ Error: Invalid multi-line string<br>│ on main.tf line 22, in resource “aws_instance” “BA_Linux_EC2”:<br>│ 22: key_name = “BA_KeyPair”<br>│ 23: } <br>│ Quoted strings may not be split over multiple lines. To produce a multi-line string, either use the \n escape to represent a newline character or use the<br>│ “heredoc” multi-line template syntax.<br>│ Error: Invalid multi-line string<br>│ on main.tf line 23, in resource “aws_instance” “BA_Linux_EC2”:<br>│ 23: } <br>│ 24: <br>│ Quoted strings may not be split over multiple lines. To produce a multi-line string, either use the \n escape to represent a newline character or use the<br>│ “heredoc” multi-line template syntax.<br>│ Error: Invalid multi-line string<br>│ on main.tf line 24, in resource “aws_instance” “BA_Linux_EC2”:<br>│ 24: <br>│ Quoted strings may not be split over multiple lines. To produce a multi-line string, either use the \n escape to represent a newline character or use the<br>│ “heredoc” multi-line template syntax.</p><p><strong>The terraform script is not formatted correctly, multple lines of extra space.</strong></p><p><strong>3.)</strong> Error: Missing required provider<br>│ This configuration requires provider registry.terraform.io/hashicorp/aws, but that provider isn’t available. You may be able to install it automatically<br>│ by running:<br>│ terraform init</p><p><strong>Run terraform init to resolve this issue.</strong></p><p>4.) Error: creating EC2 Instance: InvalidSubnetID.NotFound: The subnet ID ‘08d7962a011946932’ does not exist<br>│ status code: 400, request id: 488a702c-99cc-40f3–973a-b7539b2910c8<br>│ with aws_instance.BA_Linux_EC2,<br>│ on main.tf line 17, in resource “aws_instance” “BA_Linux_EC2”:<br>│ 17: resource “aws_instance” “BA_Linux_EC2” {<br><br><strong>Needed to add subnet to the beginning of the id. ex. subnet-08d7962a011946932.</strong></p><p>5.) <br>│ on main.tf line 56, in resource “aws_vpc_security_group_egress_rule” “Allow_All_Traffic”:<br>│ 56: cidr_blocks = [“0.0.0.0/0”]<br>│ An argument named “cidr_blocks” is not expected here.</p><p><strong>Replace Cidr_blocks with cidr_ipv4 in egress rules.</strong></p><p>6.) <br>│ Error: [WARN] A duplicate Security Group rule was found on (sg-005b368062d04188d). This may be<br>│ a side effect of a now-fixed Terraform issue causing two security groups with<br>│ identical attributes but different source_security_group_ids to overwrite each<br>│ other in the state. See <a href="https://github.com/hashicorp/terraform/pull/2376">https://github.com/hashicorp/terraform/pull/2376</a> for more<br>│ information and instructions for recovery. Error: InvalidPermission.Duplicate: the specified rule “peer: 0.0.0.0/0, ALL, ALLOW” already exists<br>│ status code: 400, request id: d03697a4-fc63–49e6-b48b-337f2b3bce7c<br>│ with aws_security_group_rule.Allow_All_Traffic,<br>│ on main.tf line 64, in resource “aws_security_group_rule” “Allow_All_Traffic”:<br>│ 64: resource “aws_security_group_rule” “Allow_All_Traffic” {</p><p><strong>Security group may exist or is duplicated, check your VPC section in the AWS Console to confirm.</strong></p><p>7.) <br>│ Error: creating S3 Bucket (jenkins_artifacts_bucket): operation error S3: CreateBucket, https response error StatusCode: 400, RequestID: 61WBDDWT7ZVBDEVZ, HostID: J5ZDahH2yrwv7lkvf4vv0hTn0iUwhtIWn5ucsjAyfsO6lcuJqThvC4vQya8S+X8l2Y0uWOQI8nM=, api error InvalidBucketName: The specified bucket is not valid.</p><p><strong>Changed the “_” to a “—” instead on my bucket name.</strong></p><p><strong>8.) </strong>Error: Incorrect attribute value type <br>│ on main.tf line 44, in resource “aws_security_group_rule” “Allow_Port_22”:<br>│ 44: cidr_blocks = “var.jenkins_cidr_block”<br>│ Inappropriate value for attribute “cidr_blocks”: list of string required.<br>│ Error: Incorrect attribute value type<br>│ on main.tf line 53, in resource “aws_security_group_rule” “Allow_Port_8080”:<br>│ 53: cidr_blocks = “var.jenkins_cidr_block”<br>│ Inappropriate value for attribute “cidr_blocks”: list of string required.<br>│ Error: expected acl to be one of [“private” “public-read” “public-read-write” “authenticated-read” “aws-exec-read” “log-delivery-write”], got var.s3_bucket_acl <br>│ with aws_s3_bucket.ba_jenkins_artifacts_bucket,<br>│ on main.tf line 69, in resource “aws_s3_bucket” “ba_jenkins_artifacts_bucket”:<br>│ 69: acl = “var.s3_bucket_acl&quot;</p><p><strong>To resolve this I removed the “” marks on var.s3_bucket_acl &amp; var.jenkins_cidr_block</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=138bf488ca27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tackling Server Management Challenges with Python, Boto3, and Lambda Automation!]]></title>
            <link>https://medium.com/@babatunde.aborisade1/tackling-server-management-challenges-with-python-boto3-and-lambda-automation-6acafe976e91?source=rss-a5a8b319b1ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/6acafe976e91</guid>
            <category><![CDATA[boto3]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[lambda]]></category>
            <dc:creator><![CDATA[Babatunde Aborisade]]></dc:creator>
            <pubDate>Thu, 08 Feb 2024 18:01:48 GMT</pubDate>
            <atom:updated>2024-02-08T23:20:38.116Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*xW8sAQEk5MhfvXtdnfxX9w.jpeg" /></figure><p>Have you ever encountered a situation where you forgot to shut down your servers leading to unexpected bills? It is a common problem faced by many organizations. However, with the potential of automation and scripting using Python, Boto3 and Lambda, we can effectively address this issue. The utilization of this technology can help us save time and resources, as well as prevent any potential financial setbacks. Lets get started.</p><p><strong>Key Terms To Remember:</strong></p><p><strong>Boto3: </strong>the Amazon Web Services (AWS) Software Development Kit (SDK)<strong> </strong>for Python.</p><p><strong>Python: </strong>Python is an easy-to-learn, interpreted, object-oriented, high-level programming language that uses built-in data structures and dynamic typing. It is ideal for Rapid Application Development and can also be used as a glue language to connect existing components.</p><p><strong>Lambda: </strong>AWS Lambda is a compute service that lets you run code without provisioning or managing servers.</p><p><strong>Serverless:</strong> Allows you to build and run applications and services without thinking about servers.</p><p><strong>Cloud 9: </strong>AWS Cloud 9 is a cloud-based IDE that lets you code with a browser. It includes a code editor, debugger, and terminal, and comes with essential tools for popular programming languages like Python and JavaScript. No need to install files or configure your machine for new projects.</p><p><strong>EC2:</strong> Amazon Elastic Compute Cloud is a web service that provides secure, resizable compute capacity in the cloud.</p><p><strong>IAM:</strong> Entities you create and assign specific permissions to that allow trusted identities such as workforce identities and applications to perform actions in AWS.</p><p><strong>Eventbridge</strong>: A serverless service that uses events to connect application components together, making it easier for you to build scalable event-driven applications.</p><p><strong>Objective 1</strong>: Create a python script that stops all running EC2 instances.</p><h3>Cloud 9</h3><p>We need to create a Cloud 9 environment before we can create our python script.</p><p>Log into your AWS console and type Cloud 9 into the search box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hrdWj5IsZAY0UJMLJqtvVQ.png" /></figure><p>Click “Create environment”.</p><p>Name = <strong>BA-Cloud-9.</strong></p><p>Description = <strong>Demo Cloud 9 environment.</strong></p><p>Environment type = <strong>New EC2 instance.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IBvNMePrDGxC9m4bInXXLg.png" /></figure><p>Instance type = <strong>t2.micro (1 GiB Ram +1 vCPU).</strong></p><p>Platform = <strong>Amazon Linux 2023.</strong></p><p>Timeout = <strong>30 minutes.</strong></p><p>Network settings = <strong>AWS Systems Manager (SSM).</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TFP4myWWpvzHfOa2tfOkig.png" /></figure><p>Click “Create”.</p><p>Now that our Cloud 9 is created click “Open”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DSBsyngkg4sO3Kgh3NCLEg.png" /></figure><p>Now we are in our Cloud 9 environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D6PLkDYIvPmIjM8Y4xbhuQ.png" /></figure><h3>Creating the Python Script</h3><p>To create a python file click<strong> File</strong> -&gt; <strong>New File From Template</strong> -&gt;<strong>Python File</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*JQK9FgstHzwZV606G9BITg.png" /></figure><p>Before we start our script we need to first create some EC2 instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ExAaLPSpAGrieysrWZzKaw.png" /></figure><p>Now that we have our EC2 instances running lets create our python script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*OLuYdMNurJJrAcdHo3nnwA.png" /></figure><p>Script code below:</p><pre>import boto3 <br><br>ec2 = boto3.client(&#39;ec2&#39;)<br><br>response = client.stop_instances(<br>    InstanceIds=[<br>        &#39;i-0325521c39870a409&#39;, &#39;i-0926d9b632814d3cb&#39;, &#39;i-04991f674eedc55af&#39;<br>    ],<br>)<br><br>print(response)</pre><p>Let’s break down the code:</p><p><strong>Import Boto3</strong>: Imports the Boto3 library from AWS which is offically used run Python on AWS.</p><p><strong>ec2 = boto3.client(‘ec2’)</strong>: Starts the communication with EC2 instances allowing to start or stop instances.</p><p><strong>response = ec2.stop_instances( InstanceIds=[‘i-0325521c39870a409’, ‘i-0926d9b632814d3cb’, ‘i-04991f674eedc55af’],): </strong>Lists all the EC2 instance ID’s and stops the instances from running.</p><p><strong>print(response): </strong>Displays the response code from the EC2 instances stopped.</p><p>Now lets run our script by clicking the green run button on top or bottom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uatpUI0gfxZ1r48dysqGzg.png" /></figure><p>Success, our python script was successful and the Dev. Lab EC2 instances have stopped running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*c0EKqmlCXXdvTQc_ZYzwhw.png" /></figure><p>Now lets save our python script.</p><p><strong>File </strong>-&gt; <strong>Save as</strong> -&gt; <strong>Python-Projects-BA -&gt; Save.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*bJOOgBSB8u5Dx_rojdhOqQ.png" /></figure><p>Congratulations you have successfully created a python script that stops running EC2 instances.</p><p><strong>Objective 2:</strong> Create a Lambda function using Python 3.8 or higher runtime to run your script.</p><h3>IAM Roles and Permissions</h3><p>Before we create our Lambda function we need to create a IAM Role permission for our EC2 instances to communicate with Lambda.</p><p>In the search bar type <strong>IAM</strong> and click <strong>Roles.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*VrfylHcMIp5dOl1OOufroQ.png" /></figure><p>Click “Create role”.</p><p>Trusted entity type: <strong>AWS Service</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ftqOb8x8FyHojvxvuKtAg.png" /></figure><p>Use Case: <strong>Lambda.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JLzosFageBfUSRJ_5A_qEQ.png" /></figure><p>Click next.</p><p>In the P<strong>ermissions policies</strong> section search for <strong>AmazonEC2FullAccess</strong> to allow Lambda to access the EC2 instances.</p><p>( Note, In a professional production environment, it is recommended to exercise caution in granting users full permissions. Instead, it is advisable to limit access to only what is necessary for their roles. This approach not only enhances security but also promotes accountability and compliance with relevant regulations.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zBEi3HWExxaqV8h4SpJbeQ.png" /></figure><p>Click next.</p><p>Role name: <strong>EC2AccessforLambda</strong></p><p>Description:<strong> Allows Lambda functions access to EC2 instances.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*3ZK9KJACXP3cZJyrRCvbuA.png" /></figure><p>Trust Policy:</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;sts:AssumeRole&quot;<br>            ],<br>            &quot;Principal&quot;: {<br>                &quot;Service&quot;: [<br>                    &quot;lambda.amazonaws.com&quot;<br>                ]<br>            }<br>        }<br>    ]<br>}</pre><p>The Trust Policy allows Lambda to be assigned to the role.</p><p>Click “Create role”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sx9i6I_VQ0P6nNIV4NctaQ.png" /></figure><p>Our role has been successfully created.</p><p>A Inline policy needs to be created in order for the lambda to run the code to stop a EC2 instance.</p><p>Click the EC2AccessforLambda role, click add permission, then click on create inline policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SefL4ZRcNq0trVERRpb_Lw.png" /></figure><p>Select EC2 in the service section.</p><p>Actions allowed: <strong>stopinstances.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZe8M4V6kAyXfZ3mv7qwKA.png" /></figure><p>click “ Add ARN”.</p><p>Resource region:<strong>us-east-1</strong></p><p>Resource instance: <strong>i-0325521c39870a409, i-0926d9b632814d3cb, i-04991f674eedc55af</strong></p><p>Resource ARN:<strong> arn: arn:aws:ec2:us-east-1:459384845622:instance/i-0325521c39870a409, i-0926d9b632814d3cb, i-04991f674eedc55af</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oacqu_XczUlAOGCIlBz9dQ.png" /></figure><p>Click next.</p><p>Policy name: <strong>StopEC2Policy.</strong></p><p>click “Create Policy.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r6vz5Pi9qT4Dwosdnz2f5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gIhHVDXH07sSIBp7sGHbtw.png" /></figure><h3>Lambda Functions</h3><p>Now let’s create a Lambda function using our python code. In the search bar type “Lambda”.</p><p>Click “Create Function”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cISKiwYFXMcWJPbQkCTm8Q.png" /></figure><p>Create function = <strong>Author from scratch</strong>.</p><p>Function name = <strong>StopEC2Function</strong>.</p><p>Runtime = <strong>Python 3.8</strong>.</p><p>Architecture = <strong>x86_64</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6qWBfuv0thSfOf5Qkz-fmw.png" /></figure><p>Execution role: <strong>Use an existing role.</strong></p><p>Existing role: <strong>EC2AccessforLambda.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bpspsKYPV8WsufmV8plYRg.png" /></figure><p>Click “Create function”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/208/1*NOTh2Mum4H-H2UUN5bkzsw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UZxTRSszhDfJFG4uxAoXJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X-zVWs2BKqspovknDHIxBg.png" /></figure><p>Lambda code:</p><pre><br>import boto3<br><br>region =&#39;us-east-1&#39;<br><br>instances = [&#39;i-0325521c39870a409&#39;, &#39;i-0926d9b632814d3cb&#39;, &#39;i-04991f674eedc55af&#39;]<br><br>def lambda_handler(event,context):<br>    <br>    ec2 = boto3.client(&#39;ec2&#39;, region_name=region)<br>    ec2.stop_instances(InstanceIds=instances)<br>    print( &#39;stopped your instances: &#39; +str(instances))</pre><p>Break down of code:</p><p><strong>import Boto3: </strong>Imports the Boto3 library from AWS which is offically used run Python on AWS.</p><p><strong>region = ‘us-east-1’:</strong> Region where the services are located.</p><p><strong>instances = [‘i-0325521c39870a409’, ‘i-0926d9b632814d3cb’, ‘i-04991f674eedc55af’]: </strong>Lists all the EC2 instance ID’s.</p><p><strong>def lambda_handler(event,context): </strong>Defines the Lambda function handler.</p><p><strong>ec2 = boto3.client(‘ec2’, region_name=region): </strong>Creates a EC2 instance in a specific region.</p><p><strong>ec2.stop_instances(InstanceIds=instances):</strong> Stops the specified instances.</p><p><strong>print( ‘stopped your instances: ‘ +str(instances)): P</strong>rints the message that confirms that the EC2 instances have stopped.</p><p>Click “Test”.</p><p>Event name: <strong>StopEC2Event.</strong></p><p>Event shaing settings: <strong>Private.</strong></p><p>Click “Save”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e2KmkQCRgA3zoOgd_pKFyw.png" /></figure><p>Click “Deploy”.</p><p>Click “Test”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IR_7VAZEegrO4A7epoODyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*c0EKqmlCXXdvTQc_ZYzwhw.png" /></figure><p>Success, the Lambda code ran successfully and the Dev. Lab EC2 Instances stoped running.</p><p><strong>Objective 3: </strong>Add a trigger to the Lambda to ensure it runs on a set schedule daily. No one should be working past 7pm.</p><h3>Trigger configuration</h3><p>Click “Add trigger”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*onmSq75vQ2vKX6NMhbZmJQ.png" /></figure><p>Trigger configuration: <strong>EventBridge (CloudWatch Events)</strong></p><p>Rule: <strong>Create a new rule</strong>.</p><p>Rule name: <strong>EventSchedule</strong>.</p><p>Rule description:<strong> Schedule test</strong>.</p><p>Rule type:<strong> Schedule expression</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*yXoZErVKP4rOUqDp0ZCezw.png" /></figure><p>Schedule Expression: <strong>cron(0 19 * * ? *), </strong>this is going to set our time for 7pm daily.</p><pre>cron(0 19 * * ? *)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*A7xCdY7vLZCmK6xgvtfqzA.png" /></figure><p>Click “Next”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OyHTu2Nrx411O6ZWaP7q3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gNWcKQX32KAGyNR-asazyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*_RueSmTfVA5l3J-8oj153g.png" /></figure><p>The Lambda trigger has been successfully enabled!</p><p><strong>Objective 4: </strong>Add code to Github.</p><h3>Github</h3><p>There are many ways to push your code to Github but im using Cloud 9 for this example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YpJ2rK0TVMdv5VcXWPpyAg.png" /></figure><p>My repository for this project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sq2qMw5TrP945fQUJUU5ZA.png" /></figure><p>The two Python files that was pushed to my Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*anj1otyAA9sZbB2bPlKCqw.png" /></figure><p>Github link: <a href="https://github.com/NBTOONS45/Python-Projects-BA">https://github.com/NBTOONS45/Python-Projects-BA</a></p><p><strong>Conclusion: </strong>With the implementation of Python and Lambda functions, we have successfully shut down the Dev. Lab EC2 instances, resulting in good cost optimization practices with the DevOps engineering team. Adding a trigger so that the instances shut off at 7 p.m. weekly ensures that no additional costs will occur outside business hours.</p><h3>Issues/Fixes:</h3><ol><li>bash: line 14: module &amp;&amp; echo : command not found<br>bash: line 15: To: command not found<br>Requirement already satisfied: ikp3db in /usr/local/lib64/python3.9/site-packages (1.4.2)<br>WARNING: Running pip as the ‘root’ user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: <a href="https://pip.pypa.io/warnings/venv">https://pip.pypa.io/warnings/venv</a><br>bash: -c: line 17: unexpected EOF while looking for matching `’’</li></ol><p><strong>Solution:</strong> Update pip3 in bash using<strong> “sudo yum update” and “sudo yum install python3-pip”</strong>. Make sure when naming your python file that you don’t use any special characters.</p><p>2. {<br> “errorMessage”: “Syntax error in module ‘lambda_function’: invalid syntax (lambda_function.py, line 9)”,<br> “errorType”: “Runtime.UserCodeSyntaxError”,<br> “stackTrace”: [<br> “ File \”/var/task/lambda_function.py\” Line 9\n print ‘stopped your instances: ‘ +str(instances)\n”<br> ]<br>}</p><p>Function Logs<br>START RequestId: 9b65bc3d-b3bd-46c3–84c0-a6dc91f5f028 Version: $LATEST<br>[ERROR] Runtime.UserCodeSyntaxError: Syntax error in module ‘lambda_function’: invalid syntax (lambda_function.py, line 9)<br>Traceback (most recent call last):<br> File “/var/task/lambda_function.py” Line 9<br> print ‘stopped your instances: ‘ +str(instances)END RequestId: 9b65bc3d-b3bd-46c3–84c0-a6dc91f5f028<br>REPORT RequestId: 9b65bc3d-b3bd-46c3–84c0-a6dc91f5f028 Duration: 10.94 ms Billed Duration: 11 ms Memory Size: 128 MB Max Memory Used: 39 MB Init Duration: 123.27 ms</p><p>Request ID<br>9b65bc3d-b3bd-46c3–84c0-a6dc91f5f028</p><p><strong>Solution:</strong> My Lambda code when trying to print did not have “<strong>(</strong>“ after print and and another “<strong>)</strong>” at the end.</p><p><strong>print( ‘stopped your instances: ‘ +str(instances))</strong></p><p>3. Make sure your code is case sensitive, I needed to change my i to a I in InstanceIds under ec2.stop_instances(InstanceIds=instances).</p><p>Follow me on Medium for more cloud blogs and add me on LinkedIn.</p><p>LinkedIn: <a href="https://www.linkedin.com/in/babatundeaborisade/">https://www.linkedin.com/in/babatundeaborisade/</a></p><p>Github: <a href="https://github.com/NBTOONS45/Python-Projects-BA">https://github.com/NBTOONS45</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6acafe976e91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Scalability: Utilizing the Power of Virtual Private Cloud, Autoscaling Groups, and Load…]]></title>
            <link>https://medium.com/@babatunde.aborisade1/optimizing-scalability-utilizing-the-power-of-virtual-private-cloud-autoscaling-groups-and-load-2640db6b51c7?source=rss-a5a8b319b1ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/2640db6b51c7</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[autoscaling]]></category>
            <category><![CDATA[vpc]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Babatunde Aborisade]]></dc:creator>
            <pubDate>Wed, 24 Jan 2024 04:42:46 GMT</pubDate>
            <atom:updated>2024-01-31T10:07:00.092Z</atom:updated>
            <content:encoded><![CDATA[<h3>Optimizing Scalability: Utilizing the Power of Virtual Private Cloud, Autoscaling Groups, and Load Balancers on AWS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fSSvEOk1NQcb8ZOEuSMKyw.png" /></figure><p>When transitioning your network to the cloud, it is crucial to prioritize its security. To achieve this goal, It is recommended to utilize a Virtual Private Cloud. By integrating Autoscaling Groups and Load Balancers into your network, you can establish a reliable foundation to perform cloud-related tasks. In this tutorial, we will begin this process and ensure the security and success of our network in the cloud for our client, Level Up Bank.</p><h4>Key Terms To Remember:</h4><p><strong>Virtual Private Cloud</strong>: A secure, isolated private cloud hosted within a public cloud.</p><p><strong>Subnets:</strong> A network inside a network.</p><p><strong>CIDR Block: </strong>An IP address allocation method that improves data routing efficiency on the internet.</p><p><strong>Autoscaling Group: </strong>A<strong> </strong>collection of EC2 instances that are treated as a logical grouping for the purposes of automatic scaling and management.</p><p><strong>Application Load Balancer: </strong>Distributes incoming application traffic across multiple targets, such as EC2 instances, in multiple Availability Zones. This increases the availability of your application.</p><p><strong>Security Group:</strong> Controls the traffic that is allowed to reach and leave the resources that it is associated with.</p><h3>Scenario: Level Up Bank wants to use AWS to move its network into the cloud.</h3><p><strong>Objective 1</strong>: Create a VPC, Security Group, subnets , Autoscaling Group and Load Balancer.</p><h3>Creating a VPC</h3><p>Go into your AWS console and search for <em>VPC</em>, and click <em>Create VPC</em>.</p><p><strong>VPC Name</strong>: Level_Up_VPC.</p><p>For this example, we are using <em>IPv4 CIDR manual input.</em></p><p>Type in <strong><em>IPv4 CIDR:</em></strong><em> 10.10.0.0/16.</em></p><p>Select <em>No IPv6 CIDR block.</em></p><p><strong>Tenancy<em>:</em></strong><em> </em>Set to <em>Default.</em></p><p>Click <em>Create</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*d8uU3m3FYYodBuvn0MywhA.png" /><figcaption><strong>Creating a VPC</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*La-Yb2vAUPHjLmsNq2JO0A.png" /><figcaption><strong>VPC Outcome</strong></figcaption></figure><h3><strong>Subnets</strong></h3><p>Next go into Subnet settings.</p><p>The Subnet name is <strong>Level_UP_Subnet1.</strong></p><p>For availability zone, select <strong>US East (N. Virgina/ us-east-1a).</strong></p><p>For IPv4 VPC CIDR block. Select <strong>10.10.0.0/16.</strong></p><p>For IPv4 subnet CIDR block. Select <strong>10.10.1.0/24.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*v-XcJh9CtEpako3Q1uZVKw.png" /><figcaption><strong>Creating Subnet 1</strong></figcaption></figure><p><strong>Subnet name:</strong> Level_Up_Subnet2.</p><p><strong>Avaiability Zone:</strong> US East (N. Virginia)/ us-east-1a.</p><p><strong>IPv4 Subnet CIDR block:</strong> 10.10.2.0/24.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*qd_Tk0Y8uutKRslHV4ewtA.png" /><figcaption><strong>Creating Subnet 2</strong></figcaption></figure><p><strong>Subnet name:</strong> Level_Up_Subnet3.</p><p><strong>Avaiability Zone:</strong> US East (N. Virginia)/ us-east-1a.</p><p><strong>IPv4 Subnet CIDR block:</strong> 10.10.3.0/24.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*q08m3vtGkGj7eSc8JrRqhA.png" /><figcaption><strong>Creating Subnet 3</strong></figcaption></figure><p>Click <em>Create subnet.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gZzFeEC54rY9ecsCtQ08RA.png" /></figure><h3><strong>Creating Autoscaling Group</strong></h3><p>After creating subnets, we will create an autoscaling group. <br>Type <strong><em>Auto Scaling Group</em></strong> in the search bar, and click <strong><em>Create Auto Scaling Group.</em></strong><br><strong>Auto Scaling group name:</strong> Level_Up_ASG.<br>Create a <strong>Launch template</strong>. (Note: <em>Creating a launch template is the same process as creating an EC2 instance).</em><br><strong>Template name: </strong>Level_Up_Template.<br><strong>AMI: </strong>Amazon Linux.<br><strong>Instance Type</strong>: t.2 micro.<br><strong>Key pair</strong>: Level_Up_Bank_Keypair.<br><strong>Security Group</strong>: Level_Up_SG.</p><p>In the Advanced section, <em>paste </em>this code to install Apache:</p><pre>#!/bin/bash<br>yum update -y<br>yum install -y httpd<br>systemctl start httpd<br>systemctl enable httpd<br>echo &#39;&lt;center&gt;&lt;h1&gt;This Amazon EC2 instance is running Apache!&lt;/h1&gt;&lt;/center&gt;&#39; &gt; </pre><p>Click <strong>Create launch </strong>template.</p><p>Return back to your autoscaling group, and add the<strong> launch template</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dzl_OesGmTdIIu02cmRwfw.png" /></figure><p>Click <em>Next</em>.</p><p>Select the <em>Level_Up_VPC</em> and the the three subnets that were created in the <strong><em>Network section</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*tmsHOTfsJo36DIvqYUv6Rw.png" /></figure><p>Click <em>Next</em>.</p><p><em>Skip </em><strong><em>Creating a load balancer. </em></strong>We will create one later.</p><p>For the Auto Scaling group, set the <strong><em>desired capacity</em></strong> scaling limit to a minimum of two. And the maximum desired capacity scaling limit is set to five.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*1iaWoeq1Y5BaFWSorElQvA.png" /></figure><p>Keep clicking <em>Next,</em>the autoscaling group is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8jG4KC7c-nX-itmGghjxOA.png" /></figure><h3><strong>Load Balancer</strong></h3><p>In the search bar, look for <strong>Create Load Balancer</strong> and click <strong><em>Creat</em>e</strong>.</p><p>The following should be listed :<br><strong>Load Balancer Types</strong>: Application Load Balancer.<br><strong>Load Balancer Name</strong>: Level-Up-ALB.<br><strong>VPC: </strong>Level_Up_VPC.<br><strong>Mappings:</strong> us-east-1a (Level_Up_Subnet2).<br><strong>Security Group:</strong> Level_Up_SG.<br><strong>Target Group</strong>: Level-Up_TG.<br>Click <strong><em>Create Load Balancer</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rppk62DG26_aLsEL5EsUPA.gif" /></figure><h3><strong>Web Security Group</strong></h3><p>Go to the <strong><em>Security group</em></strong> section, and Create a new security group.</p><p><strong>Name:</strong> Level_Up_LoadBalancer_ALB.</p><p>Set Inbound ports: <strong>80 to 0.0.0.0/0</strong> and outbound all traffic to <strong>0.0.0.0/0 (Disclaimer: In a real world setting </strong><a href="http://0.0.0.0/0"><strong>0.0.0.0/0</strong></a><strong> would not be advised. This would be open to the public, and your network would be compomised.)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Tmqxyil05j0UKuBamo-Xw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7rotENAPN7wHAZOfq6i1DQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iqoKPAPTkHalAmRVDQj12w.png" /></figure><p>Now, let’s verify that access to the instance isn’t working after creating the security group for the Load Balancer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ZOZyMG4NUN1D9ix_IUmRg.png" /></figure><h3>DNS URL</h3><p>Let’s verify that we can access the Load Balancer by copying the DNS URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PGPIMr05L5kthIs2myxMfw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*mDQLVAK285VWuwPuWsV2eQ.png" /></figure><p>Success!!!</p><p><strong>Objective 2</strong>: Add a target scale policy to the Autoscaling group and stress test it.</p><h3><strong>Adding Target Scale Policy to Autoscaling Group</strong></h3><p>In the <strong><em>Autoscaling Group </em></strong>section, Click on <strong><em>Automatic scalin</em>g</strong>. Select <strong><em>Create</em></strong> <strong><em>Dynamic scaling policy</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nduQ0nPzMf2iRcmofgjVGQ.png" /></figure><p>The dynamic scaling policy should be set to <strong><em>default</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*BE_SPueb9tetXmPqz8vm0w.png" /></figure><p>Next, we will SSH into one of our EC2 instances to perform a stress test.</p><p>Make sure you are the root user.</p><p>Run this command to install the stress test:</p><pre>yum install stress -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YcMHsLWyR8E_mdTGvyL18Q.png" /></figure><p>To perform the stress test, run this command:</p><pre>stress --cpu 6--timeout 300</pre><p>Returning to our instance and looking at the<em> </em><strong><em>CPU section</em></strong><em> </em>shows that it has jumped to over 80%, creating new EC2 instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kaa6cWGrQWDoG9sNzeX8cg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QpqxfhmHZRNboXdZ4Y6Tmw.png" /></figure><p>The stress test was performed successfully!</p><h4><strong>Issues/Fixes:</strong></h4><ol><li>The Load Balancer from the auto-scaling group would not let me attach the subnet; the solution was to create a load balancer separately and connect it to the auto-scaling group.</li><li>Load Balancer didn’t recognize the custom VPC. I created an Internet Gateway and attached the custom VPC to fix this. I made a new Subnet in a different Availability Zone to create the Load Balancer.</li><li>Traffic from the Route table was not connecting to the Internet Gateway. I solved this issue by going to the route table and allowing traffic by setting the destination to 0.0.0.0/0 and attaching the Internet Gateway.</li></ol><p><strong>Conclusion</strong>: Moving Level Up Bank’s network onto AWS has allowed them to utilize AWS’s resources in the cloud. By creating a VPC, autoscaling group, security group, and Load Balancer, Level Up Bank has been able to secure its network and regulate the flow of web traffic based on the demand of its servers, resulting in a stable environment to continue to provide its customers with excellent service while operating in the cloud.</p><p>Follow me on Medium for more cloud blogs and add me on LinkedIn.</p><p>LinkedIn: <a href="https://www.linkedin.com/in/babatundeaborisade/">https://www.linkedin.com/in/babatundeaborisade/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2640db6b51c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DynamoDB, the dynamite way of making tables!]]></title>
            <link>https://medium.com/@babatunde.aborisade1/dynamodb-the-dynamite-way-of-making-tables-1d1e5c1853e2?source=rss-a5a8b319b1ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d1e5c1853e2</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[dynamodb]]></category>
            <dc:creator><![CDATA[Babatunde Aborisade]]></dc:creator>
            <pubDate>Thu, 07 Dec 2023 19:18:05 GMT</pubDate>
            <atom:updated>2023-12-09T02:47:33.065Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X-FbUbUO0Hr6HBLoEPSn3Q.png" /></figure><h3><strong>What is Dynamo DB?</strong></h3><p><strong>DynamoDB</strong> is a<strong> </strong>fully managed, serverless, NoSQL database built for high-performance apps. DynamoDB features built-in security, continuous backups, automated multi-region replication, in-memory caching, and data import/export tools.</p><p><strong>Key Terms To Remember:</strong></p><p><strong>Database</strong>: A database is an organized collection of structured information or data stored electronically in a computer system.</p><p><strong>Table</strong>: A table is a collection of related data in a table format within a database. It consists of columns and rows.</p><p><strong>Partition Key</strong>: A simple primary key comprises one attribute known as the partition key.</p><p><strong>Attribute:</strong> A name or value, which can be scalars, sets, or document types.</p><p><strong>String</strong>: A sequence of characters used to represent text.</p><p><strong>Serverless:</strong> Allows you to build and run applications and services without thinking about servers.</p><p><strong>EC2: </strong>Amazon Elastic Compute Cloud is a web service that provides secure, resizable compute capacity in the cloud.</p><p><strong>IAM:</strong> Entities you create and assign specific permissions to that allow trusted identities such as workforce identities and applications to perform actions in AWS.</p><p><strong>CLI:</strong> A text-based interface where you can input commands that interact with a computer’s operating system.</p><p><strong>JSON:</strong> A standard text-based format for representing structured data based on JavaScript object syntax.</p><p><strong>NoSQL:</strong> An approach to database design that enables the storage and querying of data outside the traditional structures found in relational databases.</p><p><strong>Objective 1 </strong>: Create a DynamoDB Table and include 10 Items in the table.</p><h3><strong>Scenario:</strong> Let’s Go! Media Inc. needs our help to create a table using DynamoDB on AWS.</h3><h3>1.) Creating the table.</h3><p>On your AWS Console, type <strong>DynamoDB</strong> into the search bar. To create a table, click <em>Create Table</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cQ9gpPpWZdNWWnrlRn7Pyg.png" /></figure><p>Table name:<strong> Food_Table.</strong></p><p>Partition key: <strong>Food_id.</strong></p><p>Table settings: <strong>Default.</strong></p><p>Click <em>Create Table</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*0bEPFTntvNdKUkW52mChmA.png" /></figure><h3>2.) Table items.</h3><p>Select the <strong>Food_Table</strong> and click <em>Explore Table Items</em>.</p><p>To add items to the Table, click on <em>Create Item</em>.</p><p>Create attributes for <strong>F<em>ood Name, Shape, Color, and Origin</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fjXMQ73ZjaZLhPmSJ95rPQ.png" /></figure><p>We are going to create items for ten other foods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gOXlfqwRTyVF0jcsPYS8eg.png" /></figure><p>Now, let’s create an EC2 instance for our DynamoDB Table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5kdht6394NhpSpNM314q9Q.png" /></figure><h3>3.) Assigning an IAM Role.</h3><p>For the next step, we need to attach an<strong> IAM Role</strong> to the EC2 instance. This allows it to only read the tables on DynamoDB. Go to <strong><em>IAM</em></strong> in the search bar, click <em>Roles</em>, and click <em>Create Role</em>.</p><p>Trusted Identity:<strong> AWS Service.</strong></p><p>Use Case: <strong>EC2</strong></p><p>Search for <strong>AmazonDynamoDBReadOnlyAccess</strong> and click <em>Next</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bHmOhcwIEdV_sK9Tuy1HPQ.png" /></figure><p>Role name: <strong>ReadOnlyDynamoDB</strong></p><p>Description: Read access only for DynamoDB on EC2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*awLp1rWdklJW0WyUfuKH7g.png" /></figure><p>Go back to the EC2 instance and click on <em>Actions Security</em>; modify the IAM role to add the IAM role to your EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eCWf2yLwHwmvShxFi7v-GQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*62tSrWgG8qYgFAzAXeNVRw.png" /></figure><h3>4.) Scanning the table.</h3><p>Now, let’s scan the DynamoDB Table using the <em>AWS CLI</em>.</p><p>Use the <em>scan</em> command:</p><pre>aws dynamodb scan --table-name Food_Table</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*1xh_Q3Dz_JPvSOfMXhmkbg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*0RYH9Ken6QiZe4rSnN7_gg.png" /></figure><p>Use the <em>Put Command</em> to verify that we can not create any items in the table:</p><pre>aws dynamodb put-item --table-name Food_Table --item &#39;{&quot;Food_id&quot;:{&quot;S&quot;:&quot;11&quot;},&quot;Color&quot;:{&quot;S&quot;:&quot;Yellow&quot;},&quot;Food Name&quot;:{&quot;S&quot;:&quot;Noodles&quot;}, &quot;Origin&quot;:{&quot;S&quot;:&quot;China&quot;},&quot;Shape&quot;:{&quot;S&quot;:&quot;Cylinder&quot;}}&#39;</pre><p>The outcome should be <strong>AccessDeniedException,</strong> because the IAM Role only <em>allows read access </em>to the DynamoDB through the EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T1Lu7XJlXdNTVh_Pc07Ozg.png" /></figure><p>Success!!! The IAM Role attached to the EC2 Instance has blocked us from creating a new table entry into the DynamoDB table.</p><p><strong>Objective 2:</strong> Create a table using the AWS CLI.</p><h3>5.) Using the CLI.</h3><p>First lets SSH into our EC2 instance using the Command Prompt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ZUpGSlI5QpCHOA-Dkmm_w.png" /></figure><p>JSON document created for new table:</p><pre>{<br>    &quot;TableName&quot;: &quot;Food_Table2&quot;,<br>    &quot;AttributeDefinitions&quot;: [<br>        { &quot;AttributeName&quot;: &quot;ID&quot;, &quot;AttributeType&quot;: &quot;S&quot; }<br>      ],<br>      <br>    &quot;KeySchema&quot;: [<br>      { &quot;AttributeName&quot;: &quot;ID&quot;<br>        , &quot;KeyType&quot;: &quot;HASH&quot; }<br>    ],<br>    &quot;ProvisionedThroughput&quot;: {<br>      &quot;ReadCapacityUnits&quot;: 5,<br>      &quot;WriteCapacityUnits&quot;: 5<br>    }<br>    <br>}</pre><p>Type the <em>create table</em> script into the command prompt:</p><pre> aws dynamodb create-table --cli-input-json file://\Users\Babor\Documents\AWS\DynamoDB\food-table2.json --region us-east-1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V_9WtUHxsxMHUDvlmVBZsA.png" /></figure><p>Now check to see if the table was created on DynamoDB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EmiPmd3Xvro5Um1-zIjTIA.png" /></figure><p>Success, the <strong>Food_Table2</strong> was created using the AWS CLI!</p><h3><strong>Issues/Fixes:</strong></h3><ol><li>“Error parsing parameter”. This occurs when your JSON code is not properly formatted correctly. I solved this issue by double-checking if I had an extra space or a colon sign.</li><li>Ensure you are signed into your EC2 instance when running any tests for your code, or you will receive errors because the code is pulling from your local machine and not AWS.</li><li>Double-check your attribute types and make sure they are correctly labeled as “S” for String, for example, in your code, and not another type.</li><li>Verify that your IAM Role is successfully attached to your EC2 instance by checking the instance summary and the IAM Role section.</li></ol><p><strong>Conclusion: </strong>Let’s Go! Media Inc. has recently created a table using DynamoDB, with the help of our team. We have organized their table structure in a serverless format, using AWS and CLI. This has helped Let’s Go! Media Inc. to reduce their provisioning and infrastructure costs and also enabled their data to be accessed more efficiently.</p><p>Follow me on Medium for more cloud blogs and add me on LinkedIn.</p><p>LinkedIn: <a href="https://www.linkedin.com/in/babatundeaborisade/">https://www.linkedin.com/in/babatundeaborisade/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d1e5c1853e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>