Preparing Instances with Lifecycle Hooks and Warm Pools
This lesson explains how instances pass through states that can be paused or prepared in advance, so they are ready before they take traffic and finish work before they go.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how lifecycle hooks run custom actions.
- Explain how warm pools, instance warm-up and custom AMIs speed up scale-out.
- Explain health check grace periods, scale-in protection and standby.
Lifecycle hooks
Lifecycle hooks pause instances as they launch or terminate so that custom actions can run. A launch hook holds new instances in the Pending:Wait state, so scripts can install software, register the instance with external systems or warm caches before it enters service and receives traffic.
A termination hook holds instances in the Terminating:Wait state, so they can drain connections, finish jobs or copy logs before they disappear. A hook waits until it is completed, by the instance itself or by automation triggered through EventBridge, SNS or SQS notifications, or until its timeout expires, which is one hour by default.
The following diagram shows where each hook pauses an instance.

Lifecycle hooks
Speeding up scale-out
Scaling out helps only once new instances are ready to serve, and applications that take minutes to start can fall behind a sudden rise in load. Three features shorten or manage that delay. Warm pools keep instances that have already completed their launch work, stopped, hibernated or running, beside the group; scale-out takes one of them instead of launching from scratch, so it completes in seconds.
Default instance warm-up tells the group how long a new instance needs before its metrics should count. Without it, booting instances report low or no load, and the policy may launch even more instances than needed. Custom AMIs with the software already installed reduce the work done at boot, so every new instance starts faster. The following table summarises the features.
| Feature | Effect |
|---|---|
| Warm pools | Keep pre-initialised instances stopped, hibernated or running, so scale-out takes seconds instead of minutes |
| Default instance warm-up | Stops new instances' metrics counting until they are ready, so booting instances do not cause over-scaling |
| Custom AMIs | Bake software into the image so less work happens at boot |
The following diagram compares scale-out with and without a warm pool.

Health checks and grace periods
Several settings control how Auto Scaling treats new and existing instances. The health check grace period stops new instances from being marked unhealthy before they have finished starting; if it is too short, instances are terminated while still booting and the group cycles endlessly.
Scale-in protection stops chosen instances from being terminated during scale-in, for example while they process a long job. Instances can also be moved into standby, which removes them from service for troubleshooting or updates without the group replacing them, and returned to service afterwards.
Endless replacement
Slow-starting instances and lost logs
A Java application takes eight minutes to start. During spikes, users see errors before new instances are ready, and logs are lost when instances scale in.
| Problem | Fix |
|---|---|
| Instances take eight minutes to be ready | A warm pool of stopped, pre-initialised instances |
| Booting instances skew metrics and cause over-scaling | Default instance warm-up of 480 seconds |
| Instances marked unhealthy while starting | A health check grace period above the start-up time |
| Logs lost on termination | A termination lifecycle hook that copies logs to S3 before completing |
Scale-out now takes seconds, and every terminated instance hands over its logs first.
What does a warm pool do for an Auto Scaling group?
Show answer
It keeps pre-initialised instances, stopped or running, ready to join the group, so scale-out skips the slow start-up of applications that take a long time to initialise.
Exam Tips
Remember for the exam
- To run a script before an instance terminates, use a lifecycle hook.
- When long boot times delay scaling, use warm pools.
- If the group adds too many instances while new ones boot, configure instance warm-up.
- If new instances are terminated before they finish starting, increase the health check grace period.
- To troubleshoot an instance without it being replaced, put it into standby.