All Products
Search
Document Center

Auto Scaling:Use the lifecycle hook feature to ensure service availability

Last Updated:Apr 01, 2026

Lifecycle hooks give scaling activities a pause window — time for instances to fully start up before receiving traffic, or to finish processing in-flight requests before being removed. Configure lifecycle hooks for both scale-out and scale-in events to keep your application continuously available.

The examples below use Classic Load Balancer (CLB). The same approach applies to Application Load Balancer (ALB) and Network Load Balancer (NLB) server groups.

Prerequisites

Before you begin, ensure that a CLB instance is associated with your scaling group. You can also associate an ALB server group or an NLB server group based on your business requirements. For setup instructions, see Associate SLB instances with or disassociate SLB instances from a scaling group.

Key concepts

ConceptDescription
Server Load Balancer (SLB)A service that distributes incoming network traffic across backend servers to improve throughput and eliminate single points of failure (SPOFs). SLB includes three types: CLB, ALB, and NLB. See What is SLB?What is CLB?What is ALB?What is NLB?
Lifecycle hookA tool used to manage the lifecycles of ECS instances or elastic container instances in a scaling group — pausing a scaling activity and holding instances in a waiting state until the timeout expires. See Overview

Scale-out: wait for application startup

The problem

Without a lifecycle hook, Auto Scaling attaches new Elastic Compute Service (ECS) instances or elastic container instances to the CLB backend immediately after they are created. If the CLB forwards client requests before the application has finished starting, the requests fail.

How lifecycle hooks help

When a scale-out lifecycle hook is active, newly created instances enter Pending Add state instead of being attached to the CLB right away. The instances remain in Pending Add until the hook's timeout period expires. During that window, the application starts up. When the timeout expires, Auto Scaling attaches the instances to the CLB and transitions them to In Service.

The scale-out flow with a lifecycle hook:

  1. Auto Scaling creates new ECS instances or elastic container instances.

  2. Instances enter Pending Add state — not yet attached to the CLB.

  3. The application starts up on each instance during the timeout period.

  4. When the timeout expires — or you call CompleteLifecycleAction to end it early — Auto Scaling attaches the instances to the CLB. See CompleteLifecycleAction.

  5. Instances transition to In Service and begin receiving traffic.

Create a scale-out lifecycle hook

Create a lifecycle hook for your scaling group with the following settings:

ParameterValueNotes
Scaling ActivityScale-out EventTriggers the hook on scale-out only
Timeout Period30–21600 (integer, seconds)Set to the maximum time your application needs to start
Default Execution PolicyContinueProceeds with attaching instances when the timeout expires

Scale-in: drain in-flight requests

The problem

Without a lifecycle hook, Auto Scaling detaches instances from the CLB and removes them from the scaling group immediately. Instances that still have unprocessed client requests drop those requests, causing errors for your users.

How lifecycle hooks help

When a scale-in lifecycle hook is active, Auto Scaling detaches instances from the CLB first, then holds them in Pending Remove state. While in Pending Remove, instances no longer receive new requests but continue processing any requests that arrived before the hook took effect. When the timeout expires, Auto Scaling removes the instances from the scaling group.

The scale-in flow with a lifecycle hook:

  1. Auto Scaling selects instances to remove.

  2. Auto Scaling detaches instances from the CLB — no new requests are routed to them.

  3. Instances enter Pending Remove state and finish processing existing requests.

  4. When the timeout expires — or you call CompleteLifecycleAction to end it early — Auto Scaling removes the instances from the scaling group. See CompleteLifecycleAction.

Create a scale-in lifecycle hook

Create a lifecycle hook for your scaling group with the following settings:

ParameterValueNotes
Scaling ActivityScale-in EventTriggers the hook on scale-in only
Timeout Period30–21600 (integer, seconds)Set to the maximum time needed to drain in-flight requests