Auto Scaling helps to automatically scale your Amazon EC2 capacity by scaling out or scaling in according to condition defined. When traffic volume is high the Auto scaling features increases the EC2 instance for that period to maintain application performance and decreases the EC2 instance when demands null.
Auto Scaling plans:
There are several plan which defines how auto scaling is done, some of them are described below.
Maintain Current Instance Levels
Auto Scaling group is configured in such a way that it can maintain a minimum or specified number of running instances at all times. To achieve this Auto Scaling performs a periodic health check on running instances within an Auto Scaling group. When Auto Scaling finds an unhealthy instance, it terminates that instance and launches a new one.
In this we specify the change in the maximum, minimum, or desired capacity of your Auto Scaling group. Auto Scaling manages the process of creating or terminating instances to maintain the updated capacity.
When it is desired to Scale out the EC2 instance or Scale in Amazon EC2 instance on some specific period of time, we can do that. Examples include periodic events such as end-of-month, end-of-quarter, or end-of-year processing, and also other predictable, recurring events.
Dynamic scaling lets you define parameters that control the Auto Scaling process in a scaling policy. For example, you might create a policy that adds more Amazon EC2 instances to the web tier when the network bandwidth, measured by Amazon Cloud Watch, reaches a certain threshold.
Auto Scaling Components
Followings are the components of auto scaling that need to be configured to work properly:
It is the template that Auto Scaling uses to create new instances, which is is composed of the configuration name, Amazon Machine Image (AMI), Amazon EC2 instance type, security group, and instance key pair. Each Auto Scaling group can have only one launch configuration at a time.
The CLI command that follows will create a launch configuration with the following attributes:
- Name: dclessons_LC
- AMI: ami-0535d66c
- Instance type: m3.medium
- Security groups: sg-f57cde9d
- Instance key pair: dclessons_key
Auto Scaling Group
An Auto Scaling group contains configuration options that control when Auto Scaling should launch new instances and terminate existing instances. An Auto Scaling group contain a name and a minimum and maximum number of instances that can be in the group. Optionally it can be specified the desired number of instances that the group must have at all times. If you don’t specify a desired capacity, the default desired capacity is the minimum number of instances that you specify.
The CLI command that follows will create an Auto Scaling group that references the previous launch configuration and includes the following specifications:
- Name: dclessons_ASG
- Launch configuration: dclessons_LC
- Availability Zones: us-east-1a and us-east-1c
- Minimum size: 2
- Desired capacity: 4
- Maximum capacity: 10
- Load balancers: dclessons_ELB
Amazon cloud watch and scaling policies can be associated to Auto Scaling group to adjust Auto Scaling dynamically. As soon as threshold is crossed, Amazon Cloud Watch sends alarms message which trigger changes (scaling in or out) to the number of Amazon EC2 instances currently receiving traffic behind a load balancer and this action happens because of policy with instruction is set that tells what to do .
There are several ways to configure a scaling policy: You can increase or decrease by a specific number of instances, or you can adjust based on a percentage.
More than one Scaling policies can be associated with an Auto Scaling group. For example, you can create a policy using the trigger for CPU utilization, called CPULoad if CPU utilization crosses more than 75 percentage for 5 minutes and you can also attach another policy to the same Auto Scaling group to scale in if CPU utilization is less than 40 percent for 30 minutes.