Instance Refresh and Lifecycle Hooks
Roll out a new launch template gradually with instance refresh, and use lifecycle hooks to run custom logic before instances are launched or terminated.
The Problem of Rolling Instance Updates
When you update a Launch Template (new AMI, new user data, new instance type), existing running instances in the ASG do not automatically get replaced—they keep running the old configuration. To propagate changes you must replace instances. Manually terminating and relaunching instances is risky and error-prone. Instance Refresh automates this process with configurable safety controls.
Instance Refresh: How It Works
Instance Refresh replaces ASG instances in rolling batches. At each step it terminates a batch of old instances, waits for the new instances to pass health checks, and then proceeds to the next batch. You control the pace with a MinHealthyPercentage (the minimum percentage of capacity that must remain healthy during the refresh) and an optional InstanceWarmup time.
aws autoscaling start-instance-refresh \
--auto-scaling-group-name 'MyAppASG' \
--preferences '{
"MinHealthyPercentage": 80,
"InstanceWarmup": 300,
"CheckpointPercentages": [20, 50, 100],
"CheckpointDelay": 600
}'All lessons in this course
- Launch Templates and ASG Configuration
- Scaling Policies: Target Tracking and Step Scaling
- Scheduled Scaling and Predictive Scaling
- Instance Refresh and Lifecycle Hooks