Lifecycle hooks can be used to suspend scaling activities that are triggered by Auto Scaling and put Elastic Compute Service (ECS) instances into the wait state. This provides a period of time for you to perform custom operations until the lifecycle hooks time out. This topic describes how to create a lifecycle hook.

Prerequisites

  • A scaling group is created. For more information, see Create a scaling group.
  • Optional:A Message Service (MNS) topic or queue is created if you want to send MNS notifications when lifecycle hooks are triggered. For more information, see Create a topic or Create a queue.

Background information

A maximum of six lifecycle hooks can be created for each scaling group.

Procedure

  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 a region.
  4. Find the scaling group and use one of the following methods to open the details page of the scaling group:
    • Click the ID of the scaling group in the Scaling Group Name/ID column.
    • In the Actions column corresponding to the scaling group, click Details.
  5. In the upper part of the page, click the Lifecycle Hook tab.
  6. In the upper-left corner of the Lifecycle Hook page, click Create Lifecycle Hook.
  7. Configure parameters for the lifecycle hook.
    The following table describes the parameters of a lifecycle hook.
    Parameter Description
    Parameter The name cannot be modified after the lifecycle hook is created. The name must be 2 to 64 characters in length, and can contain letters, digits, periods (.), underscores (_), and hyphens (-). It must start with a letter or a digit.
    Applicable Scaling Activity Type When scaling activities of the specified type occur, the lifecycle hook is triggered to put corresponding ECS instances into the wait state. Valid values:
    • Scale-in Event
    • Scale-out Event
    Timeout period During the timeout period, corresponding ECS instances remains in the wait state. The value must be an integer from 30 to 21600. Unit: seconds.
    Execution Policy This parameter specifies the action to take after the lifecycle hook times out. Valid values:
    • Continue: For a scale-out event, Auto Scaling continues to add the created ECS instances to the scaling group. For a scale-out event, Auto Scaling continues to stop the removed ECS instances from providing computing power in a scaling group.
    • Reject: For a scale-out event, Auto Scaling releases the created ECS instances. For a scale-in event, Auto Scaling continues to stop the removed ECS instances from providing computing power in a scaling group.
      Notice
      • The action to take after a lifecycle hook times out is determined by the execution result of an Operation Orchestration Service (OOS) template only when Notification Method is set to OOS Template for the lifecycle hook.
        • If the execution is successful, Auto Scaling continues to add the created ECS instances to the scaling group for a scale-out event. For a scale-out event, Auto Scaling continues to stop the removed ECS instances from providing computing power in the scaling group.
        • If the execution fails, Auto Scaling releases the created ECS instances for a scale-out event. For a scale-in event, Auto Scaling continues to stop the removed ECS instances from providing computing power in the scaling group.
      • The following circumstances apply when Auto Scaling stops ECS instances from providing computing power in a scaling group:
        • If the Instance Reclaim Mode parameter of a scaling group is set to Release Mode and ECS instances are automatically created or if the Instance Reclaim Mode parameter of a scaling group is set to Release Mode and ECS instances are manually created and managed by the scaling group, then the ECS instances are removed from the scaling group.
        • If the Instance Reclaim Mode parameter of a scaling group is set to Shutdown and Reclaim Mode and ECS instances are automatically created or if the Instance Reclaim Mode parameter of a scaling group is set to Shutdown and Reclaim Mode and ECS instances are manually created and managed by the scaling group, then the ECS instances are stopped in the scaling group and some resources of the instances are retained. For more information, see Create a scaling group.
        • If ECS instances are manually created and not managed by a scaling group, the ECS instances are only removed from the scaling group and can still run normally.
    Notification Method When the lifecycle hook is triggered, Auto Scaling sends a notification or performs operations based on the specified notification method. Valid values:
    • No Notification: This is the default value.
    • MNS Topic: If you set the parameter to this value, you must select an MNS topic.
    • MNS Queue: If you set the parameter to this value, you must select an MNS queue.
    • OOS Template: If you set the parameter to this value, you must select an OOS template.

    You can specify a notification ID if you set the notification method to MNS Topic or MNS Queue. The notification ID is sent along with notifications to the MNS topic or MNS queue so that you can manage the notifications by ID.

  8. Click OK.

Result

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

When Auto Scaling triggers a scaling activity that is applicable to the lifecycle hook, the corresponding ECS instance is put into the wait state. You can view the status of the ECS instance on the Instances tab of the scaling group details page, as shown in the following figure. During the timeout period of the lifecycle hook, you can log on to the ECS instance to install applications or perform custom operations.

Scale-out event