All Products
Search
Document Center

Auto Scaling:Manage lifecycle hooks

Last Updated:Apr 01, 2024

The lifecycle hook feature can pause automatically triggered scaling activities to put Elastic Compute Service (ECS) instances or elastic container instances into the Pending state. This gives you a period of time to perform custom operations on the instances. For example, you can preinstall software on instances that are in the Pending state. You can resume scaling activities that are paused by lifecycle hooks only after the lifecycle hooks time out. This topic describes how to create, modify, delete, enable, and disable a lifecycle hook.

Prerequisites

Create a lifecycle hook

The lifecycle hook feature serves as an instance lifecycle management tool. For more information, see Overview. You can create up to 10 lifecycle hooks in a scaling group. In this example, only one lifecycle hook is created for your reference.

  1. Log on to the Auto Scaling console.

  2. In the left-side navigation pane, click Scaling Groups.

  3. In the top navigation bar, select the region where Auto Scaling is activated.

  4. Find a scaling group and use one of the following methods to go to the scaling group details page:

    • Click the ID of the scaling group in the Scaling Group Name/ID column.

    • Click Details in the Actions column.

  5. In the upper part of the scaling group details page, click the Lifecycle Hook tab.

  6. In the upper-left corner of the page that appears, click Create Lifecycle Hook.

  7. In the Create Lifecycle Hook dialog box, configure parameters as prompted.

    The following table describes the parameters.

    Parameter

    Description

    Name

    The name of the lifecycle hook. You cannot change the name of a lifecycle hook after you create the lifecycle hook. The name must be 2 to 64 characters in length and can contain letters, digits, periods (.), underscores (_), and hyphens (-). The name must start with a letter or a digit.

    Scaling Activity

    The type of scaling activity to which you want to apply the lifecycle hook. When a scaling activity of the specified type occurs, the lifecycle hook is triggered to put the ECS instances or elastic container instances that you want to add to or remove from your scaling group into the Pending state. Valid values:

    • Scale-in Event

    • Scale-out Event

    Timeout Period

    The timeout period of the lifecycle hook. The value of this parameter must be an integer that ranges from 30 to 21600. Unit: seconds. Default value: 1800.

    Note

    We recommend that you specify a timeout period based on your business requirements. If the timeout period is shorter than the required period of time, Auto Scaling executes the default execution policy.

    Default Execution Policy

    Scenario 1: Only one lifecycle hook is created

    The action that you want Auto Scaling to perform after the lifecycle hook times out. Valid values:

    • Continue: Auto Scaling continues to add ECS instances or elastic container instances to your scaling group during scale-outs or continues to remove ECS instances or elastic container instances from your scaling group and then releases the ECS instances or elastic container instances during scale-ins.

    • Reject: Auto Scaling releases ECS instances or elastic container instances that are in the Pending state during scale-outs or continues to remove ECS instances or elastic container instances from your scaling group and then releases the ECS instances or elastic container instances during scale-ins.

    • Roll Back: Auto Scaling releases ECS instances or elastic container instances that are in the Pending state during scale-outs or re-adds ECS instance or elastic container instances that are in the Pending state to your scaling group during scale-ins.

    Scenario 2: Multiple lifecycle hooks are created

    If you have multiple lifecycle hooks, the subsequent action that Auto Scaling performs varies based on the value of the Scaling Activity parameter that you specify for each lifecycle hook.

    • If you create multiple lifecycle hooks whose Default Execution Policy parameter is set to Reject for scale-ins, Auto Scaling removes ECS instances or elastic container instances from your scaling group and then releases the ECS instances or elastic container instances when one of the lifecycle hook times out. In this case, other lifecycle hooks time out ahead of schedule.

      For example, you set the Timeout Period parameter of Lifecycle Hook A whose Default Execution Policy parameter is set to Reject to 600 seconds and set the Timeout Period parameter of Lifecycle Hook B to 1,200 seconds. When Lifecycle Hook A times out during a scale-in, Lifecycle Hook B times out 600 seconds earlier.

    • If you create multiple lifecycle hooks whose Default Execution Policy parameter is set to Continue for scale-ins, Auto Scaling must wait until all lifecycle hooks time out before removing ECS instances or elastic container instances from your scaling group and then releasing the ECS instances or elastic container instances.

    • If you create multiple lifecycle hooks for scale-outs, Auto Scaling must wait until all lifecycle hooks time out to perform the subsequent action, regardless of the value of the Default Execution Policy parameter that you specify for each lifecycle hook.

    (Optional) Scenario 3: An OOS template is used

    If you set the Send Notification When Lifecycle Hook Takes Effect parameter to OOS Template for a lifecycle hook, the subsequent action that Auto Scaling performs after the lifecycle hook times out varies based on the execution result of the CloudOps Orchestration Service (OOS) template.

    • If the execution of the OOS template is successful, Auto Scaling continues to add ECS instances or elastic container instances to your scaling group during scale-outs or stops ECS instances or elastic container instances from providing computing power during scale-ins.

    • If the execution of the OOS template fails, Auto Scaling releases ECS instances or elastic container instances that are in the Pending state during scale-outs or continues to stop ECS instances or elastic container instances from providing computing power during scale-ins.

    When Auto Scaling stops ECS instances or elastic container instances from providing computing power in a scaling group, the following rules apply:

    • If the ECS instances or elastic container instances are automatically created or the ECS instances or elastic container instances are manually created and managed by the scaling group whose Instance Reclaim Mode parameter is set to Release, Auto Scaling removes the ECS instances or elastic container instances from the scaling group.

    • If the ECS instances or elastic container instances are automatically created or the ECS instances or elastic container instances are manually created and managed by the scaling group whose Instance Reclaim Mode parameter is set to Economical Mode, Auto Scaling stops the ECS instances or elastic container instances but retains specific resources of the instances in the scaling group. For more information, see Manage scaling groups.

    • If the ECS instances or elastic container instances are manually created but not managed by the scaling group, Auto Scaling removes the ECS instances or elastic container instances from the scaling group. The removed ECS instances or elastic container instances can independently run.

    Send Notification When Lifecycle Hook Takes Effect

    Specify whether to send notifications when the lifecycle hook takes effect. If you want to send notifications when the lifecycle hook takes effect, specify a notification method. Valid values:

    • No Notification: This is the default value.

    • MNS Topic: If you select this option, you must select an MNS topic. If you specify a notification ID, the notification ID is sent together with the notification to the MNS topic. You can manage notifications by ID.

    • MNS Queue: If you select this option, you must select an MNS queue. If you specify a notification ID, the notification ID is sent together with the notification to the MNS queue. You can manage notifications by ID.

    • OOS Template: If you select this option, you must specify the template type and configure the template parameters.

      • Auto Scaling supports the following types of OOS templates: Public Templates and My Templates. Auto Scaling uses the template that you selected to perform actions on ECS instances or elastic container instances.

        Note
        • Before you can select My Templates, you must create a template. For information about how to create a template, see Create a template.

        • For information about public templates, see Public templates.

      • Configure the template parameters based on your business requirements. If you want to configure a Resource Access Management (RAM) role for OOS, the following rules apply:

        • When you create a RAM role for OOS, you must select Alibaba Cloud Service as the trusted entity and CloudOps Orchestration Service as the trusted service. For more information, see Create a RAM role for OOS.

        • You must grant the RAM role the required permissions on resources such as ECS, Elastic Container Instance, and Auto Scaling. To view the required policy, you can click View the permission policy that is required to execute the template. For information about how to attach a policy to a RAM role, see Attach the required policy to the OOS-trusted role.

          Note

          For information about how to configure template parameters, see Overview of best practices for lifecycle hooks and OOS templates.

    • Event Bus: If you select this option, Auto Scaling sends different types of lifecycle hook notifications. You can identify and handle events in a flexible manner based on the notifications.

  8. Click OK.

    After you create the lifecycle hook, you can view the lifecycle hook on the Lifecycle Hook tab of the scaling group details page.

    When a scaling activity of the specified type is triggered by Auto Scaling, the lifecycle hook takes effect and ECS instances or elastic container instances that are involved in the scaling activity enter the Pending state. The following figure shows the status of ECS instances when a lifecycle hook takes effect.加入挂起中

