Auto scaling group is a feature of EC2 instances on AWS. An auto-scaling group consists of several EC2 instances, which can increase or decrease in numbers depending upon the scaling policy attached to the group. Auto scaling group monitors the health and load on the instances in the group, and depending upon the policy, it launches or terminates the instances to maintain a specific number of instances in the group. Auto-scaling groups are used to deploy a highly available and scalable infrastructure on AWS. In this guide, we will discuss the following steps to configure auto-scaling groups.

  • Create a launch template
  • Create an auto-scaling group from the launch template
  • Test auto-scaling group
  • Delete auto-scaling group

Create a launch template

Launch template is a kind of structure of the EC2 instances that includes all the instances’ details and parameters. All the instances in the auto-scaling group are launched using either the launch template or the launch configuration. Launch templates are newer to AWS than launch configuration and have more options to customize the EC2 instance configuration. That is why, in this blog, the launch template will be used to create an auto-scaling group.

In order to create a launch template, first, log into the management console and select the region where all the infrastructure will be deployed. From the top right corner of the management console, click on the region button and select the appropriate region. For this blog, we will deploy our infrastructure in the us-east-1 (N. Virginia) region.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-1.png" data-lazy- height="245" src="data:image/svg xml,” width=”390″>

Now search for the EC2 service from the management console.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-2.png" data-lazy- height="234" src="data:image/svg xml,” width=”331″>

From the left side panel, go to the Launch Templates under the Instances section.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-3.png" data-lazy- height="330" src="data:image/svg xml,” width=”219″>

Click on the Create launch template button to create a new launch template, and it will open a form asking for different parameters for the launch template.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-4.png" data-lazy- height="201" src="data:image/svg xml,” width=”628″>

Enter the Launch template name under the Launch template name and description section.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-5.png" data-lazy- height="340" src="data:image/svg xml,” width=”628″>

Select the AMI under the Amazon machine image and the Instance type under the Instance type section.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-6.png" data-lazy- height="324" src="data:image/svg xml,” width=”628″>

Select the specific Key pair you want to use while logging into your server over SSH. If you do not have any key, create one by clicking on the Create new key pair.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-7.png" data-lazy- height="152" src="data:image/svg xml,” width=”628″>

Under the Network settings, select the Networking platform and security groups.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-8.png" data-lazy- height="280" src="data:image/svg xml,” width=”628″>

Leave the rest of the parameters default and click on the create launch template button to create the launch template.

Create an auto-scaling group from the launch template

After creating the launch template, now create the auto-scaling group from the launch template. From the left side panel, click on the Auto Scaling Groups under the Auto Scaling section.

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-9.png" height="125" src="data:image/svg xml,” width=”227″>

Click on the Create Auto Scaling group to create a new auto-scaling group.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-10.png" data-lazy- height="159" src="data:image/svg xml,” width=”628″>

Enter the name of the auto-scaling group and select the launch template created in the previous step. You can also switch to launch configuration instead of launch template by clicking on the Switch to launch configuration, but we will stick to the launch template for this blog.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-11.png" data-lazy- height="308" src="data:image/svg xml,” width=”628″>

Click on the Next button after entering the above details, and it will ask for the instant purchase option and network details. Select the Adhere to launch template as an instant purchase option.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-12.png" data-lazy- height="207" src="data:image/svg xml,” width=”628″>

For the network, select the VPC and subnets you want to deploy instances in. For this blog, we will use default VPC and two subnets. You can select as many subnets as you want.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-13.png" data-lazy- height="364" src="data:image/svg xml,” width=”628″>

After entering the network details, click on the Next button, and it will ask for the advanced options. Click on the Next button without entering or selecting any parameter, and it will ask for group size and scaling policy. Auto scaling group size defines the maximum and the minimum number of instances to be launched in an auto-scaling group and can also be used to maintain a constant number of instances on AWS. Enter the same number for Desired capacity, Minimum capacity, and Maximum capacity to maintain a constant number of instances in the auto-scaling group.

For this demo, enter the 1 instance as Desired capacity and Minimum capacity and 3 instances as Maximum capacity.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-14.png" data-lazy- height="283" src="data:image/svg xml,” width=”628″>

A scaling policy is a set of configurations that decides when to launch or terminate the instances in the auto-scaling group. Scaling policy tracks a target defined using the Metric type and Target value while configuring the scaling policy. Following are the metric types provided by AWS.

  • Average CPU utilization
  • Average network in (bytes)
  • Average network out (bytes)
  • Application load balancer request count per target

Auto scaling group monitors the selected metric type of all the instances, and whenever the average target value of the selected metric type goes above the threshold, the auto-scaling group launches more instances to handle the load.

For this demo, select Target tracking scaling policy, enter the Scaling policy name, select Average CPU utilization as Metric type, and 10 as Target value.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-15.png" data-lazy- height="269" src="data:image/svg xml,” width=”628″>

