Amazon Auto Scaling: Getting Started with AWS
Amazon Auto Scaling: Getting Started with AWS
Auto Scaling makes sure that Amazon EC2 instances are enough to run your application. We can create an auto-scaling group which contains a collection of EC2 instances. We can specify a minimum number of EC2 instance in that group and auto-scaling will maintain and ensure the minimum number of EC2 instances. We can also specify a maximum number of EC2 instances in each auto scaling group so that auto-scaling will ensure instances never go beyond that maximum limit. We can also specify desired capacity and auto-scaling policies for the Amazon EC2 auto-scaling. By using the scaling policy, auto-scaling can launch or terminate the EC2 instances depending on the demand.
For example, the above Auto Scaling group has a minimum size of one instance, the desired capacity of two instances, and a maximum size of four instances. The scaling policies that you specify adjust the number of instances, within your minimum and the maximum number of instances, based on the criteria that you specify.
Auto Scaling Components
1. Groups
They are the logical groups which contain the collection of EC2 instances which are having similar characteristics for scaling and management purpose. When you create a group, we can specify its minimum, maximum, and, desired number of EC2 instances.
2. Launch Configuration
It is a template used by the auto scaling group to launch EC2 instances. We can specify information such as the AMI ID, instance type, key pair, and security groups for your instances while creating the launch configuration.
3. Scaling Plan
Scaling plan informs Auto Scaling how and when to scale. Amazon EC2 auto-scaling provides the following ways for you to scale the auto scaling group:
Maintaining Current instance level at all time: We can configure and maintain a specified number of running instances at all the time in the auto scaling group. For achieving this Amazon EC2 auto-scaling performs a periodic health check on running EC2 instances within an auto scaling group. If any unhealthy instance found, auto-scaling terminates that instance and launches new instances to replace it.
Manual Scaling: In Manual scaling, you have to specify the changes in maximum, minimum, or desired capacity of your auto scaling groups. It maintains the instances with updated capacity.
Scaling based on Schedule: Scaling by schedule means that scaling actions are performed at a specific time and date.
Scaling based on demand: It is the most advanced scaling model. In this model resources scale by using a scaling policy. Based on the parameters, we can scale in or scale out your resources. We can create parameters in the policy such as CPU utilization, Memory etc. For Example, we can scale your EC2 instances which exceeds the CPU utilization beyond 80%. If CPU utilization crosses this threshold value, new instances will be launched by auto scaling group using the launch configuration. We can specify two scaling policies, one for scaling in (for terminating instances) and one for scaling out (for launching instances).
Types of Scaling policies:
- Target tracking scaling: We can increase or decrease the current capacity of the auto scaling group, based on the target value of a specific metric.
- Step scaling: Here, based on a set of scaling adjustments, we can increase or decrease the current capacity of the group that vary based on the size of the alarm breach.
- Simple scaling: Here we can increase or decrease the current capacity of the group based on a single scaling adjustment.
Procedure to setup Auto scaling
As a prerequisite, we need to create an AMI of our application which is running on our EC2 instance.
Setup: Launch Configuration:
- Log in to the AWS console. Navigate to Services->EC2 and and click on Launch Configuration from Auto Scaling
- Select the Amazon Machine Image from My AMIs tab, which was used to create the image for your web application.
- Then, select the type of the instance which is suitable for the web application and click Next: Configure details.
- In the configure details, name the launch configuration, you can assign if any specific IAM role is assigned for your web application
- After that, we need to add the storage and Security Groups. Then go for review.
- Click on Create launch configuration and select the existing key pair or create new key pair
Setup: Launch Configuration:
- From the EC2 console click on Auto Scaling Group which is located below the launch configuration. Then click on create auto scaling group.
- On the Create Auto Scaling Group page, choose Launch Configuration, select an existing launch configuration, select the launch configuration created with the previous steps and then choose Next Step.
- On the Configure Auto Scaling group details page, do the following:
- In Group name section, type a name for your Auto Scaling group.
- In Group size section, type the initial number of instances for your Auto Scaling group.
- In Network section, select a VPC for your Auto Scaling group.
- In Subnet section, select one or more subnets in your VPC. It is recommended to use subnets in multiple availability zones for high availability.
- (Optional) To integrate our Amazon EC2 instances with a load balancer, select Receive traffic from one or more load balancers and select one or more Classic Load Balancers or target groups (for application load balancer).
- Select Next: Configure scaling policies.
- On the scaling policy page, we need to specify the minimum and the maximum number of instances in this group using the row that begins with “Scale between”.Here we can use a target tracking policy to configure the scaling policies. We can specify CPU utilisation and Network In or Out and also we can give the target value as well. The scaling policy will work based on the target value. We can also disable scale-in from here. We can also use step and simple scaling policies instead of target tracking policy. Step and scale in policy is the most advanced method of Auto Scaling.
- It works based on alarm, we first need to create the alarm by clicking on ‘add new alarm’ in increase group size section. The alarm will get created for CPU utilization above 80%. If CPU Utilization crosses the threshold of 80% then the auto scaling group launches new instances based on step function.Also, we need to configure scale-in policies once the traffic becomes low, as it reduces the bill.
- We can also set alarm for scale-in policies by creating alarm in decrease group size section. Here it will remove 1 instance if average CPU utilization is less than 30%
- Next click on ‘Next: Configure Notification’ to get the notification based on launch or terminate to your mail ID, and then enter the tag and then click on ‘Create auto scaling group’
This was just a review on Amazon Autoscaling. For more on this stay tuned…