<?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 Olufemi Olusanya on Medium]]></title>
        <description><![CDATA[Stories by Olufemi Olusanya on Medium]]></description>
        <link>https://medium.com/@fkfemi?source=rss-d5fbcb855977------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*E1OA0o7xZsydZWoF7hvMdA.jpeg</url>
            <title>Stories by Olufemi Olusanya on Medium</title>
            <link>https://medium.com/@fkfemi?source=rss-d5fbcb855977------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 14:41:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fkfemi/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[How to deploy Jenkins with Terraform]]></title>
            <link>https://medium.com/@fkfemi/how-to-deploy-jenkins-with-terraform-970b6443d2fe?source=rss-d5fbcb855977------2</link>
            <guid isPermaLink="false">https://medium.com/p/970b6443d2fe</guid>
            <dc:creator><![CDATA[Olufemi Olusanya]]></dc:creator>
            <pubDate>Mon, 10 Apr 2023 00:48:02 GMT</pubDate>
            <atom:updated>2023-04-11T06:50:30.218Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*oebLNE5g3As3IjdXvH8WHA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8PMYC57dIJkQ5aUGxyIL6g.jpeg" /></figure><p>In this quick project I will be showing you all how to deploy Jenkins on AWS EC2 using Terraform. Here is the context of the exercise:</p><p>Your team would like to start using Jenkins as their CI/CD tool to create pipelines for DevOps projects. They need you to create the Jenkins server using Terraform so that it can be used in other environments and so that changes to the environment are better tracked. For the Foundational project you are allowed to have all your code in a single main.tf file (known as a monolith) with hardcoded data.</p><p>1. Deploy 1 EC2 Instances in your Default VPC.</p><p>2. Bootstrap the EC2 instance with a script that will install and start Jenkins. Review the official Jenkins Documentation for more information: <a href="https://www.jenkins.io/doc/book/installing/linux/">Jenkins Documentation</a></p><p>3. 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>4. Create a S3 bucket for your Jenkins Artifacts that is not open to the public.</p><p>Prerequisites</p><p>- AWS Console Account</p><p>- Cloud9</p><p>- Terraform installed on your device</p><p>Now let’s begin the project. The first step we need to take is to check if terraform is installed. We can check by using the command:</p><pre>terraform -help</pre><p>If terraform is not installed you will get an error. If it is, you will get a list of help options. If you don’t have terraform installed on Ubuntu for example, use this command:</p><pre>sudo apt update</pre><pre>sudo yum install terraform</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zFipWs837uLiLq4L8loz7Q.png" /></figure><p>Now that we have Terraform installed, we now need to create a directory that will house the files that will carry our commands. To create the directory, use the following command:</p><pre>mkdir &lt;yourdirname&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*twl3FK7as0_stAu8ViQcCQ.png" /></figure><p>Now we are going to create 4 files to carry our commands that will initiate Terraform, create EC2 instance, install and activate Jenkins and build and deploy S3 bucket. We are going to create the four files in the directory that we just created. Use this command to create a file:</p><pre>touch &lt;file name&gt;</pre><p>The files should be created with the following name:</p><ul><li>touch main.tf</li><li>touch variables.tf</li><li>touch outputs.tf</li><li>touch providers.tf</li></ul><p>After creating the files, we can confirm by using the following command.</p><pre>ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*R6E1EKb2M2vBzGv9889a4g.png" /></figure><p>Now we are going to add commands to the files we created</p><p>The main.tf file will receive these commands:</p><pre># Create VPC Resources<br> <br> resource &quot;aws_vpc&quot; &quot;vpc&quot; {<br> cidr_block = var.vpc_cidr<br> <br> tags = {<br> Name = var.vpc_tag<br> }<br> }<br> <br> resource &quot;aws_subnet&quot; &quot;subnet&quot; {<br> vpc_id = aws_vpc.vpc.id<br> cidr_block = var.subnet_cidr<br> map_public_ip_on_launch = true<br> <br> tags = {<br> Name = var.subnet_tag<br> }<br> }<br> <br> resource &quot;aws_internet_gateway&quot; &quot;internet_gateway&quot; {<br> vpc_id = aws_vpc.vpc.id<br> <br> tags = {<br> Name = var.internet_gateway_tag<br> }<br> }<br> <br> resource &quot;aws_default_route_table&quot; &quot;default_route&quot; {<br> default_route_table_id = aws_vpc.vpc.default_route_table_id<br> <br> route {<br> cidr_block = &quot;0.0.0.0/0&quot;<br> gateway_id = aws_internet_gateway.internet_gateway.id<br> }<br> tags = {<br> Name = var.internet_gateway_tag<br> }<br> }<br> <br> resource &quot;aws_s3_bucket&quot; &quot;s3&quot; {<br> bucket = var.bucket_name<br> force_destroy = true<br> <br> tags = {<br> Name = var.bucket_name<br> }<br> }<br> <br> # Public IP and add to Security Group<br> <br> data &quot;external&quot; &quot;myipaddr&quot; {<br> program = [&quot;bash&quot;, &quot;-c&quot;, &quot;curl -s &#39;https://ipinfo.io/json&#39;&quot;]<br> }<br> <br> # Create EC2 Security Group and Security Rules<br> <br> resource &quot;aws_security_group&quot; &quot;jenkins_security_group&quot; {<br> name = var.security_group_name<br> description = &quot;Apply to Jenkins EC2 instance&quot;<br> vpc_id = aws_vpc.vpc.id<br> <br> ingress {<br> description = &quot;Allow SSH from MY Public IP&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> ingress {<br> description = &quot;Allow access to Jenkis from My IP&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> egress {<br> description = &quot;Allow All Outbound&quot;<br> protocol = -1<br> from_port = 0<br> to_port = 0<br> cidr_blocks = [&quot;0.0.0.0/0&quot;]<br> }<br> <br> tags = {<br> Name = &quot;Jenkins_Security_Group&quot;<br> }<br> }<br> <br> # Create EC2 Instance<br> <br> resource &quot;aws_instance&quot; &quot;jenkins_server&quot; {<br> ami = var.ami<br> instance_type = var.instance_type<br> key_name = var.ssh_key_name<br> subnet_id = aws_subnet.subnet.id<br> security_groups = [aws_security_group.jenkins_security_group.id]<br> user_data = var.ec2_user_data<br> <br> tags = {<br> Name = var.ec2_tag<br> }<br> }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*-oUy2G0JSKE1KsZpNYWSyw.png" /></figure><p>The variable.tf file will get these set of commands:</p><pre># Variables for main<br> <br> # VPC variables<br> <br> variable &quot;vpc_cidr&quot; {<br> description = &quot;VPC cidr block&quot;<br> type = string<br> default = &quot;10.0.0.0/16&quot;<br> }<br> <br> variable &quot;vpc_tag&quot; {<br> description = &quot;Name tag for VPC&quot;<br> type = string<br> default = &quot;W20-VPC&quot;<br> }<br> <br> variable &quot;subnet_tag&quot; {<br> description = &quot;Name tag for Subnet&quot;<br> type = string<br> default = &quot;W20-Subnet&quot;<br> }<br> <br> variable &quot;subnet_cidr&quot; {<br> description = &quot;Subnet cidr block&quot;<br> type = string<br> default = &quot;10.0.0.0/24&quot;<br> }<br> <br> variable &quot;internet_gateway_tag&quot; {<br> description = &quot;Name tag for Internet Gateway&quot;<br> type = string<br> default = &quot;W20-Internet-Gateway&quot;<br> }<br> <br> # S3 Variables<br> <br> variable &quot;bucket_name&quot; {<br> description = &quot;S3 bucket name&quot;<br> type = string<br> default = &quot;w20bucket&quot;<br> }<br> <br> # Security Group<br> <br> variable &quot;security_group_name&quot; {<br> description = &quot;Name for Security Group&quot;<br> type = string<br> default = &quot;Week 20 Security Group&quot;<br> }<br> <br> # EC2<br> <br> variable &quot;ami&quot; {<br> description = &quot;EC2 AMI&quot;<br> type = string<br> default = &quot;ami-06e46074ae430fba6&quot;<br> }<br> <br> variable &quot;instance_type&quot; {<br> description = &quot;EC2 instance type&quot;<br> type = string<br> default = &quot;t2.micro&quot;<br> }<br> <br> variable &quot;ssh_key_name&quot; {<br> description = &quot;SSH Key for EC2&quot;<br> type = string<br> default = &quot;luit-wk7-others&quot;<br> }<br> <br> variable &quot;ec2_user_data&quot; {<br> description = &quot;User data script for EC2&quot;<br> type = string<br> default = &lt;&lt;EOF<br> #!/bin/bash<br> # Install Jenkins and Java <br> sudo wget -O /etc/yum.repos.d/jenkins.repo \<br> https://pkg.jenkins.io/redhat-stable/jenkins.repo<br> sudo rpm - import https://pkg.jenkins.io/redhat-stable/jenkins.io.key<br> sudo yum -y upgrade<br> # Add required dependencies for the jenkins package<br> sudo amazon-linux-extras install -y java-openjdk11 <br> sudo yum install -y jenkins<br> sudo systemctl daemon-reload<br> <br> # Start Jenkins<br> sudo systemctl enable jenkins<br> sudo systemctl start jenkins<br> <br> # Firewall Rules<br> if [[ $(firewall-cmd - state) = &#39;running&#39; ]]; then<br> YOURPORT=8080<br> PERM=&quot; - permanent&quot;<br> SERV=&quot;$PERM - service=jenkins&quot;<br> <br> firewall-cmd $PERM - new-service=jenkins<br> firewall-cmd $SERV - set-short=&quot;Jenkins ports&quot;<br> firewall-cmd $SERV - set-description=&quot;Jenkins port exceptions&quot;<br> firewall-cmd $SERV - add-port=$YOURPORT/tcp<br> firewall-cmd $PERM - add-service=jenkins<br> firewall-cmd - zone=public - add-service=http - permanent<br> firewall-cmd - reload<br> fi<br> EOF<br> }<br> <br> <br> variable &quot;ec2_tag&quot; {<br> description = &quot;Tag for EC2&quot;<br> type = string<br> default = &quot;Jenkins_Server&quot;<br> }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*3o5rlaP_iRXFbKvD3rR2ew.png" /></figure><p>The outputs.tf file will receive:</p><pre># Terraform Outputs<br> <br> output &quot;ec2_public_ip&quot; {<br> description = &quot;Public IP address of the Jenkins EC2 instance&quot;<br> value = aws_instance.jenkins_server.public_ip<br> }<br> <br> output &quot;s3_bucket_uri&quot; {<br> description = &quot;S3 bucket URI&quot;<br> value = &quot;s3://${aws_s3_bucket.s3.id}&quot;<br> }<br> <br> output &quot;bucket_domain_name&quot; {<br> description = &quot;FQDN of bucket&quot;<br> value = &quot;https://${aws_s3_bucket.s3.bucket_domain_name}&quot;<br> }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*9uLaEPx4OsxAVWv04dd6DA.png" /></figure><p>The providers.tf file will receive:</p><pre># Terraform Providers<br> <br> terraform {<br> required_providers {<br> aws = {<br> source = &quot;hashicorp/aws&quot;<br> version = &quot;~&gt; 4.55.0&quot;<br> }<br> }<br> <br> required_version = &quot;&gt;= 1.3.0&quot;<br> }<br> <br> provider &quot;aws&quot; {<br> region = &quot;us-east-1&quot;<br> }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*4o3vKLE1oM09ETcLFDjuRA.png" /></figure><p>Now that our files have been updated with our codes, we will now run them. The first command is:</p><pre>terraform init</pre><p>This command will initiate Terraform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*9mDGvop2mFNhlUrVWKS0qg.png" /></figure><p>Then we will run this command:</p><pre>terraform plan</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*ub5ljbmTW7qp95w6bXVyhA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*3VlKN4h5bEZ2NBcqznVTFQ.png" /></figure><p>Then we will run this command to apply all the conditions of Terraform. The command is:</p><pre>terraform apply</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*7VZo0Ie_gJaxKdNZShej2A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*GqMojlOQ0bptxRc_3B1-5A.png" /></figure><p>Now that we have run all our commands the following have happened:</p><ul><li>An EC2 instance have been created</li><li>An S3 Bucket has been created</li></ul><p>The EC2 instance console now shows the newly created instance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*61-dGh-k3U0UIxJRpI1b2g.png" /></figure><p>If you go into the instance and get the public Ip address, add it to a browser with 8080 and you will be able to access the Jenkins “Unlock Jenkins” page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*uL0vmr_Mol-vvTZMrs_JXg.png" /></figure><p>If we go into our S3 “Account snapshot” you will see the newly created S3 Bucket</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lzv__1sJHhKiB8VRtbM74w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KHFdsUg3VywQgBwhIpquLg.png" /></figure><p>Now we will execute a command to turn off all the instances that have been created. The command is:</p><pre>terraform destroy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*F2cIG-ljj2rWHfX5i6IcCw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=970b6443d2fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Code any boto3 in AWS Lambda]]></title>
            <link>https://medium.com/@fkfemi/how-to-code-any-boto3-in-aws-lambda-e6961ca6c0f0?source=rss-d5fbcb855977------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6961ca6c0f0</guid>
            <category><![CDATA[boto3]]></category>
            <category><![CDATA[lamda]]></category>
            <dc:creator><![CDATA[Olufemi Olusanya]]></dc:creator>
            <pubDate>Mon, 10 Apr 2023 00:41:57 GMT</pubDate>
            <atom:updated>2023-04-10T07:18:26.529Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*qpXe9q71o78lCOHqV4tF-g.jpeg" /></figure><p>In this project we are going to Python, Lambda and the SQS queue to send out messages. Before we get started the first question is, what is Lambda?</p><p>AWS Lambda is a compute service that lets you run code without provisioning or managing servers. Lambda runs your code on a high-availability compute infrastructure and performs all of the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, and logging. With Lambda, you can run code for virtually any type of application or backend service. All you need to do is supply your code in one of the languages that Lambda supports.</p><p>Here are the steps that we will be taking to complete this project:</p><p>1. Create a Standard SQS Queue using Python.</p><p>2. Create a Lambda function in the console with a Python 3.7 or higher runtime</p><p>3. Modify the Lambda to send a message to the SQS queue. Your message should contain either the current time or a random number. You can use the built-in test function for testing.</p><p>4. Create an API gateway HTTP API type trigger.</p><p>5. Test the trigger to verify the message was sent.</p><p>6. All code should be inline commented.</p><p>Prerequisites</p><p>Before we start this project make sure you have an AWS account, and that you have installed the AWS SDK for Python (boto3) library.</p><p>1. Create a Standard SQS Queue using Python:</p><p>The first step that we will be taking is installing the AWS SDK for Python (boto3) library. This will be done by running the following command:</p><pre>pip install boto3</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uvgcofBa3wpr0g2d0wVmgQ.jpeg" /></figure><p>Next, we will run a python command to allow us create an SQS queue. The is the required command:</p><pre>import boto3<br><br># Create an SQS client<br>sqs = boto3.client(&#39;sqs&#39;)<br><br># Create a new standard SQS queue<br>response = sqs.create_queue(<br>    QueueName=&#39;my-queue&#39;<br>)<br><br># Print the queue URL<br>print(response[&#39;QueueUrl&#39;])</pre><p>After running the command, ta queue url is generated. This will be needed when setting up our Lambda function after a few more steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*yTClaB6tLpmgtRMjtZdTRg.jpeg" /></figure><p>1. Create a Lambda function in the console with a Python 3.7 or higher runtime:</p><p>To create our Lambda function, we need to take the following steps. First, we need to go to the AWS Management Console and navigate to the Lambda service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94OZFBDKLWK3HROloWcN5A.jpeg" /></figure><p>Click on the “Create function” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q1boUj3eRukaLzQ0_mXLdw.jpeg" /></figure><p>Then select “Author from scratch”, and give your function a name. Now choose “Python 3.7” or higher as the runtime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gB9wzep8g9_cA3_Q92Sluw.jpeg" /></figure><p>Now click “Create function”. You will now get a confirmation of the successful creation of the function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2s71K_OGx_Jv7RFhskKm6Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JTMPsUYPBUKYunqJLkTexw.jpeg" /></figure><p>In the “Function code” section, paste the following code:</p><pre>import json<br>import boto3<br>import datetime<br>import random<br><br># Set up the SQS client<br>sqs = boto3.client(&#39;sqs&#39;)<br><br># Get the URL of the SQS queue<br>queue_url = &#39;YOUR_QUEUE_URL&#39;<br><br>def lambda_handler(event, context):<br>    # Generate a message with either the current time or a random number<br>    message = {&#39;timestamp&#39;: str(datetime.datetime.now())}<br>    # message = {&#39;random_number&#39;: random.randint(1, 100)}<br><br>    # Send the message to the SQS queue<br>    sqs.send_message(<br>        QueueUrl=queue_url,<br>        MessageBody=json.dumps(message)<br>    )<br>        return {<br>        &#39;statusCode&#39;: 200,<br>        &#39;body&#39;: json.dumps(&#39;Message sent to SQS queue&#39;)<br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*SoaBro-_smVbgmhTP1J68A.jpeg" /></figure><p>1. Modify the Lambda to send a message to the SQS queue:</p><p>Replace YOUR_QUEUE_URL in the function with the URL of the SQS queue you created in step 1.</p><p>Uncomment either the message or random_number lines, depending on which type of message you want to send.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hRXg3dYbrzhV9Kn7KEDCAQ.jpeg" /></figure><p>2. Create an API Gateway HTTP API type trigger:</p><p>In the “Function overview” section click on “Add trigger”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UWEzrb4hM3T_ZhAJEDlsww.jpeg" /></figure><p>In the “Add triggers” section of the Lambda function page, click on the dropdown and select “API Gateway”. Under “Intent”, select “Create a new API”. Then choose “HTTP API” as the API type, and click on “Add”. You will get a confirmation page of a successful completion of the added function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*uO6GLs7vLvv4WBj-_hYm5A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f-w8MqkaM0gH9PRiTRb3rw.jpeg" /></figure><p>Click on the newly created API Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LEocjB-jqZ4yrxgLlW7RrQ.jpeg" /></figure><p>When it opens, click on “Routes” and then click on “Create” and choose a route key (e.g. “/send-message”) and then save the Route.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MRPzuTvrBuMVpLB5CipFzg.jpeg" /></figure><p>3. Test the trigger to verify the message was sent:</p><p>In the “Test” tab of the Lambda function page, under the “Test event action” select “Create a new event”, name the event, under “Event JSON” make sure it is with a payload like {‘key1’: ‘value1’, ‘key2’: ‘value2’}. Now click on the “Test” button. You will get an Execution result:succeeded result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*midy55Dg46015BJ1l0yhUg.jpeg" /></figure><p>Next to Execution result:succeeded result is a link to the “logs”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*tWAFEbthYz3D1tXABAuqPQ.jpeg" /></figure><p>Click the “logs”. In the “Log groups” select the output of your Lambda function for any errors. Also you can click on the “Details”, it will also give you some details on the event logs. It shows confirmation that our message was sent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yW7AOaZfQ8nteTFj0cpkLQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0g6ZVtIRv1BluaajbC89sA.jpeg" /></figure><p>Finally, check the function screen for the execution results to get confirmation of the sent message. It shows that the message was sent (“statusCode”: 200)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*29g053zYNwF0f7cOMFusRQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6961ca6c0f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Create EC2 Instances with Auto-Scaling]]></title>
            <link>https://medium.com/@fkfemi/how-to-create-ec2-instances-with-auto-scaling-1028f1ee801e?source=rss-d5fbcb855977------2</link>
            <guid isPermaLink="false">https://medium.com/p/1028f1ee801e</guid>
            <category><![CDATA[auto-scaling-groups]]></category>
            <category><![CDATA[ec2]]></category>
            <dc:creator><![CDATA[Olufemi Olusanya]]></dc:creator>
            <pubDate>Mon, 10 Apr 2023 00:37:34 GMT</pubDate>
            <atom:updated>2023-04-11T01:11:31.198Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tTwO6Anl5vxV3cgau5ElcA.jpeg" /></figure><p>In this project we will be creating EC2 Instances with auto-scaling. Now, I typically like to go into a lot of</p><p>details with my posts but we do have a lot of steps and images to go through here so I will try to go</p><p>straight to the point. I assure you all though that while there are a lot of steps, the process itself is pretty simple to understand.</p><p>What are we trying to achieve here:</p><p>1. Create a VPC with cidr 10.10.0.0/16</p><p>2. Create three public subnets with 10.10.1.0/24 &amp; 10.10.2.0/24 &amp; 10.10.3.0/24</p><p>3. Create an autoscaling group using t2.micro instances. All instances should have Apache installed on each instance with the ability to check any random IP address and be able to produce a test page. Ensure the autoscaling group is using the public subnets we just created in step 2.</p><p>4. The autoscaling min and max should be 2 and 5.</p><p>5. Create an Application Load Balancer to distribute traffic to the autoscaling group.</p><p>6. Create web server security group that allows inbound traffic from HTTP from your Application Load Balancer.</p><p>7. Create a load balancer security group that allows inbound traffic from HTTP from 0.0.0.0/0.</p><p>Here are out prerequisites:</p><p>a. AWS Account</p><p>b. How to use the AWS features (EC2, VPC etc.)</p><p>Here are the steps that we are going to take to execute this exercise:</p><p>1. Create a VPC with cidr 10.10.0.0/16</p><p>2. Create three public subnets with 10.10.1.0/24 &amp; 10.10.2.0/24 &amp; 10.10.3.0/24</p><p>3. Create an autoscaling group using t2.micro instances. All instances should have Apache installed on each instance with the ability to check any random IP address and be able to produce a test page. Ensure the autoscaling group is using the public subnets we just created in step 2.</p><p>4. Create an Application Load Balancer to distribute traffic to the autoscaling group.</p><p>5. Create EC2 Auto Scaling with min and max of 2 and 5.</p><p>6. Test to see if we have access to our Instances</p><p>Now let’s get this on the road.</p><p>1. Create a VPC with cidr 10.10.0.0/16</p><p>Our first step will be to create a VPC and ensure that the cidr is 10.10.0.0/16. To do so follow these steps:</p><ul><li>Log into your AWS account. In the console home select VPC (if it is not in your console home use the search option to search for it)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZHqgHwApZoXntQfMWk9Syg.jpeg" /></figure><ul><li>Select “Create VPC”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*WBJJNIv-8A5iq3elecHOug.jpeg" /></figure><ul><li>In the VPC settings page under “Resources to create” select “VPC only”. Under IPv4 CIDR input 10.10.0.0/16 and leave IPv6 CIDR block as default and click “Create VPC”. You will get a a confirmation of the successful creation of your VPC.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*BSQlUzz5EpfZ4qdCc-aSrQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DYAXWDviaWcybePi6saNKQ.jpeg" /></figure><p>2. Create three public subnets with 10.10.1.0/24 &amp; 10.10.2.0/24 &amp; 10.10.3.0/24</p><ul><li>After creating our VPC, select “Subnets” under the navigation pane. Then click “Create subnet”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V6OCIbbLx15itGAg1QHf4A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dznUxzRMulXcdJonzHyprg.jpeg" /></figure><ul><li>Under VPC ID select the VPC we created then select “Create subnet”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*X_6oeN6PmAQTB3n--I5Qxg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*PdjUDLyLyT6x9hnKPnZ-vw.jpeg" /></figure><ul><li>Under “Subnet settings”, give the subnet a name and choose the availability zone. The under IPv4 CIDR block, enter one of our public subnet addresses. When done, select “Add new subnet” to add the next subnet. We need to create a total of 3 subnets using 10.10.1.0/24 &amp; 10.10.2.0/24 &amp; 10.10.3.0/24 as our IPv4 CIDR block. When done, select “Create subnet”. You will now get success confirmation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*UsZff_-f5OYHpmZnzK70pw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*zKXmq7Bx6Yxvxc_hp8asXA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*bCBd8B_wmcgp75f1Aw9G_g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQP25r54CXxIO_XTGKgb3A.jpeg" /></figure><ul><li>Select our newly created subnet. Under “Action”, select “Edit subnet settings” and under “Auto-assign IP settings” select “Enable auto-assign public IPv4 address” and save.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7sX5GgaUhK5gylHUZ7NI0Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*mrY8x0jQOiS8gwnfmme0FQ.jpeg" /></figure><p>3. Create an autoscaling group using t2.micro instances. All instances should have Apache installed on each instance with the ability to check any random IP address and be able to produce a test page. Ensure the autoscaling group is using the public subnets we just created in step 2.</p><p>Now we are going to create our Internet gateway. To do so, in the navigation pane select “Internet gateways”.</p><ul><li>Click “Create internet gateway”. Enter a name tag and select “Create internet gateway”. You will get confirmation of the successful creation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6XEz4bBuyHzHbm0AkAZPeQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3mxRs7-eY4Yd4MIhtjaRQQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*pcPCuhHb_yt_jWhWfKfGmg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R-QKxap3FZwPhp-3kBsyAA.jpeg" /></figure><ul><li>Now we are going to attach our VPC to the Gateway. At the top of our success confirmation page after creating our Internet gateway, we are given an option to attach a VPC. Click on this to open it, select the VPC that we created and click “Attach internet gateway”. We will then get confirmation of the attachment</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*KTvN9KerqVVFlGnyvXERgQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7WOBpVh1FP4L4QXzYRGukQ.jpeg" /></figure><ul><li>Now we will create our Route tables next. Under the navigation pane select “Route tables” When in the route tables you will see that a route table has been created for us. Select the table, click on “Action”, select “Edit routes”. When open, select “Add route”. Under Destination enter “0.0.0.0/0” and under target enter the internet gateway we created. Then click save changes. We will get a confirmation that the route table has been updated.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mmUa4FjZ_q14UM7FVAJDSQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PKOAd6hGzS1204Y1yEoePQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W6TJMO8tVb6qaQjIuJouqQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CqHyeYD9iD5QuKC98swoew.jpeg" /></figure><ul><li>Now we will create our security group next. Go to the VPC home page, select “Security Groups”. Click “Create security group”. Give the security group a name, and add the VPC we created. Under “Inbound rules” select add rules. Under type add HTTP and under source add Anywhere. Now click “Create security group”. We will get success confirmation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*_-4OBIfkeDb91JOs-Ajtgg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G-bbiyenBJ-gAO_jSncxBA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qdio6cZGBG9uxg2ZpiuObA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZlfiBFvoGoCme6Mufjl99w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5FZk-TznOH75N_snXjxDZg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DCIwLpL4xYMkZcF2C2Z5HQ.jpeg" /></figure><p>- Now we are going to create our “Launch template”. To do so, go to the console home page, select EC2 and on the navigation pane, under “Instances” select “Launch Templates”. Then click “Create launch template”. Next give the template a name, under “Auto Scaling guidance” select “Providing guidance to help me set up a template…”.</p><p>Select “Quick Start”, and then select Amazon Linux. Under “Instance type” select “t2.micro”. Under “Network settings” (Firewall (security groups) select “Select existing security group”, then select the security group we created. Under “Advanced network configuration” (Network interface) add our security group to the security group tag and under “Auto-assign public IP” select “Enable”. Under “User data — optional” paste this command:</p><pre>#!/bin/bash<br>yum update -y<br>yum install -y httpd<br>systemctl start httpd<br>systemctl enable httpd<br>echo &quot;A wonderful world begins with coding&quot; &gt; /var/www/html/index.html</pre><ul><li>Now click “Create launch template”. We will then get a success confirmation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rMVdoZ7K0Rn6E87MInQlbw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bfDREAG7snpyYQG8gMfi7w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2JHSKtRuLAVlIEc0pF7v4Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*pxg49bJSakDHw4utHSSLFw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*ewB6xac5eYIU8csfwbsTNQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*Yt6XvAEEaeZz5iMt7tXIJQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*SnM0VWXRG__zkwEoAC_iVQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*-fBukTgoOBwtQa4nIOQsKg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*_zuM-wfsB_r6rT-XxXqGVw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*A7zdbtTNM1TxaEuOZ688Ug.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*wCskKl89uPpie0BbvhikZA.jpeg" /></figure><p>4. Create an Application Load Balancer to distribute traffic to the autoscaling group.</p><p>Now we are going to build our Load Balancers. To do so, go to the EC2 Dashboard and under “Resources” select “Load Balancers”. When open, select “Create Load Balancer”.</p><ul><li>Under load balancer type select “Application Load Balancer”. Under ‘Configure Load Balancer” give the load balancer a name, select internet facing and select HTTP as the load balancer protocol.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lRBq_OBr0C3F6k46dWCZhA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*Uj0vaAFvfp52XTxb3fRl8w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SEOoftR3NVwdjNluQ0nNow.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3Nm_YzYapQ4KHM0eNslPg.jpeg" /></figure><ul><li>Under the “Availability Zones”, add the VPC we created and the 3 subnets.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JuVnkvodg0fbyzDkdj0WfA.jpeg" /></figure><ul><li>Under “Configure Security Groups” add the security group we created</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fbm0slSfVEvXaRETyna3CA.jpeg" /></figure><ul><li>Under “Configure Routing” create a new target group with HTTP protocol</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ozrIWoSWdKTjJGns6vIawg.jpeg" /></figure><ul><li>Now select “Create” and get confirmation of success after.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OMcEnpwMi3cWBjPourXwow.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8OhtXkGtjKwPg9FPUyOF9Q.jpeg" /></figure><p>5. Create EC2 Auto Scaling with min and max of 2 and 5.</p><p>Now we are going to create our auto scaling. Here are the steps we are going to take.</p><ul><li>Go to EC2 home page and on the navigation, page select “Auto Scaling Groups”. When open, select “Create Auto Scaling group”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cxceqPKKV-YpyC4di2YTmA.jpeg" /></figure><ul><li>Give the group a name and under “Launch template” select the launch template we created</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*mKYSuzXLZETsOLyU_67WGw.jpeg" /></figure><ul><li>Under Network select our created VPC and the 3 subnets that we created.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*zUXOkJ0aZ--QmAhqCplYyA.jpeg" /></figure><ul><li>Under “Load balancing” select “Attach to an existing load balancer” and then “Choose from your load balancer target groups”, then select the target group we created.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*NIfAp8f1Do7YadvffFH-wQ.jpeg" /></figure><ul><li>For the “Group size”, select a desired capacity of 3, Minimum capacity of 2 and Maximum capacity of 5.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*JUIMcUN6u_GXzmLhVYXUog.jpeg" /></figure><ul><li>When done, select “Create Auto Scaling group”. We will now get confirmation of success.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*8S3xXDLRCj4khkgtu3PaJg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UGwEJ4NTBkVfMDsVQ9_tlQ.jpeg" /></figure><ul><li>If we now go to our EC2 home page we will see that 3 instances have been spun up with the 3 subnets that we created.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6QZIUg18ptvNCz4mghhjVw.jpeg" /></figure><p>6. Test to see if we have access to our Instances</p><p>Now that our auto scaling is done, we are going to test if our instances have functioning connections. To do so, open one of the 3 instances that was spun up and:</p><ul><li>Copy the public Ip address of the instance that we opened.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vlIKwQNKMug4XMjF3yvUkw.jpeg" /></figure><ul><li>Paste the Ip address in a browser and click enter. If the browser shows the message that we created in our script in step 3, then our connection works.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*AwWlEBzJ_8HcYnBwu9CNdA.jpeg" /></figure><p>We have now successfully completed our project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1028f1ee801e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Python and EC2 Random Name Generator]]></title>
            <link>https://medium.com/@fkfemi/using-python-and-ec2-random-name-generator-f328847939a0?source=rss-d5fbcb855977------2</link>
            <guid isPermaLink="false">https://medium.com/p/f328847939a0</guid>
            <dc:creator><![CDATA[Olufemi Olusanya]]></dc:creator>
            <pubDate>Sun, 09 Apr 2023 23:01:05 GMT</pubDate>
            <atom:updated>2023-04-09T23:01:05.380Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*i9nhKauSm6fp2HSsoeDTBw.jpeg" /></figure><p><strong>Using Python and EC2 Random Name Generator</strong></p><p>In this project the goal is to develop a set of scripts that will generate unique names for e.g. Computers, Servers, Printers and in this case EC2 instances.</p><p>Here is our project details:</p><p>Several departments share an AWS environment. You need to ensure that the EC2s are properly named and are unique so team members can easily tell who the EC2 instances belong to. Use Python to create your unique EC2 names that the users can then attach to the instances. The Python Script should:</p><p>1. All the user to input how many EC2 instances they want names for and output the same amount of unique names.</p><p>2. Allow the user to input the name of their department that is used in the unique name.</p><p>3. Generate random characters and numbers that will be included in the unique name.</p><p>The only departments that should use this Name Generator are the Marketing, Accounting, and FinOps Departments. List these departments as options and if a user puts another department, print a message that they should not use this Name Generator. Be sure to account for incorrect upper or lowercase letters in the correct department. Example: a user inputs accounting vs Accounting.</p><p>Now let us execute this task. Using python guides the following string of commands have been put together to help us execute our task. Here are each string of our codes:</p><p>1. All the user to input how many EC2 instances they want names for and output the same amount of unique names.</p><p>The command below will import both the random and string functions</p><p><strong><em># Setup Criteria</em></strong></p><p><strong><em>import random</em></strong></p><p><strong><em>import string</em></strong></p><p>This lists the names of all the departments that can use the generator</p><p><strong><em># List of allowed departments</em></strong></p><p><strong><em>allowed_departments = [‘Marketing’, ‘Accounting’, ‘Financial Operations’]</em></strong></p><p>This will help generate random alpha numeric characters</p><p><strong><em># To generate a unique EC2 name</em></strong></p><p><strong><em>def generate_ec2_name(department_name):</em></strong></p><p><strong><em># Generate random numbers and characters</em></strong></p><p><strong><em>random_chars = ‘’.join(random.choices(string.ascii_letters + string.digits, k=8))</em></strong></p><p>This will return our unique names</p><p><strong><em># Create and return unique EC2 name</em></strong></p><p><strong><em>return department_name.title() + ‘-’ + random_chars</em></strong></p><p>2. Allow the user to input the name of their department that is used in the unique name.</p><p>This will request the department name from the user</p><p><strong><em># Get number of EC2 instance and department name from user</em></strong></p><p><strong><em>num_ec2_instances = int(input(“Enter the number of EC2 instances: “))</em></strong></p><p><strong><em>department_name = input(“Enter the name of your department (Marketing, Accounting, Financial Operations): “)</em></strong></p><p>This will check the department name provided and generate an error if the department is not on the approved list</p><p><strong><em># Check if the department name is allowed</em></strong></p><p><strong><em>if department_name.title() not in allowed_departments:</em></strong></p><p><strong><em>print(“Sorry this Name Generator is only for the following departments Marketing, Accounting, and Financial Operations. “)</em></strong></p><p><strong><em>else:</em></strong></p><p><strong><em># Generate and print unique EC2 names</em></strong></p><p><strong><em>for i in range(num_ec2_instances):</em></strong></p><p><strong><em>ec2_name = generate_ec2_name(department_name)</em></strong></p><p><strong><em>print(ec2_name)</em></strong></p><p>Here is the string of code together:</p><pre># Setup Criteria<br><br>import random<br>import string<br><br># List of allowed departments<br><br>allowed_departments = [&#39;Marketing&#39;, &#39;Accounting&#39;, &#39;Financial Operations&#39;]<br><br># To generate a unique EC2 name<br><br>def generate_ec2_name(department_name):<br>    <br>    # Generate random numbers and characters<br>   <br>    random_chars = &#39;&#39;.join(random.choices(string.ascii_letters + string.digits, k=8))<br>    # Create and return unique EC2 name<br>   <br>    return department_name.title() + &#39;-&#39; + random_chars<br><br># Get number of EC2 instance and department name from user<br><br>num_ec2_instances = int(input(&quot;Enter the number of EC2 instances: &quot;))<br><br>department_name = input(&quot;Enter the name of your department (Marketing, Accounting, Financial Operations): &quot;)<br><br># Check if the department name is allowed<br><br>if department_name.title() not in allowed_departments:<br>   <br>    print(&quot;Sorry this Name Generator is only for the following departments Marketing, Accounting, and Financial Operations. &quot;)<br>else:<br>   <br>    # Generate and print unique EC2 names<br>    <br>    for i in range(num_ec2_instances):<br>       <br>        ec2_name = generate_ec2_name(department_name)<br>        <br>        print(ec2_name)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qHl3019Df9bcTbkr6f40Kg.jpeg" /></figure><p>3. Generate random characters and numbers that will be included in the unique name.</p><p>A test of our string of commands was performed. When the command was run it asked for the number of EC2 instances that the user wants to name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*V5zkYMXSjXvFLSmdAw9YVw.jpeg" /></figure><p>When the number was provided, the next request was for the department.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*tlVvCaZhghJkdK4hwrvPbw.jpeg" /></figure><p>When the name of the proper departments were provided, a set of unique names was generated in line with the number of instances requested.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*8dpfFij7ICswZnFARZObUQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*TV_7fb18KFIXUmjsAQLuFQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*QCPi4cLuMApfcd088tigGQ.jpeg" /></figure><p>Finally, to ensure that only the 3 departments in our list are the only ones able to generate unique names, the HR department name was used. The response was an error as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*qjB9y0Ym7d8SwXS-08HSAw.jpeg" /></figure><p>Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f328847939a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Deploy a Custom Image to Docker and AWS Elastic Container Registry (ECR)]]></title>
            <link>https://medium.com/@fkfemi/how-to-deploy-a-custom-image-to-docker-and-aws-elastic-container-registry-ecr-4cdf81dd55f9?source=rss-d5fbcb855977------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cdf81dd55f9</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[ecr]]></category>
            <dc:creator><![CDATA[Olufemi Olusanya]]></dc:creator>
            <pubDate>Sun, 09 Apr 2023 08:40:42 GMT</pubDate>
            <atom:updated>2023-04-09T08:40:42.721Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CMsdjK-jnySnG_BvmWgYwA.jpeg" /></figure><p>Today we are going to work through the steps needed to deploy a custom image to docker and AWS ECR. Here is the story guiding the need for us to perform this activity:</p><p>“Your team needs you to deploy a custom image quickly and write a quick script in a file to accomplish a task. To perform this, you need to create your own image using Nginx. Include a customized index.html file that can be viewed from a local browser. Then deploy your container with port 8080 open. Finally save your container data to the AWS Elastic Container Registry (ECR), and to your Docker Hub account.”</p><p>Here is what the project will entail:</p><p>1. Create a customized html file and name it index</p><p>2. Create your own image using Nginx.</p><p>3. Include the index.html file in the image. Make sure the index.html file can be viewed from a local browser.</p><p>4. Deploy your container with port 8080 open</p><p>5. Save your container data to the AWS Elastic Container Registry (ECR)</p><p>6. Save your container data to your Docker Hub account.</p><p>This is our core objective:</p><p>1. Create our own image using Nginx. Include a customized index.html file that can be viewed from a local browser.</p><p>2. Deploy your container with port 8080 open</p><p>3. Save your container data to the AWS Elastic Container Registry (ECR), and to your Docker Hub account.</p><p>For us to perform this activity here are some of the prerequisites:</p><p>· AWS Account</p><p>· Cloud9 (AWS feature)</p><p>· AWS Elastic Container Registry (ECR) (AWS feature)</p><p>· Docker Hub Account</p><p>Let’s get this project rolling.</p><p>1. Create our own image using Nginx. Include a customized index.html file that can be viewed from a local browser.</p><p>To get this process started we need will need an independent development environment (IDE). There are different types of IDEs but for this project I will be using Cloud9. There are two advantages to using Cloud9, the first is that Cloud9 is part of the AWS stack and two is that Docker is natively installed in Cloud9.</p><p>To set up our Cloud9 environment go to the AWS Console Home page and select “Cloud9” (if Cloud9 is not there, use the search option to search for Cloud9 and select it).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rIdEDZfETW02cy_S3wpm2w.jpeg" /></figure><p>When it opens, select “Create environment”. Then name the environment and under “Environment type” select “New EC2 instance”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hqc8yKMwnm1XwSyTobvMQQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iwWMiIpa08xUTxBdBRgJ5A.jpeg" /></figure><p>For “Instance type” select “t2.micro”. Leave all the other options as default and then click “Create”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*73Jm-9iH7YI83wgidEvIQw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QkMke9HSGmfjaxNt0HQlCA.jpeg" /></figure><p>You will now get a confirmation that the environment has been created with the environment now also under your list of environments. Under Cloud9 IDE title, select “Open” to open your environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hPqzIVV8yy9UCTbVyPph8A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*auKX3vQIAFPYp7_n8hvhZA.jpeg" /></figure><p>Now we are going to go into the EC2 instance running our Cloud9 and make some changes to our security group rules so that we can open port 8080. To do so, select or search for EC2, open the “EC2 Dashboard”, select “Instances”, select the EC2 instances created for our Cloud9 environment, then select the “Instance ID”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qB9ppFY8qZ0GfTdPwTYbNg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9HYVA73UX3sorsLhupw5iw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KClA-vDveT006qPz-HCfGg.jpeg" /></figure><p>This will open the “Instance summary” page of our EC2. Select the “Security” tab. Then select “Security groups”. When it opens select “Inbound rules” tab then select “Edit inbound rules”. In the “Edit inbound rules” page, add a new rule using the following criteria: Type — All traffic, Protocol — All, Port range — All, Source — Anywhere. Then click “Save rules”. You will now get confirmation that rules in the security group has been successfully modified. With that we have successfully opened our ports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jsovQ4Hu7_V5FtV6xtjOHA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*get_MLXW7RbfC0KlP_9bSQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ldBmzOlXAmC625bLpxtiQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IbhDdGHdJGlHJhnNXHNqFg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eFjNVTk4beWxtBGVOxQcqw.jpeg" /></figure><p>Now we are going to work on creating our Dockerfile using Cloud9. To start we are going to create the folder that will contain the contents of our Dockerfile. To do so we will use the following command:</p><p><strong><em>mkdir &lt;Directory name&gt;</em></strong></p><p>We will then change to the directory we just created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*9_xXIWsLFWSTomSDPoCEYw.jpeg" /></figure><p>Now we need to add the nginx image to our directory. This image will be pulled from the Docker Repository. To do so we will use this command:</p><p><strong><em>docker pull nginx:latest</em></strong></p><p>This command will pull the latest version of nginx from the docker repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*wgtn2ko1JH8eAv3TTjNfmQ.jpeg" /></figure><p>We can confirm that the pull was successful by using the command:</p><p><strong><em>docker images</em></strong></p><p>This command will list all the docker images that we have. In this case there is only one, nginx.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*Kx0tRkuAESQvZZNR7jdZFg.jpeg" /></figure><p>Now we are going to create our Dockerfile by using the command:</p><p><strong><em>touch Dokerfile</em></strong></p><p>We use the command “<strong><em>ls</em></strong>” to confirm that our file was created. Now we need to edit our dockerfile. To do so we will use “vim” by using this command:</p><p><strong><em>vim Dockerfile</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*pvhb6VbrXh2x70MEpFwTtA.jpeg" /></figure><p>With the Dockerfile open, press “i” to allow us to insert our command into the dockerfile. This is the command that we will paste into the dockerfile:</p><p><strong><em>FROM nginx</em></strong></p><p><strong><em>COPY index.html /usr/share/nginx/html</em></strong></p><p><strong><em>EXPOSE 8080</em></strong></p><p>When done, press escape (ESC) and then enter the command “<strong><em>:wq</em></strong>” to save and close our file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ev1hkL9fHTS2U2nj9ELtNg.jpeg" /></figure><p>Now we are going to create our index.html file. Since we will be creating a container that will contain our dockerfile and the index.html file, the index.html file must be created in the same directory as our dockerfile. To create our index.html, we will use this command:</p><p><strong><em>touch index.html</em></strong></p><p>With the index.html file created we now need to enter some information into the file. The information will include the title, background color and details of our site. Now we need to edit our index.html file. To do so we will use “vim” by using this command:</p><p><strong><em>vim index.html</em></strong></p><p>With the index.html file open, press “i” to allow us to insert our command into the dockerfile. This is the command that we will paste into the file:</p><p>&lt;!DOCTYPE html&gt;</p><p>&lt;html&gt;</p><p>&lt;head&gt;</p><p>&lt;title&gt;Femi’s LUIT Wk 16 Deliverable Exercise&lt;/title&gt;</p><p>&lt;style&gt;</p><p>body {</p><p>background-color: Green;</p><p>}</p><p>&lt;/style&gt;</p><p>&lt;/head&gt;</p><p>&lt;body&gt;</p><p>&lt;h1 style=”color:white;”&gt;This was fun. Thank you for being part of it&lt;/h1&gt;</p><p>&lt;/body&gt;</p><p>&lt;/html&gt;</p><p>When done, press escape (ESC) and then enter the command “<strong><em>:wq</em></strong>” to save and close our file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*CVin9HVwvDI69zNHSMuEmQ.jpeg" /></figure><p>The next step is for us to now create our docker image now that we have both our Dockerfile and the index.html file both in our directory. To build the image we will use the command:</p><p><strong><em>docker build .</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*8Ii7LvbkrqwQu_ZaukLaNg.jpeg" /></figure><p>Now that our image has been built, we need to check to confirm. To do so we will use the following command:</p><p><strong><em>docker images</em></strong></p><p>This command will list all our docker images. We will see that we now have a new image. That is the image we just created and it has the following details:</p><p>REPOSITORY TAG IMAGE ID CREATED SIZE</p><p>&lt;none&gt; &lt;none&gt; 831bf075b258 2 minutes ago 142MB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*VjapyFHaT1kC0adWoRGbtA.jpeg" /></figure><p>Currently our image has no name (repo) or tag. When you have many images, it becomes difficult to know which image is what. Docker provides a way to tag your images with friendly names of your choosing. This is known as tagging and it can be done using this command:</p><p><strong><em>docker build -t yourusername/repository-name .</em></strong></p><p>Let’s proceed to tag the Docker image we just built. If you run the command above, you should have your image tagged already. Running docker images again will show your image with the name you’ve chosen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*VLlMGvaITMVojzORbwaXIw.jpeg" /></figure><p>2. Deploy your container with port 8080 open</p><p>Now we are going to work on deploying our container with port 8080 open. To do so we have to first create our container from the docker image we have created. We can create the container by using the following command:</p><p>docker run -d — name &lt;give a name to your container&gt; -p 8080:80 &lt;image name&gt;</p><p>With our container created, we can confirm the creation by using a command that will list all our container. Here is the command:</p><p><strong><em>docker container ls</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jil063nza9PTVt4wcfCPbw.jpeg" /></figure><p>With our container created we are going confirm that our container has an internet access. We can do so by using this command:</p><p>Curl localhost:8080</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NrmYVNUTqDKgIuCXX-yYeA.jpeg" /></figure><p>Now that we have confirmed that our container has internet access we are going to test to see if we can access our container using a browser. To do so we will first have to get the public Ip address of our EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2-rfIqGoP2zZTUL26NXp0A.jpeg" /></figure><p>With the Ip address, we are going to use this <strong><em>&lt;EC2 IP Address&gt;:8080 </em></strong>to paste to our browser. We should have access to our site.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O5EWqp3b6MtDt52OwGWBRA.jpeg" /></figure><p>3. Save your container data to the AWS Elastic Container Registry (ECR), and to your Docker Hub account.</p><p>Now we are going to work on saving our container information in both AWS Elastic Container Registry (ECR), and to your Docker Hub account. We are going to start with saving our container in AWS Elastic Container Registry (ECR). Before we can push our container to AWS ECR we have to create a repository by using this command:</p><p><strong><em>aws ecr create-repository — repository-name &lt;give a name to your repo&gt; — region &lt;region name&gt;</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZzmmoHfZE7SuTGN7_Mh39g.jpeg" /></figure><p>We can confirm that out AWS ECR repo has been created by going to AWS, search for ECR, click ECR, go to “Repositories” and you will see our repository listed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TftlBixjgXO9w5MDQS9pvw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EfLntW7omwcr1D7ZJ_xObg.jpeg" /></figure><p>Next, we will need to log into AWS Elastic Container Registry. To do so we will need to use this command to generate the login password:</p><p><strong><em>aws ecr get-login-password — region &lt;region name&gt;</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hinO88PxSbZTFUiWWXEB5Q.jpeg" /></figure><p>Copy and save the string of alpha numeric characters somewhere safe. We are still going to use it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*34P-j03k8R4mTFXuJTpISQ.jpeg" /></figure><p>Next, we will be logging into AWS ECR by using the following command:</p><p><strong><em>aws ecr — region us-east-1| docker login -u AWS -p &lt;Output&gt; &lt;ECR Repository URI&gt;</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*OlE1SxRZgpas3ITLVzoBFQ.jpeg" /></figure><p>Here is what the final output of the command will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*zHbqJv-nRcIajwO40-9dgw.jpeg" /></figure><p>When the command is run, it will tell you that the login has succeeded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EyMvarwhc5B-ysL5nwoPXg.jpeg" /></figure><p>Now we need to tag our image with a docker tag. This can be done by using this command:</p><p><strong><em>docker tag &lt;Image Name&gt; &lt;ECR Repository URI&gt;</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*13PZVk1C_uUpFe3LC9p4hQ.jpeg" /></figure><p>Now we are going to push our container to AWS ECR by using the following command:</p><p><strong><em>docker push &lt;ECR Repository URI&gt;</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WAe8tmr-CLLKs6Fa-H1ikA.jpeg" /></figure><p>To confirm our push to AWS ECR, we will go to AWS ECR Repositiories and find your repository name. Click on it and it will open the repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RotC2aaNFL8EsTrYlU_j7w.jpeg" /></figure><p>In the open repository you will see that our image has been pushed there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0_zlKB7rhwWxODBe_lfD2g.jpeg" /></figure><p>Now we are going to push our container to our personal docker hub account. To do so we will be using this command to login to our docker hub account by providing our username and password:</p><p><strong><em>docker login -u &lt;your_user_name&gt;</em></strong></p><p>When logged in, we will get a “Login Succeeded” confirmation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*L52lfVOPEOZEauBU4KI2QA.jpeg" /></figure><p>Now that we have logged in, we have to go to our docker hub account to create the repository that we will push our image to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kAM3V4jkAjEREKsXiOqaig.jpeg" /></figure><p>Now we are going to commit our container to our docker hub repository by using the following command:</p><p><strong><em>docker commit &lt;your_container_ID&gt; &lt;your dockerhub account username/docker hub repository name:tag name</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u3NZd4xuSsxGVQxILRJeoA.jpeg" /></figure><p>Now that we have committed our container we have to now push it to the repository that we created on our docker hub account. To do this we have to use this command:</p><p><strong><em>docker push &lt;your docker hub username&gt;/&lt;docker hub repository name&gt;:tag name</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WKLQp45UTLNHmzk719A2-w.jpeg" /></figure><p>To confirm that our push worked, you will go into our docker hub account and check the repository that we created. The repo should show our image and have information on the push.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ewjP7Ji9wvB1jRbt81hnA.jpeg" /></figure><p>We have successfully deployed a custom image to Docker and AWS Elastic Container Registry (ECR).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cdf81dd55f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create an EC2 Instance with a Webserver]]></title>
            <link>https://medium.com/@fkfemi/create-an-ec2-instance-with-a-webserver-3cc2cfc3358d?source=rss-d5fbcb855977------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cc2cfc3358d</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[ec2-instance]]></category>
            <dc:creator><![CDATA[Olufemi Olusanya]]></dc:creator>
            <pubDate>Sat, 08 Apr 2023 05:51:38 GMT</pubDate>
            <atom:updated>2023-04-08T05:51:38.551Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*wBoUOAF9t3JUhv47oaFWnA.jpeg" /></figure><p>The goal is this exercise is to create an EC2 instance with a webserver.</p><p>Steps to be taken:</p><p>1. Create a t2.micro EC2 instance with the OS of your choice (Just make sure it is free tier).</p><p>2. In the user-data field, use a script that updates all packages, installs NGINX, and start the service.</p><p>3. Verify that the instance has the Apache webserver downloaded and installed through the public IP.</p><p>Now let’s execute this project:</p><p>1. Create a t2.micro EC2 instance with the OS of your choice (Just make sure it is free tier).</p><p>The first task here is to create a new EC2 instance. To do that log into your AWS Management Console. Search for EC2 and then navigate to the EC2 dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*5ZzxJqdzGN-aEk0FwCaCNQ.jpeg" /></figure><p>At the EC2 dashboard, click on the “Launch Instance” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GqfPQSyI8axE2GLvG8cF2w.jpeg" /></figure><p>Give the open instance a name. Under “Application and OS Images (Amazon Machine Image)” select “Amazon Linux 2023 AMI (this will be our OS of choice).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*uSfDR9JPCWJDl-JstR38Zg.jpeg" /></figure><p>Under “Instance type” select “t2.micro” as the instance type. Under Key pair (login), you can select “create new key pair” (if you don’t have a key) or select an existing key from the dropdown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*2D5dOQ8lnvCJzsHIufI-Lw.jpeg" /></figure><p>Under “Network settings” — Firewall (security groups) select “create security groups” for the system to create a standard security group for you. Add a rule that allows SSH traffic from anywhere with IP address 0.0.0.0/0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*2MqoMFG9DWub1Qd2GxbCsg.jpeg" /></figure><p>Under summary click “Launch instance”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*9jsLwQqxDcUfv11X23oX4A.jpeg" /></figure><p>Now let’s go to the EC2 Dashboard and under “Resources” click on Instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GsKjlrDuPAmxzNLEfnh-HQ.jpeg" /></figure><p>Under “Instances”, you will find your newly created EC2 instance. Check to make sure that your newly created EC2 instance is running. If it is, select the instance, click on “Instance state” and from the dropdown select “Stop instance”. The reason why we need to stop our instance is because the next step of our exercise requires that we update the user-data field in our EC2 instance but we cannot update the instance while it is running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BvEIgFeh12pG_q83mL-zpw.jpeg" /></figure><p>2. In the user-data field, use a script that updates all packages, installs NGINX, and start the service.</p><p>Now we have to go into our instance to update the user-data field. To do so, click on the “Instance ID”. This will take you into the “Instance summary” page. In the instance summary page click on “Actions” and from the dropdown select “Instance settings” and from the follow-up dropdown select “Edit user data”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fir_zUexjtQPRdRegMUEmg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vhf-CqH5wgXmaX6NFJepiA.jpeg" /></figure><p>In the “Edit user data” page select “Modify user data as text” and then paste the following script into the text box:</p><p><strong><em>#!/bin/bash</em></strong></p><p><strong><em>sudo yum update -y</em></strong></p><p><strong><em>sudo amazon-linux-extras install nginx1 -y</em></strong></p><p><strong><em>sudo systemctl start nginx</em></strong></p><p>Click “Save” to apply the user-data script.</p><p>Here is a brief explanation of what our script means:</p><p>sudo yum update -y: This command will update all the packages to their most recent version.</p><p>sudo amazon-linux-extras install nginx1 -y: This command will install nginx.</p><p>sudo systemctl start nginx: This command will start nginx.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*RZ8TFNUyQG98bEQ_UxtTOQ.jpeg" /></figure><p>3. Verify that the instance has the Apache webserver downloaded and installed through the public IP.</p><p>Now we have to verify that the instance has the Apache webserver downloaded and installed through the public IP. To do this will connect to your instance either by using a SSH client like PuTTY or by using the connect option in our EC2 instance. For this project I used the connect option. To use the connect option, go to the instance page, select your instance, and click on “Connect”. When it opens, select “EC2 Instance Connect” and then “Connect”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8u9sszOQJlvLF3n-WGlyKA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*Wbzt-UNURUw6wCwKQG3OsQ.jpeg" /></figure><p>We can now verify that NGINX is installed and running by running the following command:</p><p><strong><em>sudo systemctl status nginx</em></strong></p><p>If NGINX is installed and running, you should see a “active (running)” status message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rWgCyZkdU-GLbJEAGLvKsA.jpeg" /></figure><p>We can now verify that the Apache web server is not installed by running the following command:</p><p><strong><em>httpd -v</em></strong></p><p>If Apache is not installed, you will see a “command not found” message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*RYJJk-Gro1DIwYxGnWgBwA.jpeg" /></figure><p>Now we are going to use our instance’s public IP address, paste it into a web browser and run it to see if NGINX is installed and running correctly. If it is we will see the NGINX welcome page. But before we do that we have to make some configuration changes to our security group. Right now, as configured, we can only access our instance via SSH but for the web page to be accessible, we must allow HTTP and/or HTTPS accesses.</p><p>To do so, click on the instance id of the EC2 instance we just created. Click on the “Security” tab and make sure you are in the right security group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ePOPCqY79hBg7RPjt2s2DQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*xQ2xU713pkVuM7DjOY4Rrg.jpeg" /></figure><p>Open the “Security Group” we created and under “Inbound rules” select “Edit inbound rules”. Click “Add rule” twice and make the following configuration changes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*8RgNbs3JB-cGICxw8Y2ORA.jpeg" /></figure><p>Save the rules just created by clicking “Save rules”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RWEiWcpZ5eO-S6JBQgGUIQ.jpeg" /></figure><p>After making the changes to our security group, we should now be able to access our NGINX webpage by visiting the public IP address of your EC2 instance in a web browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*psWuZNhb76BoVa2TAzXdbg.jpeg" /></figure><p>We have now created an EC2 instance with a webserver.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cc2cfc3358d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a Nginx Server on Centos 8]]></title>
            <link>https://medium.com/@fkfemi/how-to-create-a-nginx-server-on-centos-8-3937a1ef87ce?source=rss-d5fbcb855977------2</link>
            <guid isPermaLink="false">https://medium.com/p/3937a1ef87ce</guid>
            <category><![CDATA[centos]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[centos-8]]></category>
            <category><![CDATA[linode]]></category>
            <dc:creator><![CDATA[Olufemi Olusanya]]></dc:creator>
            <pubDate>Fri, 07 Apr 2023 03:57:17 GMT</pubDate>
            <atom:updated>2023-04-07T03:57:17.982Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*gJXzYhK8DX7JjHxRMX3oVQ.jpeg" /></figure><p>Today I will be creating a Nginx web server on CentOS 8. To start here are the steps needed to successfully perform this activity:</p><p>1. Have a CentOS 8 Server (For this project I will be using Linode to build my CentOS 8 instance)</p><p>2. Update all packages on the server</p><p>3. Install a NGINX Web Server</p><p>4. Confirm your NGINX installation</p><p>5. Enable the NGINX Web Server</p><p>6. Open Port 80 (HTTP) and 443 (HTTPS) for web traffic access.</p><p>7. Open a web browser and paste the IP address (or domain name) in the URL bar to test that we can access the Nginx Server over the internet.</p><p>Now let’s execute this project:</p><p>1. Have a CentOS 8 Server</p><p>The first step of this project is to have a server that is running on CentOS. For this project I will be using Linode to build my CentOS 8 instance. To do so I created an account on Linode. As my OS Image I selected CentOS 8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F3L6rG2lxYS58jvBzbLKYQ.jpeg" /></figure><p>I chose a shared CPU because I really don’t need to much capacity for this project. Under shared CPU I chose the cheapest configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9GRa07R8KfDNYlCUGrzDHQ.jpeg" /></figure><p>The system auto creates a label for my instance and I create my root password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3uXuZbq757PgCCkYAoeLpg.jpeg" /></figure><p>I did not set up a VLAN or any other options. I kept my configuration simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sPGkJ7ekQPhodFG18R42NQ.jpeg" /></figure><p>Now my server is running. I have been assigned an ip address: 139.144.225.124. This ip address will come in handy when I test my web server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b3FINrF6DQQY1Qj7I09WfQ.jpeg" /></figure><p>2. Update all packages on the server</p><p>Now that my server is up and running the next step is to make sure that it is running the most recent versions of my OS and all the relevant packages. To do so I will first ssh into my server and then running the command “sudo yum update”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GuhSPdh97pDpX52C7icw-w.jpeg" /></figure><p>Now that all the packages have been updated, I will proceed to install the Nginx web server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ruALAgX0C2gCeZKceYMkBA.jpeg" /></figure><p>3. Install a NGINX Web Server</p><p>To install the Nginx web server, I will use this command “sudo yum install nginx”. This will install nginx and all its associated packages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tSyXovJW7ckl8x0_Aiuq1w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pj005PbZzHPj5QuNCy3ifg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l69bqRK-Z8v--2I-1S3pyA.jpeg" /></figure><p>4. Confirm your NGINX installation</p><p>Now that we have run the command to install our web server Nginx, let us confirm that it was indeed installed by running the command “sudo sudo yum info nginx”. This command will confirm the installation of Nginx by providing to details on the install like the name, version release, size source etc of the install.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*hN7xLlIFczJN8LWjpmCx7w.jpeg" /></figure><p>5. Enable the NGINX Web Server</p><p>Installation process of an application does not necessarily start the application and Nginx is no different. After its installation we have to start/enable it. To do so we have to use the command “sudo systemctl start nginx” or “sudo systemctl enable nginx”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*fnA_cDdNEQ8IDbELgiroIA.jpeg" /></figure><p>6. Open Port 80 (HTTP) and 443 (HTTPS) for web traffic access.</p><p>Now that Nginx is running, if you go to a browser with your server Ip address you expect to be able to access the Nginx web server but unfortunately what you get back is an error. The reason for this is we still need to configure our firewall to all traffic through both ports 80 and 443. Now to fix this problem we need to open port 80 (HTTP) and 443 (HTTPS) for web traffic access using the following commands:</p><p>“sudo firewall-cmd — add-service=http — permanent” (This will open port 80)</p><p>“sudo firewall-cmd — add-service=https –permanent” (This will open port 443)</p><p>After opening both ports 80 and 443, we will now run command “sudo firewall-cmd –reload” to refresh the traffic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*30mSqLwn3I3RQ_SuqUNiPw.jpeg" /></figure><p>7. Open a web browser and paste the IP address (or domain name) in the URL bar to test that we can access the Nginx Server over the internet.</p><p>Now that the ports are open, we now need to check to make sure that we can access the Nginx server on the web. To do so we will open a web browser and paste our IP address (or domain name) in the URL bar to test that we can access the Nginx Server over the internet. To get our Ip address we can either go to our Instance and check the server details page (in this case that will be Linode).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b3FINrF6DQQY1Qj7I09WfQ.jpeg" /></figure><p>Or, we can run this command to get our Ip address: “curl ifconfig.me”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*KMiXyoW86i8EPg35KXqNtg.jpeg" /></figure><p>Now, we will paste our Ip in our browser and run it. If the connections are working, we should see a web page saying “Welcome to nginx on Red Hat Enterprise Linux!”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iGNusUpgn4svPdcS4t_AqQ.jpeg" /></figure><p>We have just completed our project!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3937a1ef87ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating A List with Python]]></title>
            <link>https://medium.com/@fkfemi/creating-a-list-with-python-cf7711db5af3?source=rss-d5fbcb855977------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf7711db5af3</guid>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Olufemi Olusanya]]></dc:creator>
            <pubDate>Wed, 05 Apr 2023 02:38:47 GMT</pubDate>
            <atom:updated>2023-04-05T02:38:47.800Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HXMeyPYfmyUot9T9" /><figcaption>Photo by <a href="https://unsplash.com/@hiteshchoudhary?utm_source=medium&amp;utm_medium=referral">Hitesh Choudhary</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I have always talked about learning python but I never did because of the fear of the unknown. Well, nothing gets you through that wall than the need to achieve. As part of my DevOps/Cloud Engineering journey, I have finally met python.</p><p>This week I have spent my time going through my introduction to python. I have been exposed to the following in python:</p><p>· Variables</p><p>· Objects</p><p>· Escape sequences</p><p>· Strings and String Operators</p><p>· Boolean Operators</p><p>· Len function</p><p>· String indexing</p><p>· Slicing</p><p>· Lists</p><p>· Nested lists: Matrices and Cubes</p><p>· Tuples</p><p>· Dictionaries</p><p>To reinforce what I have learned so far, I executed a small project. The goal of the project is to create a list of AWS Services using Python. The project requires the following steps:</p><p>1. The list should be empty initially.</p><p>2. Populate the list using append or insert.</p><p>3. Print the list and the length of the list.</p><p>4. Remove two specific services from the list by name or by index.</p><p>5. Print the new list and the new length of the list.</p><p>Following the outlined steps, I created an empty list and named it AWS Service Inventory List using this string: aws_service_inventory_list = [].</p><p>Then I added the following AWS services to my empty list, EC2, S#, DynamoDB, Lambda and Cloud9 using this string for example: aws_service_inventory_list.append(‘EC2’)</p><p>Then I printed the list and provided the length of the list using print(‘aws_service_inventory_list’) and len(aws_service_inventory_list) respectively.</p><p>In my next steps I removed two services from my list using aws_service_inventory_list.remove (“DynamoDB”) and aws_service_inventory_list.remove (“Cloud9”) respectively (The two services removed are DynamoDB and Cloud9).</p><p>Finally, I printed the updated list and provided the length of the list using: print(‘aws_service_inventory_list’) and len(aws_service_inventory_list) respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*itF4S5ITVInVa_Ko78et_g.jpeg" /></figure><p>Hope you enjoyed my brief intro into python (I know I did).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf7711db5af3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Create, Stop and Terminate EC2 Instances Using Python (Boto3)]]></title>
            <link>https://medium.com/@fkfemi/how-to-create-run-and-stop-ec2-instances-using-python-889149f4eb44?source=rss-d5fbcb855977------2</link>
            <guid isPermaLink="false">https://medium.com/p/889149f4eb44</guid>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[boto3]]></category>
            <dc:creator><![CDATA[Olufemi Olusanya]]></dc:creator>
            <pubDate>Tue, 04 Apr 2023 06:53:02 GMT</pubDate>
            <atom:updated>2023-04-04T16:58:16.829Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post I am going to go through the process of creating, stopping and terminating EC2 Instances using simple Python scripts/codes.</p><p><strong>Details of the Project</strong></p><p>Our DevOps engineering team often uses a development lab to test releases of our application. The Managers are complaining about the rising cost of our development lab and need to save money by stopping our 3 ec2 instances after all engineers are clocked out.</p><p><strong>Prerequisites</strong></p><p>AWS Account</p><p>Some Python Knowledge</p><p>Any Integrated Development Environment (IDE). I used AWS Cloud 9 for this project.</p><p><strong>Steps to be taken</strong>:</p><p>1. Log into AWS and create a Cloud9 instance. Install python (boto3) and AWS CLI</p><p>2. Create a python file template. Get AWS AMI information from EC2 instance</p><p>3. Use python script to create EC2 instances</p><p>4. Use python script to stop EC2 instances</p><p>5. Use python script to terminate stopped EC2 instances</p><p><strong>Now let’s execute this project</strong>:</p><p>1. Log into AWS and create a Cloud9 instance. Install python (boto3) and AWS CLI</p><p>Log into your AWS account and search for Cloud9.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G8sg4enG7KZXCORusPYMeg.jpeg" /></figure><p>Open Cloud9, select “Create environment”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gdzr_5qkMRNhyMBt03QUPg.jpeg" /></figure><p>When it opens, name the environment, under “Environment type” select “New EC2 instance”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yQAQ138TOG9vJoo0G7f0Q.jpeg" /></figure><p>Under “New EC2 instance” you will find “Instance type” select “t2.micro”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aYBOw6cBBQunISOI8CN59g.jpeg" /></figure><p>Leave the rest of the option as default then click “Create”. You have now created a Cloud9 environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R2yXaBz4Hnw6kOsa9tQIYA.jpeg" /></figure><p>To access the environment, in the open Cloud9, select “Environment”, you will see the Cloud9 instance you created, under “Cloud9 IDE” select “Open”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EqnF4qhFdoALYJz-LJPijw.jpeg" /></figure><p>Now that we are in Cloud9, we will first have to install python and the AWSCLI. To do so we will run the following commands:</p><p>pip install boto3</p><p>pip install awscli</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I7EHuJE4Jq4sO2KMNcmFZA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x2TPZEbOJeiCKSJu3Ag60A.jpeg" /></figure><p>2. Create a python file template. Get AWS AMI information from EC2 instance</p><p>Now we have to create a python file. This is the template that will hold our commands. To do so we can either go to the “File” option in the upper left-hand corner of Cloud9, the select “New From Template” and then select “Python File” or you can right click the system created folder and select “New file” and save it as .py (python file).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*67YyspYx0f0H46WXJlEYjA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iW1CLwRxcvNAUPaqaZwOdQ.jpeg" /></figure><p>The script that we will use to create EC2 instances using python will need an AMI Id. To get this just go to EC2, select launch instance, scroll down to find and copy the ami id. After that close the instance wizard, you don need to actually create it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*JpF3CoaOaHlnJAo9759CXA.jpeg" /></figure><p>3. Use python script to create EC2 instances</p><p>Now we are going to create our EC2 instances. For this project I will be creating 5 instances using these commands:</p><p><strong><em>import boto3</em></strong></p><p><strong><em># Create an EC2 client</em></strong></p><p><strong><em>ec2 = boto3.client(‘ec2’)</em></strong></p><p><strong><em># Define the parameters for the instances</em></strong></p><p><strong><em>image_id = ‘ami-1234567890abcdef0’ # replace with your AMI ID</em></strong></p><p><strong><em>instance_type = ‘t2.micro’</em></strong></p><p><strong><em># Define the number of instances to create</em></strong></p><p><strong><em>num_instances = 5</em></strong></p><p><strong><em># Create the instances</em></strong></p><p><strong><em>instances = ec2.run_instances(</em></strong></p><p><strong><em>ImageId=image_id,</em></strong></p><p><strong><em>InstanceType=instance_type,</em></strong></p><p><strong><em>MaxCount=num_instances,</em></strong></p><p><strong><em>MinCount=num_instances</em></strong></p><p><strong><em>)</em></strong></p><p><strong><em># Print the instance IDs</em></strong></p><p><strong><em>for instance in instances[‘Instances’]:</em></strong></p><p><strong><em>print(instance[‘InstanceId’])</em></strong></p><p>The scrip will require the ami id, the instance type and the number of instances we need to run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*eO-XI7lecZKbHhrkKb1YMw.jpeg" /></figure><p>After running the script, 5 instances were created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*zOXESL35V4FnRY2KfUy_RQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SFEgStQR4yKiXNuqVr6kHg.jpeg" /></figure><p>4. Use python script to stop EC2 instances</p><p>Now we are going to use a python script to close the instances we just created. To do so we will use the following script:</p><p><strong><em>import boto3</em></strong></p><p><strong><em># create EC2 client</em></strong></p><p><strong><em>ec2 = boto3.client(‘ec2’)</em></strong></p><p><strong><em># list of instance IDs to stop</em></strong></p><p><strong><em>instance_ids = [‘INSTANCE_ID_1’, ‘INSTANCE_ID_2’, ‘INSTANCE_ID_3’]</em></strong></p><p><strong><em># stop EC2 instances</em></strong></p><p><strong><em>response = ec2.stop_instances(InstanceIds=instance_ids)</em></strong></p><p><strong><em>print(‘Stopping instances:’, response[‘StoppingInstances’])</em></strong></p><p>For the script to run we will need to provide the instance id of all the instances we created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qXOZir2tVB0VTWIr0gje2A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*21hXH6KCNJgW1EqsqBJk0w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2M68nS6Ts-XbKMEnDfB56w.jpeg" /></figure><p>5. Use python script to terminate stopped EC2 instances</p><p>Now we are going to use a python script to terminate the instances we just stopped. To do so we will use the following commands:</p><p><strong><em>import boto3</em></strong></p><p><strong><em># Specify the AWS region where your EC2 instances are running</em></strong></p><p><strong><em>region = ‘us-east-1’</em></strong></p><p><strong><em># Specify the instance IDs of the EC2 instances you want to terminate</em></strong></p><p><strong><em>instance_ids = [‘i-0123456789abcdef0’, ‘i-0123456789abcdef1’]</em></strong></p><p><strong><em># Create a Boto3 EC2 client</em></strong></p><p><strong><em>ec2_client = boto3.client(‘ec2’, region_name=region)</em></strong></p><p><strong><em># Terminate the specified EC2 instances</em></strong></p><p><strong><em>response = ec2_client.terminate_instances(InstanceIds=instance_ids)</em></strong></p><p><strong><em># Print the response to confirm the instances were terminated</em></strong></p><p><strong><em>print(response)</em></strong></p><p>For this script to work we will need the instance id of all the EC2 instances we want to terminate and the region the instances are housed in. After running the script, the instances are terminated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*fsT8ofcMCukFOOtWVGZjfA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6EdT1erazhGxznLdrsxqzw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9NjMc98FA-JFWGacYcmv-A.jpeg" /></figure><p>We have successfully used python script to create, stop and terminate EC2 instances.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=889149f4eb44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hosting A Website in an EC2 Instance in AWS.]]></title>
            <link>https://medium.com/@fkfemi/hosting-a-website-in-an-ec2-instance-in-aws-a8dfa301478d?source=rss-d5fbcb855977------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8dfa301478d</guid>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[ec2-instance]]></category>
            <dc:creator><![CDATA[Olufemi Olusanya]]></dc:creator>
            <pubDate>Sat, 01 Apr 2023 13:24:10 GMT</pubDate>
            <atom:updated>2023-04-01T13:24:10.077Z</atom:updated>
            <content:encoded><![CDATA[<p>The goal of this project is to host a website in an EC2 instance. Here is the details of the task at hand:</p><p>Your company wants to start shifting from using on premises servers to using servers in the cloud. Rather than purchasing all the infrastructure in a data center they ask you to create an EC2 instance in AWS to host their new website.</p><p>Steps to be taken:</p><p>1. Launch an EC2 Amazon Linux t2.micro (free tier) in a public subnet of your Default VPC. (You should NOT be creating a custom VPC for this project)</p><p>2. Create a security group that allows inbound traffic on HTTP for 0.0.0.0/0 and allows inbound traffic on SSH from your ip address.</p><p>3. SSH into your EC2 instance and install Apache with a custom webpage using a BASH script. (The webpage can be a simple Hello World or something more complex. We are not testing your HTML skills)</p><p>Now let’s execute this project:</p><p>1. Launch an EC2 Amazon Linux t2.micro (free tier) in a public subnet of your Default VPC. (You should NOT be creating a custom VPC for this project)</p><p>The first task here is to create a new EC2 instance. To do that log into your AWS Management Console. Search for EC2 and then navigate to the EC2 dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGk8mEK6k73FDipuvpxoEw.jpeg" /></figure><p>At the EC2 dashboard, click on the “Launch Instance” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8_5Z3YJk7ImrLg5rk6WUYA.jpeg" /></figure><p>Give the open instance a name. Under “Application and OS Images (Amazon Machine Image)” select “Amazon Linux 2 AMI (HVM), SSD Volume Type”, and then choose “t2.micro” as the instance type. Under Key pair (login), you can select “create new key pair” (if you don’t have a key) or select an existing key from the dropdown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*hYJ6obqrsF6OMC_ZaszVkQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*Dt8ngkZGNP58cT1jygk_KA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*F5lPYucBQnD4ElL42WCL8Q.jpeg" /></figure><p>Under “Network settings” use the default VPC, in this project mine is named vpc-03f2747470bd32fb4. Make sure that you select a public subnet by ensuring that the “Auto-assign public IP” is enabled.</p><p>Under Firewall (security groups) select “create security groups” for the system to create a standard security group for you. Add a rule that allows SSH traffic from anywhere with IP address 0.0.0.0/0.</p><p>c. Add a rule that allows inbound traffic on HTTP from 0.0.0.0/0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*KhTZpGWXPOycb9T2uNZG-Q.jpeg" /></figure><p>Under summary click “Launch instance”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*iiSqF0OmceZvCluE6UxgVw.jpeg" /></figure><p>Check to make sure that your newly created EC2 instance is running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*knUasvBo707SD0_Gd_FRvg.jpeg" /></figure><p>2. Create a security group that allows inbound traffic on HTTP for 0.0.0.0/0 and allows inbound traffic on SSH from your ip address.</p><p>Now we are going to make configuration changes to the security group that was created with the EC2 instance. To do so click on the instance id of the EC2 instance we just created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*knUasvBo707SD0_Gd_FRvg.jpeg" /></figure><p>Click on the “Security” tab and confirm that you are in the right security group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LsNzwokgw6WGMEFtvVpMAA.jpeg" /></figure><p>Open the “Security Group” we created and under “Inbound rules” select “Edit inbound rules”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YpBA9iXiXp-vV79RV7o_2g.jpeg" /></figure><p>Click “Add rule” twice and make the following configuration changes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*8RgNbs3JB-cGICxw8Y2ORA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iSl5D_8TiBTvuOZiJmJmUg.jpeg" /></figure><p>Save the rules just created by clicking “Save rules”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HXN9pp2uSqKUYviV1d6awg.jpeg" /></figure><p>3. SSH into your EC2 instance and install Apache with a custom webpage using a BASH script. (The webpage can be a simple Hello World or something more complex. We are not testing your HTML skills)</p><p>Now we are going to SSH into our EC2 instance. For this project I used PuTTY but you can also use the connect option in EC2. To SSH in we will need the public ip address and the public DNS address of our instance. To learn to SSH into an instance using PuTTY please kindly view this video on YouTube: <a href="https://www.youtube.com/watch?v=ncyovE-8fPo">https://www.youtube.com/watch?v=ncyovE-8fPo</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uvtmgx-Cidqm2TChtIcl7g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*KjdD_rLSmkV7ToEA8WNf4w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*KRUkOeKXsqUu7RJHzRxDzg.jpeg" /></figure><p>Now that we have SSH into our instance we are going to install Apache with a custom webpage using a BASH script. Here is the script:</p><p><strong><em>#!/bin/bash</em></strong></p><p><strong><em>sudo yum update -y</em></strong></p><p><strong><em>sudo yum install httpd -y</em></strong></p><p><strong><em>sudo systemctl start httpd</em></strong></p><p><strong><em>sudo systemctl enable httpd</em></strong></p><p><strong><em>echo “Hello World from $(hostname -f)” | sudo tee /var/www/html/index.html</em></strong></p><p>Now, we need to run the scripts one at a time to install the Apache web server on our instance. It should be noted the “Sudo” (root privilege ) is required to install, remove or change any software. Now I will explain what each of the command aims to do:</p><p><strong><em>sudo yum update -y:</em></strong></p><p>Updates all the packages to their most recent version</p><p><strong><em>sudo yum install httpd -y OR sudo yum install -y httpd.x86_64:</em></strong></p><p>Installs Apache Web Server</p><p><strong><em>sudo systemctl start httpd:</em></strong></p><p>Will start the Apache server</p><p><strong><em>sudo systemctl enable httpd:</em></strong></p><p>Server will auto start on system boot</p><p><strong><em>echo “Hello World from $(hostname -f)” | sudo tee /var/www/html/index.html:</em></strong></p><p>This is what will show on our web page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*2wD3UKuDZfTs48WhtyJBuQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YjMuzSyg2sWLvaoRI3peHQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*X0sbz_nEk_iyo-yeHkSHVg.jpeg" /></figure><p>After the script has finished running, you should be able to access your custom webpage by visiting the public IP address of your EC2 instance in a web browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*h1i31kVgZbqlvJcHJFixUQ.jpeg" /></figure><p>We have now hosted a website in an EC2 instance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8dfa301478d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>