Launching an AWS EC2 Auto Scaling Group for High Availability.

Abidoye Joshua mayowa
9 min readFeb 25, 2023

Thanks for Visiting my page today. This is my 5th project in the Level Up In Tech Program. This is week 7 at LUIT; in this week’s project, we will build a web server by creating an Auto-scaling Group of EC2 Instances for high availability.

Prerequisites

  • AWS account with admin permissions, NOT a root account
  • Basic understanding of computer networking
  • Basic understanding of AWS EC2, VPC, Security Group, Auto Scaling and Load Balancing.

FOUNDATIONAL

  1. Create a VPC with CIDR 10.10.0.0/16
  2. Create three public subnets with 10.10.1.0/24 & 10.10.2.0/24 & 10.10.3.0/24
  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 from #2.
  4. The autoscaling min and max should be 2 and 5.
  5. Create an Application Load Balancer to distribute traffic to the autoscaling group.
  6. Create a web server security group allowing inbound HTTP traffic from your Application Load Balancer.
  7. Create a load balancer security group allowing inbound HTTP traffic from 0.0.0.0/0.

AWS Auto Scaling group: contains a collection of EC2 instances treated as a logical grouping for automatic scaling and management. An Auto Scaling group also lets you use Amazon EC2 Auto Scaling features such as health check replacements and scaling policies. The size of an Auto Scaling group depends on the number of instances you set as the desired capacity. You can adjust its size to meet demand, either manually or by using automatic scaling.

The three aspects of EC2 Auto Scaling.

  1. Launches template or launch configuration as a configuration template for the EC2 instances.
  2. EC2 Auto Scaling group allows you to specify your instance's minimum, maximum and desired capacity.
  3. Scaling policies that allow you to configure a group to scale based on the occurrence of specified conditions or a schedule.

AWS EC2: Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers.

AWS VPC: Amazon Virtual Private Cloud enables you to launch AWS resources into a virtual network that you’ve defined. This virtual network resembles a traditional network that you’d operate in your own data center, with the benefits of using the scalable infrastructure of AWS.

AWS Load Balancing: Load balancing distributes network traffic equally across a pool of resources supporting an application. Elastic Load Balancing supports the following types of load balancers: Application Load Balancers and Network Load Balancers. Application Load Balancers route HTTP/HTTPS (or Layer 7) traffic. Network and Classic Load Balancers route TCP (or Layer 4) traffic.

Okay, we got the fundamentals covered — let’s get started!

Step 1: Create a VPC, Availability Zones, and public Subnets.

First, we will navigate to VPC>Create VPC> VPC and more, name the VPC
IPv4 CIDR block 10.10.0.0/16

Launching a Vpc from the AWS console

We are required to customize the public subnet.

Public subnet CIDR block in us-east-1a 10.10.1.0/24
Public subnet CIDR block in us-east-1b 10.10.2.0/24
Public subnet CIDR block in us-east-1c 10.10.3.0/24

Follow the details in the image above and below to follow through the hands-on lab.

Follow the instructions in the image above, then click on create VPC.

VPC was Successfully Created

Attached below is the flow chart of the VPC resource map.

For each of the 3 public subnets created, we must select “enable auto-assign public IPv4 address” by selecting the subnet, then under “Actions”, select “edit subnet settings” and click on enable.

Following the instructions, you should get something similar to the image below.

You need to repeat the same steps for VPC Project-subnet-public-us-east-1b and 1c. After completing the task above, we can move to the next step.

Step 2: We need to Create a Launch Template

Go to the AWS search bar and type in the EC2 launch template.

Click on create Launch Template.

Create a template name, an optional name for the template version description; remember to check the “provided guidance” box to help set up a template that we can use with EC2 Auto Scaling.

Under the Amazon machine image, select “Quick Start” and select Amazon Linux 2, which is Free tier eligible. Instance type is similar to a hardware profile. remember to select the “free tier eligible.” select t2.micro Family:t2 1vCPU 1GIB memory.

Amazon machine image
Instance Type t2.micro

