Homeβ€Ί Blogβ€Ί AWS Architecture Series #122 β€” Abandon and continue both terminate the instance…
AWS Architecture AWS Architecture Series

AWS Architecture Series #122 β€” Abandon and continue both terminate the instance

A lifecycle hook pauses an instance for one hour by default so a custom action can run, and on launch that pause is genuinely powerful: it happens before the instance reaches InService, which is why a launch hook is the documented alternative to a long health check grace period. What happens if the hook times out is set by its DefaultResult, which the PutLifecycleHook API defaults to ABANDON - so a timed-out launch hook terminates and replaces the instance rather than admitting it. On termination the same mechanism is weaker than it looks. Termination lifecycle hooks operate on a best-effort basis, and if the hook times out or is abandoned, Auto Scaling proceeds with terminating the instance immediately. Both results allow the instance to terminate - abandon merely stops later hooks running. A hook written to flush state does not guarantee the state is flushed, and keeping the instance requires a separate instance lifecycle policy configured to retain on TerminateHookAbandon.

Verified against current vendor documentation on 23 November 2026. Pricing, limits and API behaviour were checked against the official docs on that date. Cloud services change fast — if you are reading this much later, treat the specifics as a starting point and re-check the linked sources.

Business Challenge

The last post ended on a recommendation it did not explain: AWS says to use lifecycle hooks rather than a long health check grace period. That turns out to be a statement about ordering, and once you see the ordering the advice is obviously right.

The same mechanism on the termination side invites an assumption that is wrong, and wrong in the direction that loses data.

1A launch hook waits before InService, which is why it replaces the grace period

“The lifecycle hook puts the instance into a wait state (Pending:Wait) and then performs a custom action.” Then, after it completes: “The instance enters the InService state and the health check grace period starts.”

So the bootstrap wait happens outside the window the grace period covers. The grace period exists to tolerate an instance that is InService but not ready; a launch hook stops it being InService until it is ready. That is why the documented answer to a zero-second grace period is a hook. A launch hook can reduce or eliminate the need for a grace period by completing initialization before the instance enters InService — though both can be used together where additional stabilization time is genuinely needed after it enters service.

2A termination hook is best-effort, and the default is to terminate anyway

“By default, termination lifecycle hooks operate on a best-effort basis. If a termination lifecycle hook times out, or is abandoned, Amazon EC2 Auto Scaling proceeds with terminating the instance immediately.”

A hook written to flush a buffer, upload logs or drain a queue does not guarantee any of that happened. It guarantees you were asked. If your code fails, times out, or reports failure, the instance goes anyway.

3Abandon means the opposite of what the word suggests

On launch, the two results mean what you would expect: continue puts the instance into service, abandon means “we can terminate and replace the instance”. On termination they collapse:

“If an instance is terminating, both abandon and continue allow the instance to terminate. However, abandon stops any remaining actions, such as other lifecycle hooks, and continue allows any other lifecycle hooks to complete.”

Abandon is not a veto. It is a request to skip the remaining hooks on the way out.

Architecture

Diagram: Amazon EC2 Auto Scaling lifecycle hooks. A hook provides a specified amount of time, one hour by default, to wait for a custom action before the instance transitions to the next state. On scale out the hook puts the instance into Pending:Wait and performs a custom action; the timeout can be restarted by recording a heartbeat, and what happens when the timeout elapses is set by the hook's DefaultResult, which the PutLifecycleHook API documents as defaulting to ABANDON, so for a launch hook ABANDON causes the instance to be terminated and replaced while CONTINUE allows the launch to proceed; the heartbeat timeout ranges from 30 to 7200 seconds with a default of 3600. The instance then enters InService and the health check grace period starts, which is why a launch hook is the documented alternative to a long grace period: the hook waits before InService, so it can reduce or eliminate the need for a grace period, although both can be used together where additional stabilization time is required after the instance enters service. Before reaching InService, if the group is associated with a load balancer, the instance is registered and the load balancer starts checking its health. On scale in the hook puts the instance into Terminating:Wait, and after the action completes or the timeout expires the instance moves to Terminating:Proceed and is terminated. The result can be abandon or continue, and the meaning differs by direction: launching, continue means the actions succeeded and the instance can go into service while abandon means they failed and the instance can be terminated and replaced; terminating, both abandon and continue allow the instance to terminate, with abandon stopping any remaining actions such as other hooks and continue allowing them to complete. By default termination hooks operate on a best-effort basis, and if one times out or is abandoned Auto Scaling proceeds with terminating the instance immediately. Retention needs a separate instance lifecycle policy: without one the instance proceeds to termination immediately even on an ABANDON result, while with a policy configured to retain on TerminateHookAbandon the instance moves to a retained state. Retained instances keep incurring standard EC2 charges, do not count toward desired capacity so replacements launch, and are ignored by instance refresh and max instance lifetime. Two clocks bound the wait: the default heartbeat timeout is one hour, and a global timeout is 48 hours or 100 times the heartbeat timeout whichever is smaller, so the default ceiling is 48 hours. A hook does not prevent a Spot Instance terminating when capacity is no longer available, on a two-minute notice; Auto Scaling throttles the launch rate when hooks fail consistently; hooks do not fire on attach, detach, standby moves or force delete; multiple hooks created with the group must share a notification target and IAM role; and simple scaling policy activities are paused until lifecycle actions complete and the cooldown expires.

