Auto Scaling Group
According to what is mentioned on the official website of AWS.An Auto Scaling group contains a collection of Amazon EC2 instances that are treated as a logical grouping for the purposes of automatic scaling and management.
- An Auto Scaling group is the place where you define the logic for scaling up and scaling down.
- It has all the rules and policies that govern how the EC2 instances will be terminated or started.
- Auto Scaling groups are the collection of all the EC2 servers running together as a group and dynamically going up or down as per your definitions.
- When you create an Auto Scaling group, first you need to provide the launch configuration that has the details of the instance type, and then you need to choose the scaling plan or scaling policy.
Different AWS AutoScaling Policy
First, let's look at the different scaling policies that can be applied to the autoscaling groups.Dynamic Scaling
- The biggest advantage of AutoScaling is the dynamic scaling of resources based on the demand.
- There is no limit to the number of servers you can scale up to.
- You can scale up from two servers to hundreds or thousands or tens of thousands of servers almost instantly.
- Using AWS Auto Scaling policy you can make sure that your application always performs optimally and gets additional horsepower in terms of CPU and other resources whenever needed. You are able to provision them in real time.
Predictive scaling
- AWS Auto Scaling is now integrated with machine learning (ML), and by using ML Auto Scaling, you can automatically scale your compute capacity in advance based on predicted increase in demand.
- The way it works is AWS AutoScaling Policy collects the data from your actual usage of EC2 and then uses the machine learning models to predict your daily and weekly expected traffic.
- The data is evaluated every 24 hours to create a forecast for the next 48 hours.
Scheduled scaling
- If your traffic is predictable and you know that you are going to have an increase in traffic during certain hours, you can have a scaling policy as per the schedule.
- For example, your application may have heaviest usage during the day and hardly any activity at night.
- You can scale the application to have more web servers during the day and scale down during the night.
- To create an AWS AutoScaling policy for scheduled scaling, you need to create a scheduled action that tells the Auto Scaling group to perform the scaling action at the specified time.
Configuration of an AutoScaling Group
Log in to your AWS account and click on EC2 under Services tab. Now, from the left pane, click on Auto Scaling Groups and you will see the following screen.Step-1: Choose launch template or configuration
Here, first, we will provide the name of our AutoScaling Group. For now, we have set it to My-Test-ASG. Now we will select a launch template that contains the instance-level settings such as the Amazon Machine Image, instance type, key pair, and security groups. Since we don't have any launch template preconfigured, we will create one.#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1> Hello World from $(hostname -f)<a/h1>" > /var/www/html/index.html
Now click on Create Launch Template.
Step-2: Choose instance launch options
In the Network, we will select the default VPC in which our Auto Scaling Group will reside. Then we will define which Availability zones and subnets your Auto Scaling Group can use in the chosen VPC.Step-3: Configure advanced options (optional)
Here, we will specify that whether we want to use a load balancer or not, and if yes then whether we want to create a new load balancer or choose from an existing load balancer. Since we have a preconfigured Application Load Balancer available, for now, we will use that. In the upcoming blog, we will see that how we can create an Application Load Balancer from scratch. Now we will select a Target Group from our existing load balancer Target Groups.Step-4: Configure group size and scaling policies
Here we will set our Group size. For now, we have set the values of Desired Capacity and Minimum Capacity to 1 and Maximum Capacity to 3. Our group size will change according to the traffic received later on. This is the power of Auto Scaling Groups.Step-5: Add notifications (optional)
Here we can add notifications so that they can be sent to SNS topics whenever an Auto Scaling Group launches or terminates an EC2 instance. For now, we are leaving this step since it's optional.Step-6: Add tags (optional)
Here we can add tags so that they can be used to search, filter, and track our Auto Scaling group. For now, we are not adding any tag.Step-7: Review the AWS AutoScaling Policy configuration
Now the final step is to review all the details configured. With this, we have come to the end of the creation of our Auto Scaling Group.Verify and Monitor AWS AutoScaling Policy Behaviour
As soon as we create our AutoScaling group, in the Activity history, we will find some action happening. Here we can see that a new instance has been launched. The newly created EC2 instance can also be viewed after clicking on instances from the left pane. The capacity of Auto Scaling Group has increased from 0 to 1.Conclusion
In this tutorial, we learned about- AutoScaling Groups.
- AWS AutoScaling Policy.
- Configuration of an AutoScaling Group with Dynamic Scaling Policy from scratch.
- Changes in the size of our AutoScaling Groups according to CPU utilization.