Skip to content

LifecycleHook

Source: src/AWS/AutoScaling/LifecycleHook.ts

A lifecycle hook that pauses an Auto Scaling instance in a wait state on launch or termination so a handler can drain connections, snapshot state, or warm caches before the transition completes. Pair with consumeLifecycleActions to receive the transition events and CompleteLifecycleAction to signal CONTINUE / ABANDON.

Drain before termination (EventBridge target)

const hook = yield* LifecycleHook("Drain", {
autoScalingGroup: group,
lifecycleTransition: "TERMINATING",
heartbeatTimeout: "300 seconds",
defaultResult: "CONTINUE",
});

Warm caches before an instance enters service

const hook = yield* LifecycleHook("Warm", {
autoScalingGroup: group,
lifecycleTransition: "LAUNCHING",
heartbeatTimeout: "2 minutes",
});