All Products
Search
Document Center

Auto Scaling:Overview

Last Updated:Dec 28, 2023

This topic describes the concepts, workflows, scenarios, and limits of lifecycle hooks.

What is a lifecycle hook?

A lifecycle hook is a tool that is used to manage the lifecycles of Elastic Compute Service (ECS) instances or elastic container instances in a scaling group. When Auto Scaling executes a scaling activity, a lifecycle hook can be triggered to put ECS instances or elastic container instances involved in the scaling activity into the Pending Add or Pending Remove state. You can perform custom operations on the ECS instances or elastic container instances until the lifecycle hook times out.

The following table describes the configuration items of a lifecycle hook.

Note

For information about the features of lifecycle hooks, see the "Create lifecycle hooks" section of the "Manage lifecycle hooks" topic.

Configuration item

Description

Scaling Activity

The type of scaling activities to which you want to apply the lifecycle hook. When scaling activities of the specified type occur, the lifecycle hook is triggered and the ECS instances or elastic container instances enter the Pending Add or Pending Remove state.

Valid values: Scale-in Event and Scale-out Event. Examples:

  • If you set the Scaling Activity parameter to Scale-out Event, the lifecycle hook takes effect only on ECS instances or elastic container instances that are involved in scale-outs. In other words, ECS instances or elastic container instances that are involved in scale-outs enter the Pending Add state.

  • If you set the Scaling Activity parameter to Scale-in Event, the lifecycle hook takes effect only on ECS instances or elastic container instances that are involved in scale-ins. In other words, ECS instances or elastic container instances that are involved in scale-ins enter the Pending Remove state.

Timeout Period

The period of time during which you can perform custom operations on ECS instances or elastic container instances when the instances enter the Pending Add or Pending Remove state.

We recommend that you configure a timeout period based on your business requirements. After the timeout period expires, Auto Scaling executes the default execution policy. You can delete the lifecycle hook or call the CompleteLifecycleAction API operation to manually end the timeout period ahead of schedule.

Default Execution Policy

The action that you want Auto Scaling to perform after the timeout period of the lifecycle hook ends. Valid values: Continue and Reject.

  • If you set the Default Execution Policy parameter to Continue, Auto Scaling continues adding ECS instances or elastic container instances to the scaling group during scale-outs or stopping ECS instances or elastic container instances from providing computing power in the scaling group during scale-ins.

  • If you set the Default Execution Policy parameter to Reject, Auto Scaling releases ECS instances or elastic container instances during scale-outs or continues stopping ECS instances or elastic container instances from providing computing power in the scaling group during scale-ins.

Note

If you set the Send Notification When Lifecycle Hook Takes Effect parameter of a lifecycle hook to OOS Template, the CloudOps Orchestration Service (OOS) template must be executed before the lifecycle hook times out. The default execution policy varies based on the execution result of the OOS template. If the execution is successful, the scaling activity continues. If the execution fails, the scale-out is rolled back while the scale-in continues.

Send Notification When Lifecycle Hook Takes Effect

The method to send notifications when the lifecycle hook takes effect.

For example, you can set this parameter to MNS Topic or MNS Queue. This way, you can immediately receive notifications after the lifecycle hook is triggered and perform operations on the instances. You can also set this parameter to OOS Template to automatically execute tasks.

Note

You are charged for the use of MNS. For more information, see MNS pricing.

Workflows

The following figures use ECS instances to describe the workflows of lifecycle hooks. The workflows are similar for lifecycle hooks that are applied to elastic container instances.

Figure 1 Scale-out flowchart 流程图

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

The following table describes the concepts that are displayed in the preceding figures.

Concept

Description

Lifecycle hook

A tool that is used to manage the lifecycles of ECS instances or elastic container instances in a scaling group. For more information, see What is a lifecycle hook?

You use the scaling group to manage the lifecycles of the instances

You use the scaling group to manage the lifecycles of ECS instances or elastic container instances. For information about the lifecycles of ECS instances or elastic container instances, see Instance lifecycle. The status of ECS instances or elastic container instances varies based on how the instances are created.

  • If you use the scaling group to manage the lifecycles of ECS instances or elastic container instances that are automatically created, Auto Scaling creates ECS instances or elastic container instances during scale-outs and stops and releases the ECS instances or elastic container instances during scale-ins.

  • If you use the scaling group to manage the lifecycles of the ECS instances or elastic container instances that are manually added, Auto Scaling stops and releases the ECS instances or elastic container instances during scale-ins.

You manually manage the lifecycles of the instances

You do not use the scaling group to manage the lifecycles of the ECS instances or elastic container instances that are manually added to the scaling group. In this case, Auto Scaling only removes ECS instances or elastic container instances from the scaling group during scale-ins. The ECS instances or elastic container instances are not released.

Note

You cannot use the scaling group to manage the lifecycles of subscription ECS instances that are added to the scaling group.

Scenarios

In the following scenarios, you can create lifecycle hooks to put ECS instances or elastic container instances into the Pending Add or Pending Remove state and perform operations on the instances before the timeout periods end:

  • The ECS instances or elastic container instances that are used for scale-outs cannot immediately provide services.

    For example, you can create lifecycle hooks if the ECS instances need to be associated with ApsaraDB RDS instances or need to be bound to secondary elastic network interfaces (ENIs). You can also create lifecycle hooks if the applications that are deployed on the ECS instances require some time to start before the applications can provide services.

  • The ECS instances or elastic container instances that are used for scale-ins cannot be immediately removed from scaling groups.

    For example, you can create lifecycle hooks when you must back up data on the ECS instances or elastic container instances, copy instance logs, or wait until the ECS instances or elastic container instances finish processing all requests before you remove the instances from the scaling groups.

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

Limits

  • You can create up to 10 lifecycle hooks for each scaling group.

  • When a scaling activity is triggered in a scaling group, whether the Expected Number of Instances feature is enabled determines whether other scaling activities can be executed on the scaling group.

    • If the Expected Number of Instances feature is disabled for the scaling group, Auto Scaling rejects other scaling activities.

    • If the Expected Number of Instances feature is enabled for the scaling group, Auto Scaling can execute other scaling activities only if the ongoing scaling activity is a parallel scaling activity. For information about how to determine parallel scaling activities, see Terms.

Manage lifecycle hooks

The following table describes the operations that you can perform on lifecycle hooks and the related links.

User guide

Operation

API references

Manage lifecycle hooks

Create lifecycle hooks

CreateLifecycleHook

Modify lifecycle hooks

ModifyLifecycleHook

Delete lifecycle hooks

DeleteLifecycleHook