Select available or create a new key pair. I already have Project-3-Key created. — A key pair will allow us to securely connect to our EC2 instances through an SSH terminal.

Key Pair

Next, Under Network settings: Select “Create security group.”

Follow the steps in the image below for the proper configuration of the security group.

We need to Add inbound security rules, follow the image below to configure inbound security rules.

Inbound Security group rules

We see a warning about our rule choices, and these rules are for this project's instruction purposes. Yes, I recommend setting security group rules to allow access from known IP addresses only for best practices in the industry.

Under Advanced network configuration: it’s important to remember to ENABLE Auto-assign public IP.

In the Advanced details, scroll down to the User data info, and input your bash script to update all packages and install the Apache web server.

User Data Script

Finally, click “Create Launch Template” at the bottom right-hand corner.

Looks good! We have successfully launched our template.

Step 3: Create an Application Load Balancer

Go back to the EC2 page, and on the left side, click on Load Balancer and click the orange button “Create Load Balancer”.

Under the Load Balancer Types: Select “Application Load Balancer” It provides advanced routing and visibility features targeted at application architectures.

Click the Create button below Application Load Balancer to launch the Load balancer.

Under Basic Configuration: In Load Balancer name: Give it a name, select internet-facing and IPv4.

Under Network Mapping, select the VPC we created above, and then select each subnet in our VPC; it should be 3 subnets in total.

For the Security group, select Webservernew.

For Listeners and routing, click “create target group.”

Next, Select “Instance”

We need to name the “ApplicationLoadBalancer” in the Target group name. Select our VPC VPCProject and select HTTP1 as our Protocol version.

Click “create target group”.

Next, go back to our Load balancer configuration page and select the target group we just created named: “ApplicatonLoadBalancer” I click on the refresh icon first to generate.

Finally, on the Create Application Load Balancer page, scroll down to the bottom and click on the orange button “Create Load Balancer” Following is a summary of our Application Load Balancer Settings.

You should see the image below after clicking on create load balancer.

Step 4: Auto Scaling Group

To create the Auto scaling groups, in the bottom left side, click on Autos-caling group and click on the orange button “Create Auto Scaling group.”

First, name AutoScaling Group: Project5AutoScalingGroup, and select the Launch template “Project-ASG” created earlier. Then click next.

Under Network, select “VPC Project”, The Vpc we created earlier, and under availability Zone and subnets, select the AZs and subnets we created earlier, and then click “next.”

Under Load balancing, select “attach to an existing load balancer” and click “choose from your load balancer target group” Finally, select the “AppLoadBalancer” we created earlier and scroll down and click “next”.

Configure the group size as seen in the image attached below.

Add a notification for this project, leave it blank and click “next”.

Add tag is optional skip and click “next.”

Now scroll to the review summary page and click “create Auto scaling group.”

Great! looks like we got our Auto Scaling Group successfully created.

Finally, Let’s double-check to see if everything is working correctly.

Go back to the EC2 page to see if our EC2 is running. Looks Good!

Locate the Public IPv4 address and type it in a web browser. It could load the Apache web server, Which means the Project was successful.

Attached below is the apache webserver up and running.

We have successfully created a highly available EC2 instance with auto Scaling by creating an auto scaling group, scaling policy, load balancer, target group, listener, and two EC2 instances. Mission Accomplished!!

Now that we’ve completed all the tasks, we must clean up the files we used for the hands-on project, so we won’t get billed!

Steps 1. Type in EC2

Step 2. Delete Load Balancer

Step 3. Delete Auto Scaling Group

Step 4. Delete Launch Template

Step 5. Terminate Instances

Step 6. Type in VPC and Delete VPC.

Thats the end of the project, Thanks for reading along, Don't forget to follow me for more hands-on projects like this. You can also follow me on LinkedIn for more projects.
linkedin.com/in/joshua-abidoye-0ab796195.

--

--

Abidoye Joshua mayowa

DevOps Engineer. I'm interested in collaborating with anyone interested in cloud engineer or cloud DevOPs.