📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials AWS Solutions Architect Auto Scaling Lifecycle Hooks

Auto Scaling Lifecycle Hooks

4 min read Quiz at the end
Use Auto Scaling Lifecycle Hooks to customise instance launch and termination with Lambda functions. Understand Warm Pools for faster scaling.

Auto Scaling Lifecycle Hooks — Control Instance Launch and Terminate

Lifecycle Hooks pause an Auto Scaling Group action at a specific point — BEFORE an instance is put in service (launch) or BEFORE an instance is terminated — so you can perform custom actions.

Teacher Note: Without Lifecycle Hooks, when ASG launches a new instance, it immediately starts receiving traffic. But what if your app takes 2 minutes to start? Traffic hits a half-initialised server. Lifecycle Hooks let you say: wait until my app is fully ready before serving traffic.

Two Hook Types

HookTriggered WhenCommon Use
autoscaling:EC2_INSTANCE_LAUNCHINGNew instance just launched, before in-serviceInstall software, pull config, warm caches, wait for app startup
autoscaling:EC2_INSTANCE_TERMINATINGInstance about to terminateDrain queues, save session data, send final metrics, deregister from service discovery

Lifecycle Hook Flow

Instance Launches
    |
    v
[Lifecycle Hook: LAUNCHING]
    |--- Hook runs (up to 1 hour wait)
    |--- Your Lambda/script installs software, warms cache
    |--- Lambda calls: aws autoscaling complete-lifecycle-action
    v
Instance enters InService state
    |--- ALB starts sending traffic
    |
    ... time passes ...
    |
Scale-in triggered (too many instances)
    |
    v
[Lifecycle Hook: TERMINATING]
    |--- Hook runs
    |--- Lambda drains SQS queue, saves state
    |--- Lambda calls: aws autoscaling complete-lifecycle-action
    v
Instance terminates

Warm Pools — Pre-Initialised Instances

Warm Pools maintain a pool of pre-initialised EC2 instances that are stopped or running (but not receiving traffic). When ASG needs to scale out, it pulls from the warm pool instead of launching fresh instances — dramatically faster scaling.

Exam Tip: Lifecycle Hooks + Lambda is the exam pattern. Lambda function is triggered by the hook via EventBridge, performs the action (install, drain, etc.), then calls complete-lifecycle-action with CONTINUE or ABANDON. Use ABANDON if the setup failed — instance will be terminated.
Topic Quiz · 1 questions

Test your understanding before moving on

1. A company stores application logs in S3 Standard. Logs are accessed frequently for the first 7 days, occasionally for 30 days, then never again. What lifecycle policy minimises cost?
💡 Matching storage class to access pattern: Standard for hot data (7 days), IA for warm data (7-30 days), Glacier Deep Archive for cold/never (30+ days).