When an Auto Scaling Group (ASG) performs a scale-in event (reducing capacity), it decides which EC2 instances to terminate based on termination policies. By default, AWS follows these rules in order:
- Availability Zone Balancing – Ensures instances are evenly distributed across AZs; the ASG tries to keep balance by terminating in the AZ with the most instances.
- On-Demand vs Spot – If mixed, Spot Instances are terminated first to preserve On-Demand capacity.
- Instance Launch Configuration – Newer instances (latest launch configuration/template) are kept; older ones are candidates for termination.
- Billing Hour Consideration – Tries to maximize cost efficiency by selecting instances that are closest to the next billing hour (applies to some older pricing models).
- Default Random Selection – If multiple instances are equally eligible, one is chosen randomly.