Lifecycle hooks pause Auto Scaling activities and place ECS or ECI instances into a pending state, giving you time to perform custom actions such as installing software. The scaling activity resumes after the hook times out.
Prerequisites
-
A scaling group has been created. For more information, see Configure a scaling group or CreateScalingGroup.
-
(Optional) If you want to receive MNS notifications when a lifecycle hook is triggered, you must create an MNS topic or MNS queue in advance. For more information, see the following topics:
Create a lifecycle hook
You can create up to 10 lifecycle hooks per scaling group. For more information, see Overview of lifecycle hooks.
Log on to the Auto Scaling console.
In the navigation pane on the left, click Scaling Groups.
In the top navigation bar, select a region.
Find the scaling group that you want to manage and open its details page in one of the following ways:
In the Scaling Group Name/ID column, click the ID of the scaling group.
In the Actions column, click Details.
At the top of the page, click the Event and adhesive hook tab.
-
Click Create Lifecycle Hook.
-
On the Create Lifecycle Hook page, configure the lifecycle hook.
The following table describes the parameters of a lifecycle hook.
Parameter
Description
Name
The name of the lifecycle hook. The name cannot be changed after creation, must be 2 to 64 characters long, and must start with a letter, digit, or Chinese character. It can contain periods (.), underscores (_), and hyphens (-).
Scaling Activity Type
The type of scaling activity that triggers the lifecycle hook. Valid values:
-
Scale-In
-
Scale-Out
Timeout Period
The timeout period of the lifecycle hook, in seconds. Valid values: 30 to 21600 (6 hours). Default value: 1800.
NoteSet the timeout period based on how long it takes to process the lifecycle hook. If processing exceeds the timeout, the system performs the action specified for Default Execution Policy.
Default Execution Policy
Scenario with a single lifecycle hook
The action to perform after an instance exits the pending state. Valid values:
-
Continue: During a scale-out activity, Auto Scaling continues to add the newly created ECS or ECI instance to the scaling group. During a scale-in activity, Auto Scaling continues to remove the ECS or ECI instance from the scaling group and then releases it.
-
Reject: During a scale-out activity, Auto Scaling releases the newly created ECS or ECI instance without adding it to the scaling group. During a scale-in activity, Auto Scaling detaches the ECS or ECI instance from the scaling group but does not release it.
-
Roll Back: During a scale-out activity, Auto Scaling releases the newly created ECS or ECI instance without adding it to the scaling group. During a scale-in activity, Auto Scaling adds the removed ECS or ECI instance back to the scaling group.
Scenario with multiple lifecycle hooks
If multiple lifecycle hooks are triggered for the same scaling activity, the final outcome depends on the Scaling Activity Type set for each hook.
-
Scale-in activity: When the wait state for a lifecycle hook with a Continue policy ends, the system waits for the remaining lifecycle hooks to complete. If any of these hooks finishes with an execution policy of Reject or Roll Back, the system immediately ends the wait state and sets the policy for any unfinished hooks to the default execution policy. A rollback is initiated to stop the scale-in activity only if a completed hook has the Roll Back policy. If a completed hook has the Reject policy, the scale-in activity continues.
-
Scale-out activity: The scale-out activity proceeds only if all lifecycle hooks complete with an execution policy of Continue. If any lifecycle hook completes with an execution policy of Reject or Roll Back, the system stops waiting for the remaining incomplete hooks, cancels the scale-out, and initiates a rollback (for scale-out activities, the "Rollback" and "Reject" policies have the same effect).
(Optional) Scenario with an OOS template as the notification method
This applies only when the lifecycle hook uses an OOS template as the notification method. If the OOS template execution finishes before the pending state times out, the next action depends on the execution result:
-
Success: For a scale-out activity, the instance is added to the scaling group. For a scale-in activity, the instance stops serving traffic in the scaling group.
-
Failure: For a scale-out activity, the instance is released. For a scale-in activity, the instance stops serving traffic in the scaling group.
How an instance stops serving traffic depends on the following conditions:
-
If the instance is managed by the scaling group, and the group's Instance Reclaim Mode is set to Release, the instance is removed from the scaling group and released.
-
If the instance is managed by the scaling group, and the group's Instance Reclaim Mode is set to Economical Mode, the instance is stopped within the group, and some of its resources are retained. For more information, see Configure a scaling group.
-
If the instance was manually added to but not managed by the scaling group, it is only removed from the group and continues to run.
Send Notification When Lifecycle Hook Takes Effect
The method used to send notifications or perform actions when a lifecycle hook is triggered. Valid values:
-
No Notification: This is the default option.
-
MNS Topic: Select an MNS topic. You can specify a notification identifier that Auto Scaling includes in each message to help you categorize notifications.
-
MNS Queue: Select an MNS queue. You can specify a notification identifier that Auto Scaling includes in each message to help you categorize notifications.
-
OOS Template: Select the type of template to execute and configure its parameters.
-
Template types include Public Templates and My Templates. Auto Scaling uses the selected template to perform custom actions on instances.
Note-
To use My Templates, you must first create your own templates. For more information, see Create a template.
-
For more information about public templates, see Public templates.
-
-
Configure the parameters based on your business requirements. If you need to set the OOS RAM role, note the following:
-
The RAM role must be assumable by OOS. The trusted entity must be an Alibaba Cloud Service, and the trusted service must be OOS. For more information, see Procedure.
-
The RAM role must have permissions to manage ECS, ECI, and Auto Scaling resources. To obtain the required policy, click View Authorization Policy. For more information about granting permissions to a RAM role, see Create and authorize a RAM role for OOS.
NoteFor more examples of how to configure template parameters, see Overview of best practices for lifecycle hooks and OOS templates.
-
-
-
Event Bus: After you select an EventBridge event bus, the system generates different types of lifecycle notifications when a scaling activity occurs in the scaling group. You can identify and handle the events based on the notifications.
-
-
Click OK.
After the lifecycle hook is created, you can view it on the Lifecycle Hook tab of the scaling group details page.
If Auto Scaling triggers a scaling activity that is applicable to the lifecycle hook, the state of the affected ECS or ECI instance changes to Pending.
Modify or delete a lifecycle hook
You can modify or delete a lifecycle hook as your business needs change.
Log on to the Auto Scaling console.
In the navigation pane on the left, click Scaling Groups.
In the top navigation bar, select a region.
-
On the Scaling Groups page, find the scaling group that you want to manage and click View Details in the Actions column.
-
On the scaling group details page, click the Event and adhesive hook tab, and then go to the Lifecycle Hook section.
-
Modify or delete the lifecycle hook.
Modify a lifecycle hook
You can modify a lifecycle hook's properties instead of recreating it.
-
Find the lifecycle hook that you want to manage and click Edit in the Actions column.
-
Modify the configuration of the lifecycle hook and click OK.
You cannot modify the name of a lifecycle hook. For descriptions of the other parameters, see Step 7 in the "Create a lifecycle hook" section.
Delete a lifecycle hook
Delete a lifecycle hook to free up the hook quota. You can delete a hook even while it is pausing a scaling activity.
ImportantIf you delete a lifecycle hook while it has an instance in a pending state, the pending state for that instance ends immediately.
-
Find one or more lifecycle hooks that you want to delete and then delete them.
-
To delete a single hook: In the Actions column for the hook, click Delete.
-
To delete multiple hooks: Select the hooks that you want to delete and click Delete at the bottom of the lifecycle hook list.
-
-
In the message that appears, click OK.
-
Disable or enable a lifecycle hook
After a lifecycle hook is created, it is in the Active state by default. You can disable or enable a lifecycle hook as needed.
Log on to the Auto Scaling console.
In the navigation pane on the left, click Scaling Groups.
In the top navigation bar, select a region.
-
On the Scaling Groups page, find the scaling group that you want to manage and click View Details in the Actions column.
-
On the scaling group details page, click the Event and adhesive hook tab, and then go to the Lifecycle Hook section.
-
Disable or enable the lifecycle hook.
Disable a lifecycle hook
Disable a lifecycle hook that is temporarily not needed.
-
Find the lifecycle hook that you want to manage and click Pause in the Actions column.
-
In the message that appears, click OK.
Enable a lifecycle hook
Enable a disabled lifecycle hook when you need it again.
-
Find the lifecycle hook that you want to manage and click Enable in the Actions column.
-
In the message that appears, click OK.
-
References
-
CreateLifecycleHook: Creates a lifecycle hook.
-
ModifyLifecycleHook: Modifies a lifecycle hook.
-
DeleteLifecycleHook: Deletes a lifecycle hook.
-
CompleteLifecycleAction: Ends the pending state for a lifecycle action before the timeout period expires.