<?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 Happiness O on Medium]]></title>
        <description><![CDATA[Stories by Happiness O on Medium]]></description>
        <link>https://medium.com/@chinenyeoluedo?source=rss-4833e2eec49b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pDyYgEcqaz4SOyP-lXAaxw.jpeg</url>
            <title>Stories by Happiness O on Medium</title>
            <link>https://medium.com/@chinenyeoluedo?source=rss-4833e2eec49b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 12:00:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chinenyeoluedo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building an Apache Webserver on Scalable EC2 Instances using Terraform as IAC tool]]></title>
            <link>https://medium.com/@chinenyeoluedo/building-an-apache-webserver-on-scalable-ec2-instances-using-terraform-as-iac-tool-e0fcd77c7126?source=rss-4833e2eec49b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0fcd77c7126</guid>
            <dc:creator><![CDATA[Happiness O]]></dc:creator>
            <pubDate>Sat, 26 Oct 2024 11:21:59 GMT</pubDate>
            <atom:updated>2024-10-26T11:21:59.437Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/582/0*55LVV7zkPQxCII8G.png" /></figure><p>Architectural diagram representing EC2 autoscaling using CloudWatch Alarms</p><h3>Scenario</h3><p>Developers are constantly using tools like Terraform and autoscaling features to allow seamless workflow resulting in high productivity.</p><p>In this project I will autoscale EC2 Instances to manage the running of an apache webserver based on CPU metrics. An autoscaling group (ASG) will be established using the launch template with traffic managed by a load balancer. A scaling policy with lifecycle arguments will be implemented to avoid unwanted scaling. Terraform will be used to deploy the underlaying infrastructure on AWS.</p><h3>Objectives</h3><ul><li>Install Terraform</li><li>Create a file that enables Terraform to interact with AWS</li><li>Deploy a VPC with 3 public &amp; 3 private subnets across 3 availability zone (AZ)</li><li>Create ALB with Target groups and configure health checks</li><li>Create a Launch Template and customise User Data script to deploy an Apache Webserver</li><li>Configure ASG to be spread over 3 AZ’s in private subnets.</li><li>Create dynamic scaling policy to maintain CPU utilisation at an optimum</li></ul><h3>Pre-requisites</h3><ul><li>AWS account (free-tier) with programatic access</li><li>Install Terraform</li><li>Visual Studio Code</li><li>Source code can be obtained from: <a href="https://github.com/mokhaircc2/Terraform_autoscaling">https://</a><a href="https://github.com/chinnyo/Terraform-Project">https://github.com/chinnyo/Terraform-Project</a></li></ul><h3>The Task</h3><p>Firstly create a folder called Teraform-autoscalling. This folder will have all Terraform codes required to run this project. Using Visual Studio Code open this folder and create a file called provider.tf, with the codes as shown on the diagram below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*eLK3NxuZ7eNU1iNO.png" /></figure><p>provider.tf codes</p><p>The code in the provider.tf file enables interaction of terraform with AWS using an API. Initialise the backend by typing ‘<strong>terraform init</strong>’ on the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*YtMQqw8pRx7zUvEv.png" /></figure><p>terraform init — initialises the backend</p><p>Now create a VPC file (vpc.tf) which contains the codes for creating public/private subnets, Internet Gateway, route table for public/private subnets, Elastic IP and NAT Gateway. as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*C8NMdx6LowqRdeQT.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*2LHugN6Uusnr_w9R.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*08NGKZdy3r9NoDtq.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*FD0o8j7ruHwQLnah.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*CY3BHkuHb5co2i6h.png" /></figure><p>VPC and its resources</p><p>The IP addresses for the virtual private cloud (VPC) are represented using Classless Inter-Domain Routing (CIDR) notation. A VPC must have an associated IPv4 CIDR block. The allowed block size is between a /16 netmask (65,536 IP addresses) and /28 netmask (16 IP addresses).</p><p>A good practice is to write a small section of the code and run it. This shows the outcome on the AWS console and errors are more easily detected early on.</p><p>Next, type the ‘<strong>terraform plan’</strong> command, which creates a plan consisting of resources matching the configuration laid out on the terraform script. In other words, terraform plan (also known as a dry run) shows you a preview of the actions Terraform would take to create/modify the infrastructure before applying them.</p><p>Next, type in the <strong>‘terraform apply’</strong> command which prompts you to approve that plan, and takes the indicated actions. You can pass the “<strong>terraform apply -auto-approve</strong>” to instruct Terraform to apply the plan without asking for confirmation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*fpNAXZcMpfYWZf5x.png" /></figure><p>terraform apply -auto-approve deploys the resources</p><p>Now view the outcome deployed on the AWS console. Here you can see that 6 subnets have been created, 3 public and 3 private subnets, each connected to its designated route table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*foc8CZT2A47kCoC1.png" /></figure><p>Deployment of VPC and resources using terraform</p><p>A <strong>variables.tf</strong> file is created in the Terraform folder using the code shown below. This file contains input variables which allows you to customise aspects of Terraform modules without altering the module’s own source code.</p><p>This functionality allows you to share modules across different Terraform configurations, making your module composable and reusable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*YKhCdYLMDKOIIUiu.png" /></figure><p>variables.tf file</p><p>Save the <strong>variables.tf</strong> and run the command <strong>‘terraform plan</strong>’, then ‘<strong>terraform apply</strong>’ to deploy the resources.</p><p>Next create an <strong>alb.tf </strong>file using the codes shown below. The alb.tf file specifies the security group of the ALB, which ports are opened, Target Groups, Health Checks and Listeners. Save the file and run the command <strong>‘terraform plan</strong>’, then ‘<strong>terraform apply</strong>’, and see the resources being deployed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*rQfMu4QnXPFhNTDi.png" /></figure><p>alb.tf script</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*BBGYXYy9vROfWXVo.png" /></figure><p>alb.tf script</p><p>The Launch Template file (launche_templates.tf) contains codes describing about security groups, AMI, instance type, user data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*L0OBzD-FjK3wAkga.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Lkg7dnAvEkNydp-8.png" /></figure><p>launch_template.</p><p>Once the l<strong>aunch_template.tf</strong> file is created, save it and run the command <strong>‘terraform plan</strong>’, then ‘<strong>terraform apply</strong>’, and see the resources being deployed.</p><p>A user data is used to customise instances. When an instance is launched, you can store parameters or scripts as user data. These sets of commands are run when you launch an instance. In my user data script I will run an Apache webserver on an EC2 instance, with a custom message stating the ip address of the instance. Below is the scripts file I used:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*TTxv2qTw-HHQUmmc.png" /></figure><p>userdata script</p><p>Retrieve the DNS name of the load balancer from the AWS console, and paste it on the web browser which will show the custom message of the EC2 instance ip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/0*SYYpLq8bHHXLXCHX.png" /></figure><p>ip address of running EC2 instance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/0*lgh2iopxsLgq3q5E.png" /></figure><p>ip address of second EC2 instance</p><p>Auto Scaling is a feature on AWS that automatically adjusts the number of EC2 instances in an Auto Scaling group based on predefined conditions. It helps maintain the desired number of instances to handle varying workloads.</p><p>Scaling policies define conditions like CPU utilisation or network traffic, triggering scale-in or scale-out actions.</p><p>The Auto-Scaling Group file (<strong>asg.tf</strong>) shown below contains the code required to deploy the desired number of instances, based on CloudWatch Alarms and scaling policies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*jXrc-L_eApONMMfW.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*KwaVQfUIHLZKzwLg.png" /></figure><p>asg.tf file</p><p>Once the <strong>asg.tf</strong> file is created, save it and run the command <strong>‘terraform plan</strong>’, then ‘<strong>terraform apply</strong>’, and see the resources deploy in AWS.</p><p>To verify that scaling policy is working I can run a test from the AWS CLI with the command <strong>set-alarm-state</strong>. This temporarily changes the state of an Amazon CloudWatch alarm named “apache_cpu_alarm_up” and sets it to the ALARM state. Copy the command as shown below on to AWS CloudShell (on the console):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*bbtq9t6c6-NF4auh.png" /></figure><p>Command for changing alarm state</p><p>This command returns to the prompt if successful. On CloudWatch you can now see the “apache_cpu_alarm_up” is in an alarm state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*pKNid4TCH-QVItsE.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*ejmtQu4d_etdMU9v.png" /></figure><p>CloudWatch detects extra load on server</p><p>After a brief moment you can see that CloudWatch scaling policy has triggered another EC2 to be launched to handle the load, as can be seen on the diagram below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*uYzunWlM1_9gy3hw.png" /></figure><p>Autoscaling launching an extra EC2 instance to handle the load</p><p><strong>Conclusion</strong></p><p>Autoscaling is a crucial aspect of cloud computing that enables organisations to manage their computing resources effectively based on scaling policies that you define. It enables an application to automatically increase or decrease its capacity in response to changing demand, ensuring that users always have access to the resources they need. Autoscaling provides many advantages such as improved resource utilisation, cost-effectiveness, scalability, high availability, and easy management.</p><p>Terraform is an infrastructure as code tool that lets you define infrastructure resources that you can version, reuse and share and therefore helps you manage your entire IT ecosystem. Terraform creates and manages resources on cloud platforms and other services through their application programming interfaces (APIs).</p><p>Using Terraform and autoscaling features, developers are able to increase their efficiency in a seamless workflow and being more productive on their task management. Don’t forget to delete all resources deployed by typing the ‘<strong>terraform destroy</strong>’ command to avoid unwanted cost.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0fcd77c7126" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitor AWS EC2 Disk and Memory usage using CloudWatch alarms, and sending SNS notification to user]]></title>
            <link>https://medium.com/@chinenyeoluedo/monitor-aws-ec2-disk-and-memory-usage-using-cloudwatch-alarms-and-sending-sns-notification-to-user-b13503f1edba?source=rss-4833e2eec49b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b13503f1edba</guid>
            <dc:creator><![CDATA[Happiness O]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 16:42:30 GMT</pubDate>
            <atom:updated>2024-10-20T16:42:30.260Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/367/0*dNUbf1ncT9eijL4A.png" /></figure><p>On the AWS console launch an EC2 instance, select Amazon Linux free tier, instance type — t2.micro, and create key pair.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*S121Fsn0yJd1mE9Y.png" /></figure><p>Go to IAM and create an IAM role for EC2 to assume — “CloudWatchAgentServerPolicy”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*JpBwep_PzLCl6EN4.png" /></figure><p>—</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*0SqqBdqiMwdi1Z4w.png" /></figure><p>After role is created, go to EC2, Actions, Security, modify IAM role and attach the role created from the drop down menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*WvPsEUI43KCRy3Fs.png" /></figure><p>Connect to EC2 via EC2 instance connect, and update Linux server by typing:</p><p><strong>sudo yum update -y</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*aJhB5mocQEdVHrxh.png" /></figure><p>Download and install the CloudWatch agent package with the following command:</p><p><strong>sudo yum install amazon-cloudwatch-agent</strong></p><p>when prompted answer ‘yes’ and press ‘enter’ key</p><p>Download link:</p><p><strong>wget </strong><a href="https://amazoncloudwatch-agent.s3.amazonaws.com/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm"><strong>https://amazoncloudwatch-agent.s3.amazonaws.com/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm</strong></a></p><p>Install the package:</p><p><strong>sudo rpm -U ./amazon-cloudwatch-agent.rpm</strong></p><p>Create a CloudWatch agent configuration file. The agent configuration file is a JSON file that specifies the metrics and logs that the agent is to collect, including custom metrics. This can be achieved by the wizard or customised manually (manual configuration is complex but you gain more control of the metrics/logs). In my case I will use the wizard by entering the following command:</p><p><strong>sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard</strong></p><p>Answer the questions to customise the configuration file for your server (mainly default settings) and then select advanced metrics, and continue with the customisation. When asked about the log file pathway the following is used:</p><p><strong>/opt/aws/amazon-cloudwatch-agent/bin/config.json</strong></p><p>To start the CloudWatch agent the following command is used:</p><p><strong>sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json</strong></p><p>To show status of agent:</p><p><strong>sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/0*zqRY-LXOdHrO7nVZ.png" /></figure><p>Now create Alarms for memory usage by returning to the console. Go to CloudWatch, create alarm, select metrics, select CWagent, InstanceID, select “mem_used_percent” on the metric name, and configure your alarm e.g alarm condition where the threshold is greater than or equal to 70.</p><p>Create a topic with SNS, provide e-mail for notification and confirm the e-mail to accept SNS subscription.</p><p>Repeat the same for Disk utilisation (disk_used_percent) and create an Alarm using the same topic ARN created previously.</p><p>Now CloudWatch Alarms is set to monitor CPU disk ad memory usage, and will inform you if the parameters are breached.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b13503f1edba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[User notification upon object upload/delete on Amazon S3]]></title>
            <link>https://medium.com/@chinenyeoluedo/user-notification-upon-object-upload-delete-on-amazon-s3-e2ee5911bded?source=rss-4833e2eec49b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2ee5911bded</guid>
            <dc:creator><![CDATA[Happiness O]]></dc:creator>
            <pubDate>Thu, 17 Oct 2024 17:44:04 GMT</pubDate>
            <atom:updated>2024-10-17T17:44:04.410Z</atom:updated>
            <content:encoded><![CDATA[<p>In this project I will use a Lambda function to trigger a SNS notification when an object is uploaded or deleted on Amazon S3. AWS Lambda is a serverless event-driven compute service that lets you run code for virtually any type of application or backend service without provisioning or managing servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*IlRjA57BQogUAzko.png" /></figure><p>Firstly log onto your AWS account and create a S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*gCewNtXT2FsNK6Da.png" /></figure><p>Create S3 Bucket</p><p>Now create a topic in SNS with a subscription to an email address. If you send a message to a topic, Amazon SNS delivers the message to each endpoint that is subscribed to the topic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*k4S5McmJb6Y1xrUB.png" /></figure><p>SNS topic</p><p>Now create a lambda function using python 3.9 or later</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*MrPE3tNkfM5qJH_-.png" /></figure><p>Configure Lambda</p><p>Give Lambda the permission to connect to SNS by firstly going to configuration and permission and then select role name which will open up an IAM window</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*BXUvtPuW3svb8fSp.png" /></figure><p>Lambda permission configuration</p><p>Under permission policies select add permissions and add policies, and on the search bar type SNS and a list will be shown. Tick AmazonSNSFullAccess and add permission. This will now add the relevant policy to the Lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*JaSu4w93h5zjrKLF.png" /></figure><p>Attach IAM policy with SNS full access</p><p>Now to link the AWS services used — go to s3 bucket, properties and configure event notification</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*W2PJ2MyENJLaKKGu.png" /></figure><p>Configure S3 Event notification</p><p>On object creation tick the box for put, post and permanently deleted. This specifies an event which I want to receive notifications for.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*ULpWlj3D0b-c-otH.png" /></figure><p>Notification upon put/post and delete of objects</p><p>Select Lambda function, as this is what is triggered after s3 is uploaded/deleted with an object</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*JyUsl_XlEBbvWjWg.png" /></figure><p>Lambda execution upon object upload/delete on S3</p><p>Now on the Lambda page the code must be written to trigger these events. Using the AWS documentation for boto3 we can obtain the client for SNS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*MQpwcUgruO8jNSWE.png" /></figure><p>Lambda code to trigger SNS notification</p><p>Select Test, and on the Test event page create a new event and select event name as s3-put. The Json code shows information regarding the bucket, objects as well as request and response parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*bpEdcgFkGD-2xhCy.png" /></figure><p>json script for test event</p><p>Next I will modify the Lambda function code to only show bucket name (“name”) and object name (“key”). This provides data which is more readable when sent as an email. The code would look like the diagram below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*ryhiHT2Iq-TvT3Yv.png" /></figure><p>Configure Lambda code to disclose information on bucket and objects only</p><p>Now select deploy and test. The results should look something like the diagram below when is successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*22zoBjVtkPn72OQP.png" /></figure><p>Test Lambda code</p><p>Once the Lambda test is successful I will now upload an object to S3 from the console. Upon upload the user receives a notification with bucket and object name. The same is true if an object is deleted from the console where the user receives an email notification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*323-7YJ74RXMkxa8.png" /><figcaption>email notification when object has been uploaded</figcaption></figure><p>In conclusion to this project we can understand that the power of Lambda is very dynamic and efficient as well as cost productive. There is no need to use an EC2 instance instead of a Lambda, as the EC2 is continuously running and you pay for the compute for being inactive even if nothing gets uploaded/deleted on S3.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2ee5911bded" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scheduling EC2 Instances Using Lambda]]></title>
            <link>https://medium.com/@chinenyeoluedo/scheduling-ec2-instances-using-lambda-6fd756d022a6?source=rss-4833e2eec49b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fd756d022a6</guid>
            <dc:creator><![CDATA[Happiness O]]></dc:creator>
            <pubDate>Wed, 09 Oct 2024 21:13:09 GMT</pubDate>
            <atom:updated>2024-10-09T21:13:09.344Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*dasDKft8j2NgifX6.png" /></figure><p>Architectural representation of EC2 Scheduling</p><p><strong>Scenario</strong></p><p>In this project I will use CloudWatch Event triggers and Lambda’s to turn EC2 instances on at 9am and off at 5pm, Mon-Fri. The purpose of this is to prevent instances from running outside of working hours and hence a simple cost optimisation strategy.</p><p><strong>Objectives</strong></p><ul><li>Launch EC2 instance</li><li>Create a Lambda function</li><li>Configure IAM roles</li><li>Write a code using Boto3 for Lambda</li><li>Test codes</li><li>Create an EventBridge schedular to trigger the Lambda function at a specific time</li></ul><p><strong>Pre-requisites</strong></p><ul><li>AWS account (free-tier)</li></ul><p><strong>Task</strong></p><p>On the AWS console launch an EC2 instance: Amazon Linux 2023 AMI, Instance type t2-micro. After the EC2 instance has been launched and status shows it’s in a running state, then stop the running instance.</p><p>Now create a Lambda function that gets invoked to start a stopped EC2 instance. I will use the following parameters as shown in the diagram below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*ZS18QqcnmIFrlRZc.png" /></figure><p>Once Lambda function is created configure the IAM permission to allow EC2 full access. This is achieved by going to configuration, permission, and select role name, a window will open in IAM. Add permission and attach policy to allow EC2 full access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*zHG0o8bV_QcN13hJ.png" /></figure><p>IAM permission attached to EC2</p><p>Now in the Lambda function write a code in Boto3 to start an instance. These codes can be found on the AWS boto3 documentation. The code includes the Boto3 Client, and in the response section the EC2 instance-ID as shown in the diagram below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*AdqIG4uXxT90hZWo.png" /></figure><p>Lambda code for starting a stopped instance</p><p>Deploy and test the lambda code to see that it works. If successful the response should be like the diagram below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*8BKr4cIgiAZSD-ef.png" /></figure><p>Once the lambda is triggered check the status of the EC2 instance that it now shows as running</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*L1R3fbzAPQti8p6Q.png" /></figure><p>Lambda triggered stopped EC2 to start and is running</p><p>Now create a second Lambda function with EC2 full access permission but this time when triggered will stop a running EC2 instance. The Lambda code used is shown in the diagram below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*JosaqH0txltfwLQE.png" /></figure><p>Lambda Code for stopping a running EC2 Inscance</p><p>On the AWS console go to CloudWatch and create a rule that runs on a schedule. So when an event occurs, the rule triggers the Lambda function to run the code.</p><p>I will use a cron-based scheduler which uses a cron expression to run at a specific time, i.e. Mon-Fri, 9:00am UTC time. At this scheduled time the Lambda function will be executed to start an instance.</p><p>You can use FreeFormatter.com (<a href="https://www.freeformatter.com/cron-expression-generator-quartz.html">https://www.freeformatter.com/cron-expression-generator-quartz.html</a>) to customise your cron expression for your specific schedule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*KvZ5YJ3MsWBZ5nib.png" /></figure><p>In the EventBridge Scheduler select the Recurring Schedule tab, and then Cron-based schedule, and configure the cron expression as shown in the diagram below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*HW5FMEtxL3lWMKXQ.png" /></figure><p>Cron expression for Scheduling EC2 to start at 9am, Mon-Fri</p><p>Next, select Lambda to be invoked, and select Lambda function which was created earlier from the drop down list (i.e. Start-EC2) and continue with default settings to create the schedule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/0*5aCiHQlZxwI5F9y1.png" /></figure><p>Now create a second CloudWatch Event Rule using the cron-scheduler and configuring the invocation of Lambda to stop a running EC2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*SjAseP3QI50AIg5U.png" /></figure><p>Cron expression for Scheduling EC2 to stop at 17pm, from Mon-Fri through out the year</p><p><strong>Conclusion</strong></p><p>I created a custom Lambda function that was able to trigger the Start/Stop action of an EC2 instance. To further automate this action on a schedule (Mon-Fri, 9am-5pm) I used CloudWatch Cron-expression. This project provides a simple solution to manage instances without incurring additional expense outside of business working hours.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fd756d022a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scenario]]></title>
            <link>https://medium.com/@chinenyeoluedo/scenario-6d7d27f22457?source=rss-4833e2eec49b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d7d27f22457</guid>
            <dc:creator><![CDATA[Happiness O]]></dc:creator>
            <pubDate>Wed, 09 Oct 2024 19:36:06 GMT</pubDate>
            <atom:updated>2024-10-09T19:36:06.964Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*ld48nwHPsaRLcoon.png" /></figure><p><strong>Scenario</strong></p><ul><li>In this project, I will be utilising GitHub and AWS CodeDeploy to automate the deployment process for applications running on EC2 instances in a Dev/Prod environment. Git is used for version control, ensuring code quality and facilitating collaboration through pull requests.</li></ul><p><strong>Key Tasks</strong></p><ul><li>Launch an EC2 Instance for the Dev and Prod environment</li><li>Create IAM roles</li><li>Write a UserData script to deploy an Apache web server</li><li>Create a CodePipeline that orchestrates the flow of code through different stages using GitHub as version Control</li><li>Merge the Dev branch to the Main branch in GitHub containing an updated version of index.html</li></ul><p><strong>Prerequisites</strong></p><ul><li>Must have a repository on GitHub with a Main and Dev branch</li></ul><h3>Create IAM roles for CodeDeploy and EC2</h3><ul><li>On the AWS Console, go to IAM and create a role for CodeDeploy, and a role for EC2 to assume the role of CodeDeploy.</li><li><strong>AmazoneEC2RoleforAWSCodeDeploy</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*SP9FexrBR7pvLkeX.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*UuFRRN93kjrAlO3j.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/0*Dqc38zZBNQPWCPmi.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/0*o0_SHETHOPwAPrkm.png" /></figure><h3>Create 2 EC2 Instances</h3><ul><li>One instance will be linked to the Prod environment and the other to the Dev environment</li><li>Use Amazon Linux 2 (free tier)</li><li>Create a security group allowing SSH on port 22 from your ip &amp; HTTP on port 80 from anywhere</li><li>We’re allowing SSH access, in the event that we need to troubleshoot</li><li>On the <strong>advanced details </strong>section select the <strong>IAM Instance Profile </strong>created in the previous step (<strong>EC2-CodeDeploy-Role</strong>)</li><li>In the <strong>User Data </strong>section copy and paste the commands below:</li></ul><pre>#!/bin/bash<br> <br>yum update -y<br>yum install httpd -y<br>systemctl start httpd<br>systemctl enable httpd<br></pre><pre>yum install ruby -y<br>yum install wget -y<br>wget <a href="https://aws-codedeploy-ap-southeast-2.s3.ap-southeast-2.amazonaws.com/latest/install">https://aws-codedeploy-ap-southeast-2.s3.ap-southeast-2.amazonaws.com/latest/install</a><br>chmod +x ./install<br>./install auto</pre><ul><li>This script installs Apache web server and the AWS CodeDeploy agent</li><li>You will need to change the <strong>bucket name</strong> and the <strong>region</strong> to match the region in which you want to launch your two instances.</li><li>Follow the documentation below:</li></ul><h3><a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-linux.html?source=post_page-----1958b51c092e--------------------------------">Install the CodeDeploy agent for Amazon Linux or RHEL</a></h3><h3><a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-linux.html?source=post_page-----1958b51c092e--------------------------------">Sign in to the instance, and run the following commands, one at a time. Running the command sudo yum update first is…</a></h3><p><a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-linux.html?source=post_page-----1958b51c092e--------------------------------">docs.aws.amazon.com</a></p><h3><a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/resource-kit.html?source=post_page-----1958b51c092e--------------------------------#resource-kit-bucket-names">CodeDeploy resource kit reference</a></h3><h3><a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/resource-kit.html?source=post_page-----1958b51c092e--------------------------------#resource-kit-bucket-names">Learn about the contents of the CodeDeploy Resource Kit.</a></h3><p><a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/resource-kit.html?source=post_page-----1958b51c092e--------------------------------#resource-kit-bucket-names">docs.aws.amazon.com</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*iRigALtJovd7tYDM.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*UyGdp3ETciYaoFVA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*a1wf_nviLpNWXUVt.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*BmH88U6JLozPt26u.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*uPYAXjyFkSBNrsoD.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*1mPgi0k8BIj0m-DU.png" /></figure><h3>Test the Apache Web Server</h3><ul><li>After the successfully create on your 2 instances</li><li>Copy the public ip of one of the newly created instances and paste it into a new tab</li><li>The Apache Test page should appear</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*Vq6ASefKAdw7tx8x.png" /></figure><h3>Configure Tags</h3><ul><li>Under the <strong>Tags </strong>section of each instance, you want to add the <strong>env </strong>key and the <strong>value</strong> of Dev for one instance and Prod for the other instance.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*RpA_KXir6Z55A5Jo.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*C1UKiszrdhCtMBcs.png" /></figure><h3>Create Apache Pipeline</h3><ul><li>Create the Apache pipeline which connects the Apache web server running on EC2 (Dev/Prod) to GitHub (Dev branch/Main branch)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*-y5zfssuI-UY2abr.png" /></figure><h3>Create Dev &amp; Prod Deployment Groups</h3><ul><li>Select the service role created in step 1</li><li>untick the <strong>Load Balancing box</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*0jVICey4zNWqQ0ve.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*i__4oBUvyn8TwIPh.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*oX3Sq85QepXkEQD8.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*aHEDuBkNU5QtkkSy.png" /></figure><ul><li>Repeat this process for the Prod Environment</li><li>Make sure you select the <strong>Prod </strong>Tag group</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*8JCix8p7vTsL15kW.png" /></figure><h3>Create Dev Pipeline</h3><ul><li>Create the Dev environment pipeline</li><li>Repeat this exact process to create the Prod pipeline for the Prod environment</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/0*ncJrjQSpxc207qOb.png" /></figure><h3>source provider</h3><ul><li>Select <strong>GitHub Version 2</strong></li><li>Select C<strong>onnect to GitHub</strong></li><li>Select <strong>Create a GitHub application</strong></li><li>a new AWS window should launch</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/229/0*jOYCbGkTjWK7q2K3.png" /></figure><ul><li>Click<strong> connect to to GitHub</strong></li><li>Click <strong>install a new app</strong></li><li>Select either all repositories or only this repository <strong>under repository access</strong></li><li>Click <strong>save</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*tkgzfAX8UAJGe1gT.png" /></figure><ul><li>Click <strong>connect</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*Iy3IqW-GZuXHhdFW.png" /></figure><ul><li>Select <strong>Dev</strong> branch as default branch</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*qTAXGa-YNrObOXpB.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*_CHDefHAXUoakCBq.png" /></figure><ul><li>Select <strong>skip build stage</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*UOc9iLgI9vCAfXhw.png" /></figure><ul><li>Lastly, click C<strong>reate pipeline</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*E7MG1lvF1txmj72T.png" /></figure><h3>Create index.html file</h3><ul><li>Inside this file write some HTML</li><li>This index file will be used to check whether the Dev branch is correctly feeding the Apache-Dev pipeline.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*qp3QAvCkyJJcduxD.png" /></figure><ul><li>Ensure that you are on the Dev branch</li><li>Push these changes to GitHub</li><li>This should trigger the Apache-Dev pipeline</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*yAXo7CVcdBiqi8wX.png" /></figure><p><strong>Stop execution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*LyxMXYp32eD6Mgpv.png" /></figure><ul><li>The pipeline will be triggered, but won’t be able to complete successfully, due to the absence of the <strong>appspec.yml </strong>file present.</li><li>The appspec.yml file provides instructions to CodeDeploy on what to do with the code that is pushed to GitHub.</li></ul><h3>Create appspec.yml file</h3><ul><li>Ensure that you are on the Dev branch</li><li>Create an <strong>appspec.yml </strong>file on the root of your directory, <strong>must be on the root</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*zmq1EhyAmT51Iu0w.png" /></figure><ul><li>add this code to the appspec.yml file:</li></ul><pre>version: 0.0<br>os: linux<br>files:<br>  - source: /<br>    destination: /var/www/html</pre><h3><a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file.html?source=post_page-----1958b51c092e--------------------------------">CodeDeploy AppSpec file reference</a></h3><h3><a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file.html?source=post_page-----1958b51c092e--------------------------------">Learn about the structure and sections of the AppSpec file used in CodeDeploy.</a></h3><p><a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file.html?source=post_page-----1958b51c092e--------------------------------">docs.aws.amazon.com</a></p><ul><li>Push these changes to GitHub</li><li>This shoud once again trigger the Apache-Dev pipeline and lead to the successful deployment of your code down the pipeline to the Dev EC2 instance.</li><li>To confirm the success of the deployment, copy the public ip address of the EC2 instance tagged Dev and paste it into a new tab.</li><li>The contents of the <strong>index.html</strong> file that you created earlier should be displayed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*LuH0jcL7eZBhTDPT.png" /></figure><ul><li>Copy the public ip of the EC2 instance tagged <strong>Prod</strong></li><li>Ensure that the Prod pipeline isn’t receiving any code changes from the Dev branch</li><li>The public ip of the Prod EC2 should still display the Apache Test web page</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*ukfh5cndnW6xusA3.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*NJOcfoN2jMEYoRY8.png" /></figure><h3>Merging Dev Branch with Main Branch</h3><ul><li>To merge the changes made in the Dev branch with the Main/Prod branch you need to make a <strong>compare &amp; pull request.</strong></li><li>Usually, this is where a senior team member would review your code changes and decide whether to implement them into the Main/Prod branch.</li><li>Merge to Dev branch</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*zQd7PaCd5FpuL3VV.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/0*0gVM2IMhDbpQM99s.png" /></figure><ul><li>After merging the two branches the Main branch will now have the changes made on the Dev branch implemented into the Main branch.</li></ul><p><strong>Testing the Apache-Prod Environment</strong></p><ul><li>Copy and paste the EC2 instance tagged <strong>Prod</strong> in a web browser</li><li>Because we merged the two branches, you should now see the same index.html file that was displayed when we launched the public ip of the EC2 Dev instance.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*q8ni30zMKPwn7-OP.png" /></figure><h3>Conclusion</h3><ul><li>Continuous integration (CI) and Continuous Delivery (CD) pave the way for a faster and more efficient approach to integrating the work of different team members into one cohesive task.</li><li>In DevOps, CI/CD is a set of practices that help the application development teams streamline the entire software development lifecycle, from the development and testing phases to the delivery and deployment phases.</li><li>This enables the teams to integrate and deliver new code changes more frequently and reliably. While the CI approach continuously integrates code changes into a shared branch, the CD approach automates the release and rollout of the application after integration.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d7d27f22457" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Architectural overview of Autoscaling Apache webserver]]></title>
            <link>https://medium.com/@chinenyeoluedo/architectural-overview-of-autoscaling-apache-webserver-b94250a97b69?source=rss-4833e2eec49b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b94250a97b69</guid>
            <dc:creator><![CDATA[Happiness O]]></dc:creator>
            <pubDate>Wed, 09 Oct 2024 19:18:58 GMT</pubDate>
            <atom:updated>2024-10-09T19:18:58.004Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*UamwwTU4mo7G2LzE.png" /></figure><p>Architectural overview of Autoscaling Apache webserver</p><p><strong>Scenario</strong></p><p>In this article I will be designing a highly available Apache webserver hosted on an EC2 instance, which will be automatically provisioned/terminated using scaling policies based on CPU utilisation. An autoscaling group (ASG) will be established using the launch template with traffic managed by a load balancer.</p><p><strong>Objectives</strong></p><ul><li>Deploy a VPC with 3 public &amp; 3 private subnets across 3 availability zone (AZ)</li><li>Create ALB with Target groups and configure health checks</li><li>Create a Launch Template and customise User Data script to deploy an Apache Webserver</li><li>Configure ASG to be spread over 3 AZ’s in private subnets.</li><li>Create dynamic scaling policy to maintain CPU utilisation at an optimum</li></ul><p><strong>Pre-requisites</strong></p><ul><li>AWS account (free-tier)</li></ul><p><strong>Task</strong></p><p>On the AWS console create a VPC and select 3 availability zones (AZ’s) for high availability and disaster recovery. The AZ’s are the location of the AWS datacenter within a region. If one datacenter develops an outage then you still have resources running in the other AZ’s. Select one NAT gateway in one AZ, but for high availability you can select one NAT gateway per AZ (however this comes at a cost).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*RbuLP5nWzCOGBObi.png" /></figure><p>Customised VPC</p><p>Now create an Application Load Balancer (ALB), and selecting the custom VPC that was created (development-VPC, in my case). The ALB will be deployed in all 3 AZ’s in the public subnets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/0*VkIZgxhGS8VMzjmU.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/0*Qcr8xo0Crs3fLaw6.png" /></figure><p>Customising ALB</p><p>Remove the default security group (SG) and create a new security group for ALB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*w7skxCcjPdUmJ-81.png" /></figure><p>Customise ALB-SG to be used in the VPC created. Configure inbound rule to allow HTTP traffic from anywhere and allow outbound rule from all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*93NQyslszO1k8L4-.png" /></figure><p>ALB-SG configuration</p><p>Now back on the ALB page refresh the SG, and from the drop down list select the ALB-SG that was created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*udNYcWk2koiKhBpM.png" /></figure><p>Next create Target Group (TG).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*9UlIV_IJKCFTlLrN.png" /></figure><p>A window will open and configure Target Group as follows::</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/0*4Otva1OVlUXFa9hY.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/0*htEXdTIU2HtZUD4I.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*YVFKoVO509RvfbI-.png" /></figure><p>Once the TG is created go back to the ALB page and refresh TG listing and from the drop down list select the TG that was created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*7vRWLPfZNFSbObrg.png" /></figure><p>ALB Listeners and Target group configuration</p><p>Now complete creating the ALB. This may take some time to provision.</p><p>Next create a Launch template. Choose Amazon linux 2023 AMI and t2 micro instance (all free tier eligible), no need for a key pair as I will not SSH into it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/0*yLimmufuARJvaeyg.png" /></figure><p>Launch Template configuration</p><p>Create a custom SG for the EC2 in the Launch Template. This is where I will make security group least permissible as possible. This means that traffic to my Apache webserver (EC2) is only coming from our ALB-SG. Encrypting EBS volume is good practice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/0*F4R39OKFf0xttOqD.png" /></figure><p>Launch Template configuration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/0*MZj3wOqQIJTxz33B.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/0*Xvz-d32Io_34oXZF.png" /></figure><p>Launch Template configuration</p><p>The user data script is a bootstrap script which has commands to configure the instance at the first launch. In my script after the Apache webserver is installed it will print the DNS name of the EC2 (hostname) into the pathway /var/www/html/index.html.</p><p>When you copy the DNS name of the ALB and paste it on the browser a message will appear with the IP address of the server.</p><p>Next create the Auto Scaling Group (ASG) with the following configuration shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*06RG_AQ-Ch3Drmmw.png" /></figure><p>Configure ASG to be spread over 3 AZ’s in private subnets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*FmYgmaKH1ZdwcOQX.png" /></figure><p>ASG is spread over 3 AZ’s in the private subnets within the custom VPC</p><p>Enable ELB health checks, which monitors the running of the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/0*ZS6jieUHE1sk4jOJ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/0*qOa_BQwcgSd938BW.png" /></figure><p>Configure the scaling limits of instances:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*rklYlWy9i8wJYVwZ.png" /></figure><p>Tag all instances that are launched. This helps to manage and identify which ASG the instance belongs to</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*DawvsoYuE_NR8kox.png" /></figure><p>Tagging your instance helps you to manage and grouping them</p><p>Next review and create ASG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*DXecaWKLEjEHmMMO.png" /></figure><p>After ASG is created you can see the activity of the launch template — it creates 2 instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*6JPgc5FHtopMLTd9.png" /></figure><p>ASG activity</p><p>The instances are all running and healthy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*96aV7ct6ezYUCGoI.png" /></figure><p>The ALB activity is shown to be in an active state and the listeners are checking for connection request. Once traffic is received by the listener then its routed to the TG as specified within the rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*MankRdjLjsKIMs98.png" /></figure><p>Copy the DNS name of the ALB and paste it on the web browser where you will see the message of the hostname. If you refresh the page you will see the IP of the second instance. This is because the ALB distributes the traffic between the two instances, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/0*TPJLnN_iIgg6fDLY.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*674LgwpigOv8m4mo.png" /></figure><p>IP address of the two instances that the traffic cycles between</p><p>Manually terminating one of the instance causes the ASG to trigger another EC2 to be launched as indicated in the rules (desired min of 2 instances to be running at anytime). This is a self healing function of ASG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*kxMwInbz-pb_kwWs.png" /></figure><p>Terminating an instance causes ASG to launch another instance</p><p>If a launch template need to be updated for example to modify the user data script, then go to launch template and select the current launch template. Then in “actions” modify template. This will create a new updated version which takes effect as soon as a new instance is launched.</p><p>Now create simple scaling policy by going to ASG and “automatic scaling” and select create “dynamic scaling policy”. Select simple scaling from the drop down list and create a CloudWatch alarm. This alarm indicates when to scale out (i.e increase the number of instances). Select “metric”, “EC2”, and select the autoscaling group name (in my case its apache-asg) which is associated with CPU utilisation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*JPNHnahjBbbGMrPC.png" /></figure><p>Next set the parameters where the CPU utilisation is greater than 70, the ASG will launch an instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*sMz7nW3Es8MqPcXr.png" /></figure><p>Configuring CloudWatch alarm with ASG</p><p>Next on the notification page, remove the “alarm state trigger” because this action will be stated in our alarm policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4nMQhONhCEqYMghp.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BUHQFp4WVKbtBKLm.png" /></figure><p>Now create another dynamic policy called Scaling In policy, which gets triggered when CPU utilisation is lower than or equal to 30, then instance is removed.</p><p>Now to test cloudwatch alarms go to the cloudshell and run the following scipt:</p><p>aws cloudwatch set-alarm-state — alarm-name “Scale out” — state-value ALARM — state-reason “Testing purpose”</p><p>A target tracking scaling policy automatically scales the capacity of your Auto Scaling group based on a target metric value. This allows your application to maintain optimal performance and cost efficiency without manual intervention.</p><p>With target tracking, you select a metric and a target value to represent the ideal average utilisation or throughput level for your application. Amazon EC2 Auto Scaling creates and manages the CloudWatch alarms that invoke scaling events when the metric deviates from the target. As an example, this is similar to how a thermostat maintains a target temperature.</p><p>For example, let’s say that you currently have an application that runs on two instances, and you want the CPU utilisation of the Auto Scaling group to stay at around 50 percent when the load on the application changes. This gives you extra capacity to handle traffic spikes without maintaining an excessive number of idle resources.</p><p>You can meet this need by creating a target tracking scaling policy that targets an average CPU utilisation of 50 percent. Then, your Auto Scaling group will scale out, or increase capacity, when CPU exceeds 50 percent to handle increased load. It will scale in, or decrease capacity, when CPU drops below 50 percent to optimise costs during periods of low utilisation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*37jLr7Cn7H0zrKN0.png" /></figure><p><strong>Conclusion</strong></p><p>Autoscaling is a crucial aspect of cloud computing that enables organisations to manage their computing resources effectively based on scaling policies that you define. It enables an application to automatically increase or decrease its capacity in response to changing demand, ensuring that users always have access to the resources they need. Autoscaling provides many advantages such as improved resource utilisation, cost-effectiveness, scalability, high availability, and easy management.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b94250a97b69" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three Tier AWS WordPress Deployment using EC2]]></title>
            <link>https://medium.com/@chinenyeoluedo/three-tier-aws-wordpress-deployment-using-ec2-9b1aee068665?source=rss-4833e2eec49b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b1aee068665</guid>
            <dc:creator><![CDATA[Happiness O]]></dc:creator>
            <pubDate>Tue, 08 Oct 2024 09:35:32 GMT</pubDate>
            <atom:updated>2024-10-08T09:35:32.554Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zc2XwWuJNRCoatkpme8jKw.png" /></figure><p>Have you ever wondered about writing a blog about your life experience or sharing some skills for others to follow or even to market yourself for a career change? If so, you could do all this on hosting your WordPress website on AWS. AWS has a number of different options for provisioning virtual machines. In this project I will be using Amazon EC2 to host a WordPress website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*6pIa44eEznB2vRbu.png" /></figure><h3>Objectives</h3><ul><li>Deploy a VPC with 3 public &amp; 3 private subnets across 3 availability zone (AZ)</li><li>Deploy RDS instance and WordPress (EC2) in a private subnet</li><li>Deploy Bastion EC2 server and Application Load Balancer (ALB) in the public subnet</li><li>Configure security groups (SG) and networking to allow traffic flow between the services</li><li>WordPress deployment on the browser using the DNS of the ALB</li></ul><h3>Pre-requisites</h3><ul><li>AWS account (free-tier)</li></ul><h3>Task</h3><h3>Setup VPC</h3><p>On the AWS console, type VPC on the search bar and create a VPC with the following parameters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*iugC8uSg1YqiIufh.png" /></figure><p>NAT gateway is a Network Address Translation (NAT) service that enables instances in a private subnet to send outbound traffic to the internet, while preventing the internet from establishing connections to the instances. It must be in a public subnet as it communicates with the Internet and needs a route to the Internet Gateway.</p><p>Here I will be deploying a NAT gateway in only 1 AZ, however if you require high availability and resiliency then you can deploy a NAT gateway in each AZ which will come at a higher price.</p><p>An internet gateway (IGW) is a horizontally scaled, redundant, and highly available VPC component that allows communication between the VPC and the internet. An internet gateway enables resources in the public subnets (such as EC2 instances) to connect to the internet.</p><p>Similarly, resources on the internet can initiate a connection to resources in the public subnet. AWS creates an IGW out of the box when you create a VPC with public subnets. AWS will automatically assign VPC CIDR range for all your resources and create the necessary route table for public and private subnets.</p><h3>Setup RDS and EC2’s</h3><p>On the search bar type RDS and select Create Database (DB), and use the following parameters shown in the diagrams below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*XW7aecKyjbMQ2lLW.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*zm2crLvuiJ0CH2sP.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*9BUtRw7PXZGqtlLm.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*jKarKqDMvpFjWXsK.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*gY0yWfdhgr7e9ugZ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*77aT8wJ9Lhp3F2OD.png" /></figure><p>Now create a WordPress (EC2) Server in the private subnet by going to search bar and typing EC2. Launch an instance with the following parameters below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*ZpUiiuOlU_Z-RG5K.png" /></figure><p>A key pair consists of a public key and a private key, and it’s a set of security credentials that is used to prove the users identity when connecting to an Amazon EC2 instance. For Linux instances, the private key allows the user to securely SSH into the instance.</p><p>Amazon EC2 stores the public key on the instance, and the user will store the private key on their local computer. It’s important that the private key is stored securely, and it’s saved as a PEM or PPK file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*W7Rjs3UTAiXgElD7.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*gvipvb8E4O4p0pOZ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*F7_7VqmpeZU0p7SF.png" /></figure><p>Now create a Bastion EC2 server in the public subnet. This allows a developer with permissions to connect (i.e SSH) into EC2 instances in a private subnet using the pem key.</p><p>In this project the Bastion EC2 server will have the same configuration as the WordPress EC2 except it will be located in any one of the public subnets, and therefore requires Auto-assign public IP switched on. Configure SG of Bastion EC2 to allow SSH from MY IP.</p><p><strong>Security group configuration for WordPress and RDS</strong></p><p>Best practice is to always grant the minimum required permissions in Security Groups (least privilege).</p><p>On the WordPress-EC2 go to security and configure the security group inbound rule. Delete the current rule and add a new rule to accept SSH traffic from Bastion-sg.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*nMFvuplrw3RtBCB-.png" /></figure><p>On the RDS instance edit security group inbound rules by deleting current rule and customising it to accept inbound traffic from WordPress-SG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Hg-U1zUczMVJoH4-.png" /></figure><p><strong>SSH to Bastion and WordPress Server</strong></p><p>Now I will connect to my Bastion host from my local computer, and from the Bastion EC2 access my WordPress server. For this I require the pem key to access the WordPress server. On the terminal locate the pem key and from that directory type “<strong>cat WordPress-key-pair.pem</strong>” and copy the whole public (pem) key up to “<strong>%</strong>” and save it on a note pad of your choice to be used later on for the Bastion host .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Yo8MTvVav0DV5TcK.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*0Gu1PfAyrVr4NEP3.png" /></figure><p>Now back on the AWS console go to the Bastion-EC2 and select the connect button. Then Select SSH client.</p><p>I will use an SSH client on my macOS to connect to my Linux instance with the following command on the terminal:</p><pre>chmod 400 “Wordpress-key-pair.pem”</pre><p>followed by the SSH command, in my case its:</p><pre>ssh -i &quot;Wordpress-key-pair.pem&quot; ec2-user@ec2-54-171-243-55.eu-west-1.compute.amazonaws.com</pre><p>I have now SSH to my Bastion-EC2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*2OJRpsBYKBnvsY8c.png" /></figure><p>The next step is to retrieve the pem key from note pad and save it to command line text editor on the bastion host. Type the command below and save the pem key:</p><pre>nano WordPress-key-pair.pem</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*_kWr_V7ICh_yQOrJ.png" /></figure><p>Now type the“<strong>ls</strong>” command and the file “<strong>WordPress-key-pair.pem”</strong> is visible on the Bastion-EC2.</p><p>The next step on the AWS console is to get the SSH command key of the WordPress-EC2, and paste it onto the terminal Bastion-EC2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*JIwAMBvQQXyLWOuJ.png" /></figure><p>I have now connected to my WordPress instance with its unique private IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*GIenOcHTrBKxqiZg.png" /></figure><p><strong><em>NOTE:</em></strong><em> SSH agent forwarding should be enabled with caution as allowing SSH agent forwarding creates a security risk as anyone with root access on the remote host can directly access your local SSH agent through the socket and use the keys by impersonating you on other machines on the network.</em></p><h3>Configure WordPress and ALB</h3><p>LAMP is an acronym for the operating system, Linux; the web server, Apache; the database server, MySQL (MariaDB); and the programming language, PHP.</p><p>In this project I will use the Amazon Linux 2023 AMI (AL2023 AMI) and install the LAMP stack on it. If you are using a different distribution, such as Amazon Linux 2, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-lamp-amazon-linux-2.html">Install LAMP on Amazon Linux 2</a> on the AWS documentation. The following commands takes place on the terminal:</p><p>1. Perform a quick software update on the instance:</p><pre>sudo dnf update -y</pre><p>2. Install the latest versions of Apache web server and PHP packages for AL2023:</p><pre>sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel</pre><p>3. Install the MariaDB software packages. Use the <strong>dnf install</strong> command to install multiple software packages and all related dependencies at the same time:</p><pre>sudo dnf install mariadb105-server</pre><p>4. Start the Apache web server:</p><pre>sudo systemctl start httpd</pre><p>5. Use the next command to start the Apache we server at each system boot:</p><pre>sudo systemctl enable httpd</pre><p>6. Verify that <strong>httpd</strong> is on by running:</p><pre>sudo systemctl is-enabled httpd</pre><p>7. Set file permissions by adding the user (in this case, ec2-user) to the apache group:</p><pre>sudo usermod -a -G apache ec2-user</pre><p>8. Log out and then log back in again to pick up the new group. Log out (use the exit command or close the terminal window):</p><pre>exit</pre><p>9. Verify the membership in the apache group by reconnecting to the instance, and then run the following command:</p><pre>groups</pre><p>10. Change the group ownership of /var/www and its contents to the apache group:</p><pre>sudo chown -R ec2-user:apache /var/www</pre><p>11. To add group write permissions and to set the group ID on future subdirectories, change the directory permissions of /var/www and its subdirectories.</p><pre>sudo chmod 2775 /var/www &amp;&amp; find /var/www -type d -exec sudo chmod 2775 {} \;</pre><p>12. To add group write permissions, recursively change the file permissions of /var/www and its subdirectories:</p><pre>find /var/www -type f -exec sudo chmod 0664 {} \;</pre><p>13. Test LAMP server. Create a PHP file in the Apache document root:</p><pre>echo &quot;&lt;?php phpinfo(); ?&gt;&quot; &gt; /var/www/html/phpinfo.php</pre><p>14. Verify that all of the required packages were installed with the following command:</p><pre>sudo dnf list installed httpd mariadb-server php-mysqlnd</pre><p>15. Delete the phpinfo.php file, it should not be broadcasted to the internet for security reasons:</p><pre>rm /var/www/html/phpinfo.php</pre><p>I don’t need to secure the database server manually as shown on the AWS documentation because I am using RDS (AWS managed service).</p><p>Now I will install the WordPress on AL2023 (<a href="https://docs.aws.amazon.com/linux/al2023/ug/hosting-wordpress-aml-2023.html">https://docs.aws.amazon.com/linux/al2023/ug/hosting-wordpress-aml-2023.html</a>).</p><p>16. Download and install Mysql-MariaDB packages:</p><pre>dnf install wget php-mysqlnd httpd php-fpm php-mysqli mariadb105-server php-json php php-devel -y</pre><p>17. Download the latest WordPress installation package:</p><pre>wget https://wordpress.org/latest.tar.gz</pre><p>18. Unzip and unarchive the installation package. The installation folder is unzipped to a folder called wordpress:</p><pre>tar -xzf latest.tar.gz</pre><p>19. Create a database user and database for the WordPress installation. First start the database and web server:</p><pre>sudo systemctl start mariadb httpd</pre><p>20. If you require root privilege while executing the command then type sudo in front of the command. Connect to the MariaDB database with the following command:</p><pre>mysql -h wordpress-rds.cdoycwk2maho.eu-west-1.rds.amazonaws.com -u admin -p</pre><p>“-h” stands for host followed by the RDS DNS name found from the RDS instance and “-u” represents user name and “-p” is password. Enter the password which was done during RDS setup — in my case its “password”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Wk-A0UqFX_AR23d7.png" /></figure><p>21. I have now entered my Database. Type the command “<strong>Show databases;</strong>” and you can see the database:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*_fEdMWMy1ioQo1V4.png" /></figure><p>22. Create a user and password for your MySQL database. WordPress installation uses these values to communicate with the MySQL database. Enter the following command, substituting a unique user name and password:</p><pre>CREATE USER &#39;wordpress-user&#39;@&#39;%&#39; IDENTIFIED BY &#39;your_strong_password&#39;;In my case its: “CREATE USER ‘John’@’%’ IDENTIFIED BY ‘password’;”</pre><p>The “%” sign allows this user called john to access the database from any host not just localhost.</p><p>23. Now I will create my Database with the following command:</p><pre>CREATE DATABASE `wordpress-db`;</pre><p>24. Grant full privileges for the database to the WordPress user “john” that was created earlier:</p><pre>GRANT ALL PRIVILEGES ON `wordpress-db`.* TO “John”@&quot;%&quot;;</pre><p>25. Flush the database privileges to pick up all of your changes:</p><pre>FLUSH PRIVILEGES;</pre><p>26. View the wordpress-db database for the user John with the command:</p><pre>show databases;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*iA2sVn-_D3FGkc_i.png" /></figure><p>27. Exit the mysql client:</p><pre>exit</pre><p>Next, create and edit the wp-config.php file. The WordPress installation folder contains a sample configuration file called wp-config-sample.php.</p><p>28. Copy the wp-config-sample.php file to a file called wp-config.php. This creates a new configuration file and keeps the original sample file intact as a backup:</p><pre>cp wordpress/wp-config-sample.php wordpress/wp-config.php</pre><p>29. Edit the wp-config.php file with nano text editor and enter values for the installation.</p><pre>nano wordpress/wp-config.php</pre><p>30. Inside the text editor find the line that defines DB_NAME and change database_name_here to the database name that was created previously:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*kqowLO4ZcuQZqfYB.png" /></figure><p>Note when editing the wp-config.php file make sure to edit the Database hostname with the RDS DNS name, my one is as follows:</p><pre>define( &#39;DB_HOST&#39;, &#39;wordpress-rds.cdoycwk2maho.eu-west-1.rds.amazonaws.com&#39; );</pre><p>31. In the text editor keep scrolling down till find the section called Authentication Unique Keys and Salts. Use the website,<strong> </strong><a href="https://api.wordpress.org/secret-key/1.1/salt/"><strong>https://api.wordpress.org/secret-key/1.1/salt/</strong></a>, to generate random Key and SALT values and replace the ones in the text editor and save:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*57q59TsVR6NqJUR5.png" /></figure><p>At this stage I have unzipped the installation folder, created a MySQL (MariaDB) database and User, and customised the WordPress configuration file. I am now ready to copy the installation files to my web server document root so that I can run the installation script that completes the installation.</p><pre>cp -r wordpress/* /var/www/html/</pre><p>32. WordPress permalinks need to use Apache .htaccess files to work properly, but this is not enabled by default on Amazon Linux. Type the following command:</p><pre>sudo vim /etc/httpd/conf/httpd.conf</pre><p>This will now open in the text editor, find the section starting with <strong>&lt;Directory “var/www/html”&gt;</strong>. In this section change the line that says <strong>AllowOverride None</strong> to read <strong>AllowOverride All</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*LmwtnyG86YqMd7Nf.png" /></figure><p>33. Now install the PHP graphics drawing library on AL2023:</p><pre>sudo dnf install php-gd</pre><p>34. Some of the available features in WordPress require write access to the Apache document root (such as uploading media though the Administration screens). Fix file permissions for the Apache web server:</p><pre>sudo chown -R apache /var/www</pre><p>35. Grant group ownership of /var/www and its contents to the apache group:</p><pre>sudo chgrp -R apache /var/www</pre><p>36. Change the directory permissions of /var/www and its subdirectories to add group write permissions and to set the group ID on future subdirectories:</p><pre>sudo chmod 2775 /var/www<br>find /var/www -type d -exec sudo chmod 2775 {} \;</pre><p>37. Recursively change the file permissions of /var/www and its subdirectories:</p><pre>find /var/www -type f -exec sudo chmod 0644 {} \;</pre><p>38. Restart the Apache web server to pick up the new group and permissions:</p><pre>sudo systemctl restart httpd</pre><p>Now that everything is installed, create an ALB, on the console go to EC2 and on the left pane select load balancers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*bPL2t2hz3un3iUlq.png" /></figure><p>Make sure to map the ALB to all public subnets. Create a new SG for ALB and edit inbound rules to allow HTTP traffic from anywhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*9jCGD8HWmrQbZOI6.png" /></figure><p>Create a target group so when traffic comes on port 80 it gets directed to the Wordpress EC2. Make sure to edit security groups inbound rules for Wordpress-SG to allow HTTP traffic from Wordpress-ALB-SG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*3Tk7wPrFwxTU15cA.png" /></figure><p>Now edit Target Group Health Checks to allow success code 302 error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*1RekhL_mCg93XZk9.png" /></figure><p>After registering the Wordpress-EC2 as a TG you should get healthy status:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*YrBNOafKGPm4uSTR.png" /></figure><p>Now copy the ALB DNS name onto the browser and complete WordPress installation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/0*BH9SDwwfmr0txt-1.png" /></figure><h3>Complete WordPress setup from the browser and create a Blog</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*rnev2zC-BCHFsSz8.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/0*36yJL5oUdg_o8bjB.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*W_G2HPZ0VUzDt90i.png" /></figure><h3>Conclusion</h3><p>Congratulations, we have now installed WordPress and can write a blog!!! In this project I used EC2 and RDS for WordPress deployment, installed a LAMP stack, configured ALB and security groups, and used Bastion server to SSH to the WordPress server.</p><p>To improve on this project in terms of security next time I would use Route53 with my domain name to access the WordPress server instead of using the DNS name of ALB. At present I am using HTTP on port 80 to route the traffic, better would be to use HTTPS. For this I need to request a certificate from AWS certificate manger and apply it to the ALB. By doing this the ALB will convert any HTTP request into HTTPS. Another important thing to be aware of is using the pem key and storing it into the Bastion host creates a security risk. If an unauthorised person hacks into your webserver then they can access your private key, which may be used for other webservers. A better practice would be to use SSH agent forwarding to connect from the Bastion host to other instances in your private subnet. The SSH agent forwarding forwards the private key to the Bastion host so you can SSH to the instances in the private subnet. Once the connection is terminated then the private key is no longer with the Bastion host.</p><p>Hope you enjoyed this project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b1aee068665" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>