Create an Auto Scaling Group

How To Set Up AWS Auto Scaling Group With Elastic Load Balancer for AWS EC2 Instance

Introduction

We will learn to deploy an AWS Auto Scaling Group for a deployed EC2 instance. In this walk through, you will learn how to connect the Auto Scaling Group to an Application Load Balancer, and then use the AWS Launch Template to deploy our Auto Scaling Group. To have a better under standing of what the Auto Scaling does, I recommend you read the previous post about some core components and features of AWS Auto Scaling.

CREATE EC2 AMAZON MACHINE IMAGE

We will start with creating an EC2 AMI. I already deployed an EC2 instance from this post here. Once you deploy your instance, select the instance, under Actions button, select Images and Templates. Then Create Image.

AMI image for EC2 instance

In the next window, input the name for your image. Also include the description. Choose a suitable size for the EBS that the AMI instance will use when deployed.
Then click the create Image.

Name of the ami image. Create Image

You can check that the image is create. Click the AMI on the left, and you should see the AMI in the list.

See the created image
create target group for load balancer

Now that we have created the image for our EC2 instance, we can now create the Load balancer. The load balancer will route traffic equally among the EC2 instance fleet when the AWS Auto Scaling Group scales in or scales out. This will ensure no server is overworked.

We will create an Application Load Balancer, however, we first need to create the Target Group for Load Balancer. A target group is a collection of EC2 instance that the Application Load Balancer will route the traffic to. And since we will be using the servers deployed by our Auto Scaling Group, we will not need to specify a target here.

Select Instances target type. Enter the name and the protocol. Port 80 is default port for the server web browser.

Create target group for aws load balancer

In the Networking, select the VPC to deploy your Application Load Balancer. Make sure it is the same as where the AWS Auto Scaling Group will be deployed.
Use the HTTP1 or HTTP2 protocol version. And for the Health Check path, we specify the root path of our application.

Select the https protocol for ELB target group

Leave the other settings as default and click Next.

Click Next

The next window is where you Register Target instance. Do not select any instance here. Then click the create Target Group.

CREATE LOAD BALANCER

Once we create the Target Group without registering any target, we will go ahead an configure our AWS Application Load Balancer.

Scroll down the left menu in you AWS EC2 console. Select Load Balancer. Then select Application Load Balancer.

Application Load balancer configuration.

In the next window, enter the Load Balancer name, then select the Internet-Facing for the scheme. We use internet facing because our Load Balancer will be accepting traffic from the public IP address.

Select the IPv4 IP address type.

Name the AWS ELB

Select the VPC and Subnet for the Load Balancer.

Select the vpc and subnet for the load balancer

Then, select the Target Group you created earlier from the dropdown list. Also include the Protocol and Port number.

Security Tip: It is important to note that the Security Group should be refactored to allow only traffic from the Load Balancer security group only, while the Load Balancer security group would allow other public traffic.

Add listener and routing for your application load balancer

Then click the Create Load Balancer.

create aws load balancer
CREATE LAUCH TEMPLATE

Now we have the Application Load Balancer ready, we will create a Launch Template for our AWS Auto Scaling Group. The Launch Template will carry the definition of instance that ASG will spin up.

Click the Launch Template at the site bar of the EC2 dashboard. Select the Create Launch Template.

Create EC2 launch template for AWS auto scaling group

Enter a name to identify your launch template. Also add the description.

name the launch template

Next, under the Application and OS Images, select the My AMIs, then select Owned by me. In the dropdown, select the AMI you created from the EC2 instance earlier.

select the free tier instance type for aws auto scaling group

Check the summary and then Create Launch Template.

Check the summary for launch template and create

Once it is created, check that it is created, and take note of the version number.

confirm launch template
CREATE EC2 AUTOSCALING GROUP

And once again, scroll to the bottom of the menu in the AWS EC2 dashboard and select Auto Scaling Group. Then click Create Auto Scaling Group.

Create ASG

Give the Auto Scaling Group a name. Then select the Launch template you created earlier from the dropdown list. Take note of the version too.

Add name for aws auto scaling group and select the launch template

Select the same VPC where you deployed the Load Balancer and the EC2 instance. Also select the Availability Zone.

Select the vpc and subnet for aws auto scaling group

Leave the other settings at the default. Then click Next.

click next

In the next window, you will select the Load Balancer that ASG will work with. Select Attach to an Existing Load Balancer. Then select the Choose from Load Balancer Target Groups. Select the Target Group from the dropdown list.

select the application load balancer to attach to aws auto scaling group

In the Health Checks, select the check box for Turn On Elastic Load Balancing Health Checks. Make the grace period 300 seconds.

Select the Health check for Load Balancer

Select the check box to enable the group metric collection within cloudwatch. Then click Next.

Enable cloudwatch monitoring for aws auto scaling group

In the next window, select the Desired, Minimum, and Maximum capacity for the size of instance that ASG will work with.

create the size of your auto scaling group

Then use the Target Tracking Policy to tell Auto Scaling Group the condition to scale the instance. Here is used the CPU Utilization at 80%. I also specify a 300 seconds warm up period. Your could be lower.

Configure target tracking for your aws auto scaling group

Click Next.

click next

Review all the settings and the click the Create Auto Scaling Group once you are satisfied.

Skip sns and create auto scaling group
check the instances deployed for confirmation

You can confirm the Auto Scaling Group is created by checking the list of the AWS creaated.

confirm auto scaling group is created

Also when you check the list of deployed EC2 instance, you should also see that AWS has deployed more servers for use based on our configuration.

confirm aws auto scaling group creates the instance

…and our server is working.

Instance check passed.
CONclusion

In this post, we have been able to configure AWS AutoScaling Group and Elastic Load Balancer to make our EC2 instance server more resilient, reliable, fault tolerant, and secure.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *