Amazon EC2 Auto Scaling

Amazon EC2 Auto Scaling is a region-specific Amazon Web Services service that maintains application availability by automatically adding or removing Amazon EC2 instances in response to compute workload, ensuring the correct number of instances are available to handle load and adjusting capacity at the lowest possible cost.

Key points

  • An Auto Scaling group (ASG) is a collection of the minimum number of EC2 instances used for high availability, and it scales across multiple Availability Zones within the same AWS region.
  • ASG sizing is driven by desired capacity, not necessarily equal to max size — e.g. DesiredCapacity: 2, MinSize: 1, MaxSize: 2 produces 2 running EC2 instances.
  • Supports fault tolerance, health checks, scaling policies, and cost management.
  • Horizontal Scaling (increasing/decreasing the number of EC2 instances) is the automatic scaling method used, rather than Vertical Scaling (increasing/decreasing instance size, e.g. small to large).
  • Launch Templates are now the only way to create new launch configs. AWS blocked the creation of new Launch Configurations as of December 31, 2023, and recommends Launch Templates for all new ASGs; launch configurations are legacy — existing ones keep working, but they can’t be created or copied anymore.
    • Launch Configuration (legacy): a configuration file used by an ASG to launch instances; launches only one of Spot or On-Demand; specifies a single instance type; one launch configuration active at a time.
    • Launch Template (current): adds extra features over a launch configuration; can launch both Spot and On-Demand instances together; specifies multiple instance types; supports multiple versions and multiple launch templates.
  • Distinct from AWS Auto Scaling: EC2 Auto Scaling manages only Auto Scaling groups of EC2 instances. AWS Auto Scaling is a separate, broader service that sits on top of it — a single unified interface to configure scaling plans across EC2 Auto Scaling groups, Amazon Elastic Container Service (ECS) services, Amazon DynamoDB tables/indexes, Amazon Aurora read replicas, and EC2 Spot Fleets.
  • Ways to scale an Auto Scaling group:
    • Manual Scaling — update the desired capacity of the ASG by hand.
    • Scheduled Scaling — adds or removes instances based on predictable traffic patterns (e.g. scale out every Tuesday, scale in every Saturday).
    • Dynamic Scaling:
      • Target tracking scaling policy — adds/removes instances to keep a scaling metric close to a specified target value.
      • Simple Scaling Policy — adds/removes instances when the scaling metric exceeds a threshold value.
      • Step Scaling Policy — adds/removes instances based on step adjustments (lower and upper bound of the metric value).
      • Predictive Scaling — uses machine learning on historical load data to forecast traffic and scale ahead of anticipated demand, rather than reacting after a metric threshold is crossed.
  • The cooldown period is the time during which an ASG doesn’t launch or terminate further instances until the previous scaling activity completes.
  • Useful for a significant rise in online traffic and dynamic resource adjustment in response to changing demand.
  • Integrates with Amazon Cloudwatch alarms, which trigger scaling activity (e.g. add EC2 instances when an alarm fires).
  • Warm pools keep a set of pre-initialized EC2 instances (stopped, running, or hibernated) alongside an ASG so scale-out events can draw on already-booted instances instead of over-provisioning the group to hide long instance boot times.

Sources