The above configuration will maintain a minimum of 1 instance running. Whenever the instance dies, the auto-scaling group will automatically launch a new instance. Also, when the load on the instance reaches more than 10%, the auto-scaling group will automatically launch a new instance. The auto-scaling group will not launch more than 3 instances at a time even if the load is more than 10% on all the instances as we have specified a maximum number of 3 instances.

Now click on the Skip to review button to skip the remaining steps and click on the Create auto scaling group button at the end of the page after reviewing the configuration to create the auto scaling group.

Test auto scaling group

After creating the auto scaling group, it will launch one EC2 instance as we have specified the desired capacity to be one EC2 instance. The auto scaling group can be tested by either terminating the instance or increasing the CPU utilization of the instance.

First, we will test the auto scaling group by terminating the EC2 instance. From the left side, the panel selects the Instances under the INSTANCES section.

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-16.png" height="298" src="data:image/svg xml,” width=”231″>

Select the instance launched by the auto scaling group and click on the Instance state button on the top right corner. It will open a list, click on the Terminate instance to terminate the instance manually.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-17.png" data-lazy- height="208" src="data:image/svg xml,” width=”506″>

After 3 minutes of terminating the instance, the auto-scaling group will launch a new instance.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-18.png" data-lazy- height="104" src="data:image/svg xml,” width=”551″>

Another way to test the auto scaling group is to increase the load on the EC2 instance, as we have configured the CPU utilization as a metric of the scaling policy. Whenever the load on the CPU goes above 10%, the auto-scaling group will launch another EC2 instance. For this purpose, SSH into the EC2 instance and run an infinite loop.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-19.png" data-lazy- height="163" src="data:image/svg xml,” width=”628″>

On the terminal, run the following command.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-20.png" data-lazy- height="129" src="data:image/svg xml,” width=”628″>

It will run an infinite loop, and the CPU utilization will reach a maximum that will trigger the auto-scaling group to launch another instance. Go to the instances section to see the instances.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-21.png" data-lazy- height="143" src="data:image/svg xml,” width=”557″>

Delete auto scaling group

This section will discuss how we can delete the auto scaling group on AWS, as whenever an instance is deleted, the auto scaling group will create another instance to maintain a specific number of instances. In order to delete the auto-scaling group, first edit the desired capacity and a minimum number of instances to 0. Select the Auto Scaling Groups from the EC2 console.

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-22.png" height="181" src="data:image/svg xml,” width=”231″>

Select the auto scaling group and click on the Edit button.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-23.png" data-lazy- height="207" src="data:image/svg xml,” width=”628″>

Set the desired capacity and the minimum capacity to 0 and click on the Update button at the end of the page.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-24.png" data-lazy- height="305" src="data:image/svg xml,” width=”628″>

It will automatically terminate all the instances launched by the auto scaling group to maintain the size of the group. Go to the instances section to see all the instances available.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-25.png" data-lazy- height="144" src="data:image/svg xml,” width=”564″>

Both the instances are terminated, and now the auto-scaling group can be deleted. From the auto scaling group section, select the auto scaling group and click on the Delete button.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-26.png" data-lazy- height="180" src="data:image/svg xml,” width=”628″>

Now it will ask for your confirmation to delete the auto scaling group. Enter delete in the input bar and click on the Delete button to delete the auto scaling group.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-27.png" data-lazy- height="307" src="data:image/svg xml,” width=”606″>

After deleting the auto scaling group, go to the launch template section to delete the launch template.

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-28.png" height="258" src="data:image/svg xml,” width=”229″>

Select the launch template and click on the Actions button. It will display a list of different options. Select the Delete template option from the list.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-29.png" data-lazy- height="123" src="data:image/svg xml,” width=”628″>

Now it will ask for confirmation before deleting the launch template. Enter delete in the input bar and click on the Delete button to delete the launch template.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-configure-auto-scaling-group-in-AWS-step-by-step-30.png" data-lazy- height="371" src="data:image/svg xml,” width=”605″>

Conclusion

Auto scaling group is the feature provided by AWS to create a highly available and scalable infrastructure on AWS cloud. Auto scaling group uses launch template or launch configuration to launch instances to scale the infrastructure on AWS. Launch template includes all the configurations required to launch new instances in the group. Auto scaling group provides different types of target tracking policies used to launch and terminate instances in the group. This guide provides a step-by-step procedure to create, manage and delete an auto-scaling group on AWS.

About the author

<img data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/Zain-150×150.jpg615bbdbf8b1ea.jpg" height="112" src="data:image/svg xml,” width=”112″>

Zain Abideen

A DevOps Engineer with expertise in provisioning and managing servers on AWS and Software delivery lifecycle (SDLC) automation. I’m from Gujranwala, Pakistan and currently working as a DevOps engineer.