Where the wait states sit

PhaseSequence
Scale out Pending → Pending:Wait → Pending:Proceed → registered with the load balancer → InService, then the grace period starts
Scale in deregistered from the load balancer → Terminating:Wait → Terminating:Proceed → terminated
Root volume replacement ReplacingRootVolume:Wait → RootVolumeReplaced → Pending → Pending:Wait → InService

One ordering detail is easy to miss and matters for the load-balancer use case: “However, before the instance reaches the InService state, if the Auto Scaling group is associated with an Elastic Load Balancing load balancer, the instance is registered with the load balancer, and the load balancer starts checking its health.”

Registration happens at the end of the hook, not at the start of the launch. That is what makes a launch hook effective at keeping traffic away from a half-built instance — the instance is not a target until the hook says so. It also means the load balancer's own health checks begin before InService, which is the reason the grace period exists at all for groups that do not use hooks.

Two clocks, and the one you cannot extend past

“Instances can remain in a wait state for a finite period of time. The default timeout for a lifecycle hook is one hour (heartbeat timeout). There is also a global timeout that specifies the maximum amount of time that you can keep an instance in a wait state. The global timeout is 48 hours or 100 times the heartbeat timeout, whichever is smaller.”

With the default one-hour heartbeat, 100 heartbeats would be 100 hours, so the ceiling is the 48-hour figure — two days, and no amount of heartbeating gets past it. The heartbeat is the renewable clock: “If you need more time, you can restart the timeout period by recording a heartbeat.” The global timeout is not renewable, and the instance lifecycle policy documentation names that ceiling as a reason to reach for retention instead — “Applications requiring extended draining periods that may exceed the maximum lifecycle hook timeout of 48 hours”.

What expiry does is not fixed, and this is the part to configure deliberately. When a lifecycle hook times out, Auto Scaling applies the hook's configured DefaultResult, described as “The action the Auto Scaling group takes when the lifecycle hook timeout elapses or if an unexpected failure occurs”, with valid values CONTINUE and ABANDON. The API reference is explicit about which you get if you say nothing: “The default value is ABANDON.”

For a launch hook, ABANDON causes the instance to be terminated and replaced, whereas CONTINUE allows the launch process to proceed. So launching an instance after an unsuccessful bootstrap is not the universal default — it is what you get only with CONTINUE set. The user guide's walkthrough describes that path, which is worth knowing when the narrative and the API reference are read side by side.

On the termination side the distinction collapses, because both results permit termination. The configured DefaultResult therefore changes a great deal on launch and almost nothing on the way out — except which later hooks still run.

What retention actually is

To prevent an Auto Scaling termination from proceeding when a termination lifecycle action is abandoned, configure an instance lifecycle policy to retain instances on TerminateHookAbandon. This provides an opportunity to retry or complete cleanup but does not guarantee graceful shutdown or prevent data loss from other failure mechanisms. The scope is stated narrowly in the documentation: “Instance lifecycle policies provide protection against Amazon EC2 Auto Scaling terminations when a termination lifecycle action is abandoned.”

The behaviour is stated as a direct comparison: “Without an instance lifecycle policy configured, the instance proceeds to termination immediately even if the termination lifecycle action was completed with ABANDON result. With an instance lifecycle policy configured to retain instances on TerminateHookAbandon, the instance moves to a retained state if the termination lifecycle action was completed with ABANDON result.”

So ABANDON changes meaning depending on whether a policy exists. Without one it is a hint that stops later hooks. With one it is the signal that preserves the instance. The same API call with the same argument, two different outcomes, decided by group configuration.

Retention is not free, and the documentation is unusually direct about the bill: “Instances in retained states continue to incur standard Amazon EC2 charges. These instances don't count toward your Auto Scaling group's desired capacity, so Auto Scaling launches replacement instances to maintain the desired size. Auto Scaling features such as instance refresh and max instance lifetime will also ignore retained instances.”

Read that carefully: a retained instance is paid for, outside the group's capacity accounting, and invisible to the two mechanisms that would otherwise eventually clean it up. A policy that retains on every abandoned shutdown, in a group with a flaky shutdown script, accumulates paid instances that nothing will ever remove. Retention is a tool for workloads where a failed shutdown genuinely requires a human, and the human is the part you have to supply.

Getting rid of one is deliberate too: “After you complete the necessary actions on the retained instance, you call the TerminateInstanceInAutoScalingGroup API. This starts a new termination attempt that invokes your termination lifecycle hooks again, so the instance terminates only after you complete the new lifecycle action with the CONTINUE result.” The hooks run again, so the cleanup path has to be idempotent.

Where hooks do not fire at all

