Home / How To / How to set EC2 Auto Scaling Group (ASG) to AWS

How to set EC2 Auto Scaling Group (ASG) to AWS

The ASG (Auto Scaling Group) feature comes bundled with EC2 (Elastic Compute Cloud) service from AWS (Amazon Web Services) Cloud. An ASG contains a collection of EC2 instances that are treated as a logical grouping for automatic scaling. An ASG makes it possible to use EC2 Auto Scaling features as a substitute for health checks and scaling principles. It helps maintain the number of instances in an ASG and automatically scales the EC2 Auto Scaling service. To create and ASG, we must first create a startup configuration.

A startup configuration is a configuration template that an ASG uses to start EC2 instances. When we create an initial configuration, we specify information for instances such as Amazon Machine Image (AMI), instance type, key pair, security groups, etc.

Auto Scaling monitors our applications and automatically adjusts the desired capacity if there is any difference in the bill.

There are no additional fees for automatic scaling. We only have to pay for the AWS resources needed to run the applications and Amazon CloudWatch monitoring fees.

To know more about billing related to ASG, click here.

In this article we will see how to create an ASG and see how the number of instances can be maintained if the number decreases or the load on the system increases.

  1. AWS Account (Create If You Don't Have One).
  1. Login to AWS.
  2. Creating an initial configuration
  3. Creating an automatic scaling group
  4. Exit the instance to allow ASG to handle the instance count.
  5. Increase the load on servers to allow ASG to increase the instance count.
  6. Delete the auto peeling group.

Log in to AWS

  1. Click here to go to AWS login page.

When we click on the link above, we see a web page as follows where we are required to log in with our login credentials.

 AWS logon

Once we have logged in to AWS we will see the main console with all services listed as follows.

 AWS Management Console

Create a Launch Configuration

To create a startup configuration, click "Services" in the navigation bar at the top of the screen and click "EC2" to go to the EC2 console.

 Services> Resource groups "width =" 750 "height =" 413 "style =" display: block; margin-left: auto; margin-right: auto; "ezimgfmt =" rs rscb1 src ng ngcb1 "class =" ezlazyload "data-ezsrc =" https://www.howtoforge.com/images/how_to_setup_ec2_auto_scaling_group_asg_on_aws/Sc-123_7 png "/> [194559004] On the left of the screen, under "Auto Scaling", select "Launch Configurations". </strong> </p>
<p>  <img src=

On Select next page "Create boot configuration".

 Create boot configuration

Select an AMI page on Select AMI You can even select AMI from My AMIs if you have your own AMI, here I choose an Ubuntu Server 18.04 LTS AMI Applicable to Free Tier.

 Chosed AMI image

On the Select Setting Type, select a hardware configuration for your instance Click "Next: Configure" Details.

Here I choose an instance type that is the applicable cable for Free Tier, you can choose any one instance type.

 Select instance type

On this page, name the startup configuration that should is created and retains the rest as it is. Click "Next: Add Storage".

 Add Storage

Enter the desired disk space and click "Next: Configure Security Group".

 Configure Security Group Ads

On the Review page, select "Create a new security group" and then click View. This will help to take ssh access to the server anywhere as the source is] Create a new security group "width =" 750 "height =" 413 "style = "display: block; margin-left: auto; margin-right: auto; "ezimgfmt =" rs rscb1 src ng ngcb1 "class =" ezlazyload "data-ezsrc =" https://www.howtoforge.com/images/how_to_setup_ec2_auto_scaling_group_asg_on_aws/Screenshot_2019-12___Screenshot_2019-12__ png "/>

On the Review page, select" Create Boot Configuration ".

 Create Boot Configuration

To select an existing key pair or create a new key pair, select one of the listed options that you select, then select the Receipt check box and then select Create boot configuration.

 Select key pair

Create an automatic scaling group

When you are done creating a startup configuration, you will see the following screen. To create an ASG, click on "Create an automatic scaling group with this boot configuration."

 Create an automatic scaling group

Enter an ASG name to be created and select existing subnets from your VPC for high availability and click "Next: configure scaling principles."

 configure scaling policy Ads

On this page, select "use scaling principles to adjust the capacity of this group" and specify the number of instances to be scaled between the desired and maximum number of instances in ASG. Keep "Average CPU Usage" in the metric type and enter the "Goal Value" you choose. This will increase the number of instances in the group if the CPU load exceeds the specified target value in% for the specified period. Click "Next: Configure Message".

 use scaling policies to adjust the capacity of this group

This is an optional step that helps get the messages. I do not configure this because it is optional. Click "Next: Configure Tags".

 Add message

This is also an optional step. To add tags, select Edit Tags, enter a tag key and value for each tag, and then select View.

 Add Tags

On the Review page, click the "Create Auto Scaling Group" button.

 Create Auto Scaling Group

If you get "Could not create Auto Scaling Group", don't panic and just click Retry.

 Retry to create group

Now go to Auto Scaling Page and you can see the status of the Auto Scaling group, click on Activity History to see the status.

 Activity History

You can also see the instance state and the number of instances from the instance page.

 Instance state and number of instances

End the instance to let ASG handle the instance count.

To see if ASG works as expected, exit one of the instance es. Select the instance and click Actions -> Instance State -> Exit and click "Yes, Exit" when prompted.

We had specified 2 as our desired / minimum number in scaling policy, which means that our ASG must always have two cases in healthy condition. When the termination goes down, ASG will wait for 300 seconds as we had specified in the scaling policy before any scaling activity is performed.

 Exit instance

After waiting for 300 seconds, ASG is activated and tries to launch a new instance to maintain the desired number. You can check the status in ASG Activity History.

 Launch of new instance

Increase the load on instances to allow ASG to increase the number of instances.

Now we see how the ASG instance reckons if the load on the servers crosses the target value that we set in the scaling policy we created.

To increase the load on the server login in both EC2 instances.

To learn how to create an EC2 instance and know the steps to connect to it, click here. Advertising Services


When you log in, you install the package required to increase the load using following commands.

  sudo apt-get update 
  sudo apt-get install stress 

Increase CPU load with the following command.

  stress - cpu 50 - timeout 400 

This command will increase the CPU load to 50% for 400 seconds.

We had s specified target value as 40% in ASG. Once the CPU load has crossed the target value, ASG will wait for 300 seconds as we had specified in the scaling policies before performing any scaling activity.

After waiting for 300 seconds, ASG will be invoked and try to start a new instance to meet requirements.

You can check the status in ASG Activity History.

 Load Testing

You can also see the instance count on the instance page.

 Number of instances has increased

Delete Auto Scaling Group

Removing just all instances is not enough to clean up the resources. ASG will recreate the occurrence to match the desired condition. To clean up the resource, we must remove ASG.

To remove ASG, go to ASG we created and click Actions -> Delete and when prompted to click "Yes, delete".

 Delete Autoscaling Group


In this article we have created a startup configuration and created an ASG that uses it. We saw how ASG updates the desired state and increases the number of instances to comply with the scaling policy. We also saw how an ASG can be removed.

Source link