All Products
Search
Document Center

Auto Scaling:Overview

Last Updated:Apr 01, 2026

Lifecycle hooks let you pause instances during scale-out or scale-in events so you can run custom operations before Auto Scaling continues or releases them.

For example:

  • During scale-out: A newly launched ECS instance enters the Pending Add state. While it waits, a script installs dependencies and starts your application. Once the script finishes, Auto Scaling adds the instance to the scaling group and it begins serving traffic.

  • During scale-in: An ECS instance selected for removal enters the Pending Remove state. While it waits, you back up instance data and drain in-flight requests. After the operations complete, Auto Scaling stops and releases the instance.

How it works

When Auto Scaling triggers a scaling activity, each lifecycle hook you configure intercepts the instances involved and holds them in a wait state. During this window, you run your custom logic — installing software, registering with a load balancer, flushing logs, or draining connections. After the timeout period expires or you explicitly complete the lifecycle action, Auto Scaling resumes the scaling activity according to the default execution policy.

Scale-out flow

Figure 1 Scale-out flowchart 流程图

  1. Auto Scaling launches a new ECS instance or elastic container instance in response to a scale-out event.

  2. The lifecycle hook fires and puts the instance into the Pending Add state. The timeout period starts.

  3. While the instance is in the Pending Add state, perform your custom operations (for example, install software packages, associate an ApsaraDB RDS instance, or bind a secondary elastic network interface (ENI)).

  4. End the wait state in one of the following ways:

    • Call the CompleteLifecycleAction API to complete the action ahead of schedule.

    • Delete the lifecycle hook to immediately end the wait state.

    • Let the timeout period expire — Auto Scaling then applies the default execution policy.

  5. If the default execution policy is Continue, Auto Scaling adds the instance to the scaling group and it begins serving traffic. If the policy is Reject, Auto Scaling releases the instance.

Scale-in flow

Figure 2 Scale-in flowchart 缩容过程-zh

  1. Auto Scaling selects instances to remove in response to a scale-in event.

  2. The lifecycle hook fires and puts the instances into the Pending Remove state. The timeout period starts.

  3. While the instances are in the Pending Remove state, perform your custom operations (for example, back up data, copy logs, or wait for the instances to finish processing all in-flight requests).

  4. End the wait state by calling CompleteLifecycleAction, deleting the lifecycle hook, or letting the timeout period expire.

  5. Regardless of the default execution policy (Continue or Reject), Auto Scaling stops the instances from providing computing power in the scaling group.

The workflows above use ECS instances as examples. The same flows apply to elastic container instances.

Configuration

Configuration itemDescription
Scaling ActivityThe type of scaling events that trigger the hook. Valid values: Scale-out Event and Scale-in Event.
Timeout PeriodHow long instances stay in the Pending Add or Pending Remove state before Auto Scaling applies the default execution policy. Set this based on how long your custom operations take. To end the wait early, delete the lifecycle hook or call the CompleteLifecycleAction API.
Default Execution PolicyThe action Auto Scaling takes after the timeout period expires. Valid values: Continue and Reject. For scale-out: Continue adds the instance to the scaling group; Reject releases it. For scale-in: both values stop the instances from providing computing power.
Send Notification When Lifecycle Hook Takes EffectHow Auto Scaling notifies you or triggers automation when the hook fires. Options: MNS Topic, MNS Queue, or OOS Template. Use MNS options to receive a notification and respond manually. Use OOS Template to run automated tasks — the CloudOps Orchestration Service (OOS) template must complete before the timeout expires. If the OOS template succeeds, the scaling activity continues. If it fails, scale-out is rolled back while scale-in continues.
Using MNS Topic or MNS Queue incurs charges. For pricing details, see MNS pricing.

Instance lifecycle management

How Auto Scaling handles an instance during scale-in depends on how that instance was added to the scaling group.

How the instance was addedWho manages the lifecycleScale-in behavior
Automatically created by Auto ScalingScaling groupAuto Scaling stops and releases the instance.
Manually added; scaling group manages lifecycleScaling groupAuto Scaling stops and releases the instance.
Manually added; you manage lifecycleYouAuto Scaling removes the instance from the scaling group only. The instance is not released.
You cannot use the scaling group to manage the lifecycle of subscription ECS instances added to the scaling group.

Use cases

Create lifecycle hooks when instances involved in scaling activities need extra time before joining or leaving the scaling group:

  • Scale-out: Instances cannot immediately serve traffic after launch — for example, they need to be associated with an ApsaraDB RDS instance, bound to secondary ENIs, or need time for an application to start.

  • Scale-in: Instances cannot be immediately removed — for example, you need to back up data, copy logs, or wait for instances to finish processing all in-flight requests.

For a practical example, see Use lifecycle hooks to ensure service availability and Overview of best practices for lifecycle hooks and OOS templates.

Limitations

  • Each scaling group supports a maximum of 10 lifecycle hooks.

  • While a lifecycle hook is active, whether other scaling activities can run depends on the Expected Number of Instances feature:

    • If Expected Number of Instances is disabled, Auto Scaling rejects all other scaling activities on the scaling group until the current one completes.

    • If Expected Number of Instances is enabled, Auto Scaling can run other scaling activities only if the ongoing activity is a parallel scaling activity. For details, see Terms.

Manage lifecycle hooks

OperationUser guideAPI reference
Create lifecycle hooksManage lifecycle hooksCreateLifecycleHook
Modify lifecycle hooksManage lifecycle hooksModifyLifecycleHook
Delete lifecycle hooksManage lifecycle hooksDeleteLifecycleHook