The gaps matter more than the coverage, because each one is a path by which an instance leaves without your action running.

  • Attach, detach, standby and force delete. The footnote on the availability table is explicit: “Does not apply when you attach or detach instances, move instances in and out of standby mode, or delete the group with the force delete option.” Three of those are things an operator does during an incident, and the fourth is how groups get torn down in a hurry.
  • Spot interruption. A hook “does not prevent an instance from terminating in the event that capacity is no longer available, which can happen at any time with a two-minute interruption notice”. If your shutdown needs more than two minutes, Spot is not the place for it regardless of hooks.
  • Warm pools. “The stop or hibernate action does not wait for user data to finish running”, so an instance entering a warm pool can be stopped mid-bootstrap unless a launching hook holds it.

Two operational side effects

A broken hook does not fail loudly; it slows the group down. “Amazon EC2 Auto Scaling limits the rate at which it allows instances to launch if the lifecycle hooks are failing consistently, so make sure to test and fix any permanent errors in your lifecycle actions.” So the symptom of a permanently broken launch hook is a group that scales out sluggishly — which looks like a capacity problem, not a code problem.

And hooks interact with the older scaling policies: “In most cases when lifecycle hooks are invoked, scaling activities due to simple scaling policies are paused until the lifecycle actions have completed and the cooldown period has expired.” An hour-long hook plus a cooldown is an hour in which a simple scaling policy does nothing.

Why This Architecture Holds Up

Best-effort on termination is the right default, even though it surprises people

A termination hook that could block indefinitely would turn every scale-in into a potential hang, and a group that cannot shed capacity is a worse failure than a lost buffer flush. Defaulting to proceed anyway keeps the control loop live. The criticism is not the default; it is that the word abandon suggests a veto it does not have.

Separating retention into its own policy is better than a flag on the hook

Retention has consequences the hook author cannot see: a paid instance outside capacity accounting, invisible to instance refresh, awaiting a human. Making it a group-level policy rather than a hook option puts the decision where the cost lands, and forces it to be made once deliberately rather than implied by a return value.

The hook-before-InService ordering is the quiet good design

Putting the wait before InService, and registration at the end of the hook, is what makes the readiness problem solvable at all. It means readiness is expressed as a state transition rather than as a timer. The two mechanisms act at different stages, so they compose: the hook covers initialization before InService, and a grace period, if you keep one, covers stabilization after it.

Key Architecture Decisions

DecisionTakeWhy
Readiness on launch Launch hook for initialization; keep a grace period only for post-service stabilization The hook waits before InService, so it can reduce or remove the need for a grace period without replacing it
Cleanup on termination Hook for the attempt; add a retention policy where an abandoned action must not proceed The hook alone is best-effort and both results permit termination; retention covers that scenario, not durability generally
Retention policy scope Only where a failed shutdown genuinely needs a human Retained instances are billed, outside capacity, and ignored by refresh and max lifetime
Heartbeat timeout Set it to the real action duration, not the default hour The range is 30 to 7200 seconds; a too-long timeout delays the configured DefaultResult rather than preventing it
Shutdown needing more than two minutes Not on Spot A hook does not prevent an interruption termination
Cleanup script design Idempotent Terminating a retained instance invokes the termination hooks again

The audit worth running

  • Every termination hook whose purpose is data safety, checked against whether the group has an instance lifecycle policy. Without one, the hook is advisory.
  • Every launch hook paired with a long grace period, checked for whether the grace period is covering genuine post-service stabilization or is just absorbing an unmeasured hook duration. Both together is a legitimate configuration; both together by accident is not.
  • Any group scaling out slowly, checked for consistently failing hooks before capacity is blamed.
  • Runbooks that detach instances or force-delete groups, which bypass hooks entirely.

Closing Thought

This series has spent several posts on the same shape: a mechanism that looks like a guarantee and is documented as an attempt. Automatic recovery attempts a migration. An aggregate alarm attempts to mean one thing. A termination hook attempts a graceful shutdown. In each case AWS is precise in the documentation and the precision is easy to read past, because the feature name sounds like a promise.

The useful habit is to ask what happens when the mechanism fails, and whether the failure is permissive or blocking. On termination it is permissive whatever you configure: a hook that never completes terminates the instance anyway. On launch it depends on the hook's DefaultResult, and the API default of ABANDON means a timed-out launch hook terminates and replaces the instance rather than admitting it. Either way the group keeps moving, which is almost certainly right, and either way the hook is where you express intent rather than where you enforce it.

Where an abandoned shutdown must not simply proceed, the retention policy is the mechanism that stops it — for that scenario, not as a general durability guarantee. It buys an opportunity to retry or finish cleanup by hand; it does not protect against the other ways an instance can go away, and a Spot interruption or a force delete still bypasses all of this. The price is a billed instance waiting for a person, which is the honest cost of refusing to let one specific failure pass silently.

Next in this series

Reliability — Amazon EC2 Auto Scaling warm pools: what the Stopped, Running and Hibernated pool states cost, why the stop action does not wait for user data, how reuse-on-scale-in changes the lifecycle, and when a warm pool is cheaper than a faster bootstrap.

Official AWS Reference

Comments

How was your experience?
Your feedback helps improve this site.
PoorExcellent