A lifecycle hook is a tool used to manage the lifecycle of Elastic Compute Service (ECS) instances in a scaling group. When Auto Scaling triggers a scaling activity, a lifecycle hook can be triggered to put the ECS instances involved in the scaling activity into the wait state. This provides a period of time for you to perform custom operations until the lifecycle hook times out.

What is a lifecycle hook?

A lifecycle hook can suspend a scaling activity that is triggered by Auto Scaling and provides a period of time for you to perform custom operations. You can specify the following parameters for a lifecycle hook:

  • Applicable Scaling Activity Type. For example, if you set this parameter to Scale-out Event, the lifecycle hook puts ECS instances into the wait state only during scale-out events.
  • Timeout Period. During the timeout period, you can perform custom operations. You can delete a lifecycle hook or call the CompleteLifecycleAction operation to terminate the wait state of a scaling activity ahead of schedule.
  • Notification Method. For example, you can use Message Service (MNS) queues or topics to help you perform custom operations in a timely manner or use Operation Orchestration Service (OOS) templates to automatically execute tasks.
    Note You are charged for the MNS service. For more information, visit the Pricing tab of the Message Service page.
  • Execution Policy. This parameter specifies the next action to take after the wait state ends. The action is to continue or reject a scaling activity.
    Note Only when Notification Method in a lifecycle hook is set to OOS Template, the next action to take is determined by the execution result of the specified OOS template, instead of by the Execution Policy parameter value. If the execution is successful, the scaling activity continues. If the execution fails, the scaling activity that is a scale-out event is rolled back and the scaling activity that is a scale-in event continues.


You can use lifecycle hooks in the following scenarios. After ECS instances are put into the wait state, you can perform custom operations on them before the instances provide services.

  • ECS instances that are created during scale-out events are not suitable to immediately provide services to clients. For example, if ECS instances are required to be added to an ApsaraDB instance or to be bound with secondary elastic network interfaces (ENIs) or if applications deployed on ECS instances require some time to start to provide services, you can use lifecycle hooks.
  • During scale-in events, ECS instances are not suitable to be immediately removed. For example, before ECS instances are removed, you must back up data for the instances, copy logs from the instances, or wait until the instances finish processing all client requests.

For more information, see Use lifecycle hooks to ensure service availability and Overview of best practices for lifecycle hooks and OOS templates.


  • You can create only a limited number of lifecycle hooks for a scaling group. For more information, see Limits.
  • When a scaling activity is triggered in a scaling group, whether other scaling activities in the scaling group can be executed is determined by the settings of the expected number of instances.
    • If the expected number of instances is not specified for the scaling group, Auto Scaling rejects other scaling activities.
    • If the expected number of instances is specified for the scaling group, Auto Scaling can execute other scaling activities only when the ongoing scaling activity is a parallel scaling activity. For information about how to determine a parallel scaling activity, see Common terms and operations.