Lesson 4 of 5 Amazon EC2 Auto Scaling

Refreshing, Protecting and Troubleshooting Auto Scaling Groups

This lesson explains day-to-day Auto Scaling operations: rolling out new launch template versions, controlling which instances are removed, pausing processes for maintenance and fixing groups that fail to launch.

Learning outcomes

After completing this lesson, you will be able to:

  • Roll out new versions with instance refresh.
  • Use termination policies, scale-in protection and suspended processes.
  • Troubleshoot launch failures from activity history.

Instance refresh

Instance refresh replaces instances in a group with ones launched from a new launch template version or configuration, in batches. The minimum healthy percentage (for example 90%) and optional maximum healthy percentage (above 100% launches new instances before terminating old ones) control capacity during the refresh. Checkpoints pause at chosen percentages to validate, skip matching leaves instances that already match the desired configuration, and auto rollback returns to the previous configuration if the refresh fails or CloudWatch alarms go into ALARM. It is the standard way to roll out a new AMI.

The following diagram shows a refresh paused at its checkpoint.

An instance refresh. Instances are replaced in batches from a new launch template version while the minimum healthy percentage, here 90%, keeps capacity up. A checkpoint pauses at 50% for validation, skip matching leaves instances that already match, and auto rollback returns to the previous version if the refresh fails or an alarm fires.
The counts are illustrative.

Termination policies, scale-in protection and suspended processes

When scaling in, the default termination policy first chooses the AZ with the most instances, then terminates instances using the oldest launch template or configuration, then those closest to the next billing hour. Other policies include OldestInstance, NewestInstance, OldestLaunchTemplate, AllocationStrategy and custom Lambda-based policies. Instance scale-in protection prevents specific instances being terminated on scale-in (not on health check replacement). Putting an instance into Standby removes it from service for troubleshooting while keeping it in the group. Suspending processes such as Launch, Terminate, HealthCheck, ReplaceUnhealthy, AZRebalance or AlarmNotification stops Auto Scaling from interfering during maintenance.

Scenario questions

Controlling termination

Exam skills 2.1.1

Control which instances a group terminates and when.

Log in to try this activity Interactive activities are free with an account.

Troubleshooting launches

The group's activity history (describe-scaling-activities) records the reason for every failed launch. The following table lists common messages.

Message or symptomCauseFix
Launch template ... AMI does not existAMI deleted, not shared or in another RegionUpdate the template version
You are not authorized to use launch template / iam:PassRoleMissing permissions for the service-linked role or the instance profile roleGrant iam:PassRole or fix the template
InsufficientInstanceCapacityNo capacity for the type in an AZAdd instance types or AZs
VcpuLimitExceededAccount quotaRequest a quota increase
Client.InvalidKMSKey.InvalidState / KMS key accessEncrypted volumes and the service-linked role lacks key accessGrant the AWSServiceRoleForAutoScaling role use of the key
Desired capacity never reachedMaximum too low, subnet IPs exhausted, or suspended Launch processCheck limits, subnets and suspended processes
Worked example

Rolling out a patched AMI

A new hardened AMI is published monthly. The team creates a new launch template version and starts an instance refresh with minimum healthy 90%, maximum healthy 110%, a checkpoint at 25% with a 10-minute wait, skip matching enabled and auto rollback tied to the group's 5XX and latency alarms. In the first batch the 5XX alarm fires because the AMI is missing a library. The refresh rolls back automatically to the previous template version, and no more than 10% of capacity was ever affected.

aws autoscaling start-instance-refresh --auto-scaling-group-name web-asg \
  --desired-configuration '{"LaunchTemplate":{"LaunchTemplateName":"web-lt","Version":"7"}}' \
  --preferences '{"MinHealthyPercentage":90,"MaxHealthyPercentage":110,"SkipMatching":true,
    "CheckpointPercentages":[25,100],"CheckpointDelay":600,"AutoRollback":true,
    "AlarmSpecification":{"Alarms":["web-5xx","web-latency"]}}'
Check yourself

Does scale-in protection prevent replacement of an unhealthy instance?

Show answer

No. It only stops scale-in terminations.

Exam Tips

Remember for the exam

  • Instance refresh rolls out new templates with min/max healthy percentages, checkpoints and auto rollback.
  • The default termination policy balances AZs, then removes the oldest launch template.
  • Scale-in protection stops scale-in terminations, not health replacements.
  • Suspend processes such as ReplaceUnhealthy or AZRebalance during maintenance.
  • Read the activity history for the reason a launch failed.