Overview
- When you use Amazon EC2 Auto Scaling, your applications gain the following benefits:
- Better fault tolerance. Amazon EC2 Auto Scaling can detect when an instance is unhealthy, terminate it, and launch an instance to replace it. You can also configure Amazon EC2 Auto Scaling to use multiple Availability Zones.
- Better availability. Amazon EC2 Auto Scaling helps ensure that your application always has the right amount of capacity to handle the current traffic demand.
- Better cost management. Amazon EC2 Auto Scaling can dynamically increase and decrease capacity as needed.
- There are no additional fees with Amazon EC2 Auto Scaling
- Amazon EC2 Auto Scaling attempts to distribute instances evenly between the Availability Zones that are enabled for your Auto Scaling group. Amazon EC2 Auto Scaling does this by attempting to launch new instances in the Availability Zone with the fewest instances.
Auto Scaling components
- Auto Scaling Group
- Your EC2 instances are organized into groups so that they can be treated as a logical unit for the purposes of scaling and management.
- When you create a group, you can specify its minimum, maximum, and, desired number of EC2 instances.
- Configuration templates
- Your group uses a launch template, or a launch configuration (not recommended, offers fewer features), as a configuration template for its EC2 instances.
- You can specify information such as the AMI ID, instance type, key pair, security groups, and block device mapping for your instances.
- Scaling options
- Amazon EC2 Auto Scaling provides several ways for you to scale your Auto Scaling groups.
Rebalancing activities
- Rebalancing activities fall into two categories: Availability Zone rebalancing and capacity rebalancing.
Availability Zone rebalancing
- After certain actions occur, your Auto Scaling group can become unbalanced between Availability Zones. Amazon EC2 Auto Scaling compensates by rebalancing the Availability Zones. The following actions can lead to rebalancing activity:
- You change the Availability Zones for your group.
- You explicitly terminate or detach instances and the group becomes unbalanced.
- An Availability Zone that previously had insufficient capacity recovers and has additional capacity available.
- An Availability Zone that previously had a Spot price above your maximum price now has a Spot price below your maximum price.
Capacity Rebalancing
- You can enable Capacity Rebalancing for your Auto Scaling groups when using Spot Instances.
- When you turn on Capacity Rebalancing, Amazon EC2 Auto Scaling attempts to launch a Spot Instance whenever Amazon EC2 notifies that a Spot Instance is at an elevated risk of interruption.
Amazon EC2 Auto Scaling instance lifecycle
The EC2 instances in an Auto Scaling group have a path, or lifecycle, that differs from that of other EC2 instances.
Scale out
- When a scale-out event occurs, the Auto Scaling group launches the required number of EC2 instances, using its assigned launch configuration.These instances start in the
Pending
state - If you add a lifecycle hook to your Auto Scaling group, you can perform a custom action here.
- When each instance is fully configured and passes the Amazon EC2 health checks, it is attached to the Auto Scaling group and it enters the
InService
state.
Instances in service
Instances remain in the InService
state until one of the following occurs:
- A scale-in event occurs, and Amazon EC2 Auto Scaling chooses to terminate this instance in order to reduce the size of the Auto Scaling group.
- You put the instance into a
Standby
state. - You detach the instance from the Auto Scaling group.
- The instance fails a required number of health checks, so it is removed from the Auto Scaling group, terminated, and replaced
Scale in
- The following scale-in events direct the Auto Scaling group to detach EC2 instances from the group and terminate them:
- You manually decrease the size of the group.
- You create a scaling policy to automatically decrease the size of the group based on a specified decrease in demand.
- You set up scaling by schedule to decrease the size of the group at a specific time.
- Instances that are in the process of detaching from the Auto Scaling group and shutting down enter the
Terminating
state, and can't be put back into service. If you add a lifecycle hook to your Auto Scaling group, you can perform a custom action here
Attach an instance
- You can attach a running EC2 instance that meets certain criteria to your Auto Scaling group.
- After the instance is attached, it is managed as part of the Auto Scaling group.
Detach an instance
- You can detach an instance from your Auto Scaling group.
- After the instance is detached, you can manage it separately from the Auto Scaling group or attach it to a different Auto Scaling group.
Lifecycle hooks
- You can add a lifecycle hook to your Auto Scaling group so that you can perform custom actions when instances launch or terminate.
- If you added an
autoscaling:EC2_INSTANCE_LAUNCHING
lifecycle hook to your Auto Scaling group, the instances move from thePending
state to thePending:Wait
state. After you complete the lifecycle action, the instances enter thePending:Proceed
state. - If you added an
autoscaling:EC2_INSTANCE_TERMINATING
lifecycle hook to your Auto Scaling group, the instances move from theTerminating
state to theTerminating:Wait
state. After you complete the lifecycle action, the instances enter theTerminating:Proceed
state.
Enter and exit standby
- You can put any instance that is in an
InService
state into aStandby
state. This enables you to remove the instance from service, troubleshoot or make changes to it, and then put it back into service. - Instances in a
Standby
state continue to be managed by the Auto Scaling group. However, they are not an active part of your application unt