Modify or delete a lifecycle hook

You can modify a lifecycle hook based on your business requirements. You can also delete a lifecycle hook that you no longer require.

  1. Log on to the Auto Scaling console.

  2. In the left-side navigation pane, click Scaling Groups.

  3. In the top navigation bar, select the region where Auto Scaling is activated.

  4. On the Scaling Groups page, find the desired scaling group and click Details in the Actions column.

  5. On the scaling group details page, click the Lifecycle Hook tab.

  6. Modify or delete a lifecycle hook based on your business requirements.

    Modify a lifecycle hook

    If your lifecycle hook no longer meets your business requirements, you can modify the parameters of the lifecycle hook, without the need to create a new one.

    1. Find the lifecycle hook that you want to modify and click Modify in the Actions column.

    2. Modify the lifecycle hook based on your business requirements and click OK.

      You cannot modify the name of a lifecycle hook after you create the lifecycle hook. For information about lifecycle hook parameters, see Step 7.

    Delete a lifecycle hook

    If you no longer require a lifecycle hook, you can delete the lifecycle hook to free up the lifecycle hook quota. For example, when a scaling activity is paused by a lifecycle hook, you can delete the lifecycle hook.

    Important

    If you delete a lifecycle hook that is in effect, the ECS instances or elastic container instances to which the lifecycle hook is applied exit the Pending state ahead of schedule.

    1. Delete one or more lifecycle hooks.

      • Delete one lifecycle hook: Find the lifecycle hook that you want to delete and click Delete in the Actions column.

      • Delete multiple lifecycle hooks: Select the lifecycle hooks that you want to delete and click Delete in the lower left corner of the page.

    2. In the Delete Lifecycle Hook message, click OK.

Disable or enable a lifecycle hook

By default, a lifecycle hook immediately enters the Effective state after you create it. You can enable or disable lifecycle hooks based on your business requirements.

  1. Log on to the Auto Scaling console.

  2. In the left-side navigation pane, click Scaling Groups.

  3. In the top navigation bar, select the region where Auto Scaling is activated.

  4. On the Scaling Groups page, find the scaling group and click Details in the Actions column.

  5. On the scaling group details page, click the Lifecycle Hook tab.

  6. Disable or enable a lifecycle hook based on your business requirements.

    Disable a lifecycle hook

    If your business does not require a lifecycle hook that is in effect for now, you can disable the lifecycle hook.

    1. Find the lifecycle hook that you want to disable and click Disable in the Actions column.

    2. In the Disable Lifecycle Hook message, click OK.

    Enable a lifecycle hook

    If your business requires a lifecycle hook that is disabled, you can enable the lifecycle hook.

    1. Find the lifecycle hook that you want to enable and click Enable in the Actions column.

    2. In the Enable Lifecycle Hook message, click OK.

References

  • For information about how to create one or more lifecycle hooks by calling an API operation, see CreateLifecycleHook.

  • For information about how to modify a lifecycle hook by calling an API operation, see ModifyLifecycleHook.

  • For information about how to delete a lifecycle hook by calling an API operation, see DeleteLifecycleHook.

  • For information about how to end a lifecycle hook ahead of schedule, see CompleteLifecycleAction.