Version 2 of the template is ready. Running instances never pick it up: they keep what they were launched with. They have to be replaced.
Which version new instances get
A group that names $Latest (or $Default) launches the new version from now on. A group pinned to a number keeps launching that number:
aws autoscaling update-auto-scaling-group --auto-scaling-group-name web-asg --launch-template LaunchTemplateName=web-lt,Version='$Latest'Replacing them all
An instance refresh replaces every instance in batches:
aws autoscaling start-instance-refresh --auto-scaling-group-name web-asg --preferences '{"MinHealthyPercentage":100,"MaxHealthyPercentage":200,"InstanceWarmup":60}'MinHealthyPercentage: the share of capacity that must stay healthy.MaxHealthyPercentage: how far above capacity it may go. At 100 it terminates first, then launches; above 100 it launches first.InstanceWarmup: how long a new instance gets before it counts.
A group of two, refreshed
| Min / Max | During the refresh | Customers |
|---|---|---|
| 50 / 100 | one old instance goes, then a new one comes | one server carries everything |
| 100 / 200 | two new start, then the old two go | always two serving |
aws autoscaling describe-instance-refreshes --auto-scaling-group-name web-asg --query "InstanceRefreshes[0].[Status,PercentageComplete]" --output textIt goes Pending, InProgress, then Successful, or Failed when new instances never become healthy. aws autoscaling cancel-instance-refresh --auto-scaling-group-name web-asg stops it; instances already replaced stay.
Letting the old ones finish
An old instance is deregistered first, and drains for the target group's deregistration delay: 300 seconds unless lowered. For a shop whose requests take well under a second:
aws elbv2 modify-target-group-attributes --target-group-arn $TG --attributes Key=deregistration_delay.timeout_seconds,Value=30