AWS Certified DevOps Engineer – Professional
EC2 Auto Scaling lifecycle hooks: CONTINUE vs ABANDON (DOP-C02)
A lifecycle hook holds an instance in a wait state while it launches or terminates, so a custom action can run. The EC2 Auto Scaling User Guide gives it one hour by default. On launch, ABANDON terminates and replaces the instance. On termination, both CONTINUE and ABANDON let the instance terminate.
When does a lifecycle hook run?
Launch and termination hooks apply to all launches and terminations in the group, whether automatic or started by calls such as SetDesiredCapacity or TerminateInstanceInAutoScalingGroup. They also apply to replacements made by instance refresh, maximum instance lifetime and Capacity Rebalancing, and to instances entering and leaving a warm pool.
Hooks do not run when you attach or detach instances, move instances in or out of standby, or delete the group with the force delete option.
The default heartbeat timeout is one hour. An instance can stay in a wait state for at most 48 hours or 100 times the heartbeat timeout, whichever is smaller. A lifecycle hook does not stop a Spot Instance interruption.
What do CONTINUE and ABANDON do?
For a launching instance, CONTINUE means the custom action succeeded and the instance can go into service. ABANDON means it failed, and Auto Scaling can terminate and replace the instance.
For a terminating instance, both results allow the termination. ABANDON stops any remaining actions, such as other lifecycle hooks. CONTINUE lets the other hooks complete. Termination hooks are best effort by default: if one times out or is abandoned, the instance is terminated immediately.
An instance lifecycle policy changes that. With a policy set to retain instances on TerminateHookAbandon, an instance whose termination action ends in ABANDON moves to a retained state. Retained instances keep incurring EC2 charges and do not count toward desired capacity, so Auto Scaling launches replacements.
How does the custom action get notified?
Auto Scaling sends lifecycle event notifications to Amazon EventBridge without a notification target on the hook. AWS recommends EventBridge or a user data script over Amazon SNS or Amazon SQS as the target. A rule with the source aws.autoscaling and the detail-type EC2 Instance-launch Lifecycle Action matches launch hooks for a group, and can invoke a Lambda function or another target.
A user data script needs no notification target. To finish the hook from the instance, the script runs complete-lifecycle-action, and the instance's IAM role must allow that call. SNS and SQS targets need the topic or queue ARN and an IAM role that gives Auto Scaling access to it. The console does not show the field for an SNS or SQS target.
With a launch hook, the health check grace period starts when the instance reaches InService. A common use is to finish bootstrap scripts before the instance is registered with the load balancer at the end of the hook.
Where the exam catches people
- Believing
ABANDONon a termination hook keeps the instance: both results let it terminate. Retention needs an instance lifecycle policy withTerminateHookAbandon. - Believing termination hooks run when a group is force deleted: they do not. They also do not run on detach or standby.
- Believing a hook needs an SNS topic or SQS queue to notify anything: Auto Scaling already sends the events to EventBridge.
- Believing a hook can hold an instance indefinitely: the limit is 48 hours or 100 times the heartbeat timeout, whichever is smaller.
- Believing a lifecycle hook delays a Spot interruption: it does not.