AWS Auto Scaling
Amazon EC2 Auto Scaling launches and terminates EC2 instances automatically. A group of instances is managed as a unit: AWS keeps it between a minimum and a maximum size, spreads the instances across Availability Zones and replaces the ones that fail their health checks.
Key concepts #
- Launch template: the blueprint of the instances: AMI, instance type, key pair, security groups, user data (Cloud-init), tags and IAM instance profile.
- Auto Scaling group (ASG): the minimum, maximum and desired number of instances and the subnets where they run.
- Scaling policies: target tracking (keep a metric, such as the average CPU, near a value), step and simple scaling, scheduled actions and predictive scaling.
- Health checks: EC2 status checks, and optionally the health checks of an Elastic Load Balancer.
- Instance refresh: replaces the instances gradually when the launch template changes.
- Warm pools and lifecycle hooks speed up and customize the start and the termination of instances.
Pricing #
There is no charge for Auto Scaling itself. You pay for the resources that it launches (instances, volumes, data transfer) and for optional detailed CloudWatch monitoring.
With Terraform #
The resources are aws_launch_template, aws_autoscaling_group, aws_autoscaling_policy and aws_autoscaling_schedule. Add ignore_changes = [desired_capacity] to the group so that Terraform does not undo the changes made by the scaling policies.
See tutorials:
See also: AWS EKS node groups and AWS ECS capacity use Auto Scaling groups.