ALIYUN::ESS::LifecycleHook is used to create a lifecycle hook for a scaling group.

Syntax

{
  "Type": "ALIYUN::ESS::LifecycleHook",
  "Properties": {
    "LifecycleHookName": String,
    "NotificationArn": String,
    "HeartbeatTimeout": Integer,
    "NotificationMetadata": String,
    "ScalingGroupId": String,
    "DefaultResult": String,
    "LifecycleTransition": String
  }
}

Properties

Property Type Required Editable Description Constraint
LifecycleHookName String No Yes The name of the lifecycle hook. Each name must be unique within a scaling group.

The name must be 2 to 40 characters in length and can contain letters, digits, underscores (_), hyphens (-), and periods (.). It must start with a letter or digit.

The default value is the ID of the lifecycle hook.

NotificationArn String No Yes The Alibaba Cloud Resource Name (ARN) of the notification receiver that Auto Scaling uses to notify you when an instance is in the transition state for the lifecycle hook. This receiver can be an OOS template, MNS queue, or MNS topic. Format: acs:ess:{region}:{account-id}:{resource-relative-id}.
  • region: the region in which the scaling group is deployed.
  • account-id: the ID of the Alibaba Cloud account.

Examples:

  • MNS queue: acs:ess:{region}:{account-id}:queue/{queuename}
  • MNS topic: acs:ess:{region}:{account-id}:topic/{topicname}
  • OOS template: acs:ess:{region}:{account-id}:oos/{template_name}
HeartbeatTimeout Integer No Yes The waiting period before the lifecycle hook times out. When the lifecycle hook times out, the scaling group performs the action specified by the DefaultResult parameter. Unit: seconds. After you create a lifecycle hook, you can call the RecordLifecycleActionHeartbeat operation to extend the timeout period and keep the ECS instance in the wait state. You can also call the CompleteLifecycleAction operation to terminate the wait state of a scaling activity. Valid values: 30 to 21600.

Unit: seconds.

Default value: 600.

NotificationMetadata String No Yes The fixed string that you want to include when Auto Scaling sends a message about the wait state of a scaling activity to the notification receiver. The string can be up to 128 characters in length.

Auto Scaling sends the specified NotificationMetadata parameter value along with the notification message so that you can easily categorize your notifications. The NotificationMetadata parameter takes effect only when you specify the NotificationArn parameter.

ScalingGroupId String Yes No The ID of the scaling group. None
DefaultResult String No Yes

The action that the scaling group takes when the lifecycle hook times out.

If the scaling group has multiple lifecycle hooks and one of them is terminated when DefaultResult is set to ABANDON during a scale-in event, the remaining lifecycle hooks within the same scaling group are also terminated. Otherwise, the scaling activity proceeds normally after the wait period times out and continues with the action specified by the DefaultResult parameter.
Default value: CONTINUE. Valid values:
  • CONTINUE: The scaling group continues to respond to a scale-in or scale-out event.
  • ABANDON: The scaling group releases the created ECS instances if the scaling activity type is scale-out or removes the ECS instances to be scaled in if the scaling activity type is scale-in.
LifecycleTransition String Yes Yes The type of scaling activity to which the lifecycle hook applies. Valid values:
  • SCALE_OUT: scale-out events of the scaling group
  • SCALE_IN: scale-in events of the scaling group

Response parameters

Fn::GetAtt

LifecycleHookId: the ID of the lifecycle hook.

Examples

  • YAMLformat

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      ScalingGroupId:
        Type: String
        AssociationProperty: ALIYUN::ESS::AutoScalingGroup::AutoScalingGroupId
    Resources:
      LifecycleHook:
        Type: ALIYUN::ESS::LifecycleHook
        Properties:
          LifecycleHookName: Demo997
          NotificationArn:
            Fn::Join:
              - ''
              - - 'acs:ess:'
                - Ref: ALIYUN::Region
                - ':'
                - Ref: ALIYUN::TenantId
                - ':'
                - oos/ACS-ESS-LifeCycleRunCommand
          ScalingGroupId:
            Ref: ScalingGroupId
          LifecycleTransition: SCALE_OUT
          HeartbeatTimeout: 30
          NotificationMetadata:
            Fn::Join:
              - ''
              - - |-
                  {
                    "commandContent": "python /home/test.py",
                    "commandType": "RunShellScript"
    Outputs:
      LifecycleHookId:
        Description: The lifecycle hook ID
        Value:
          Fn::GetAtt:
            - LifecycleHook
            - LifecycleHookId
  • JSONformat

    {
      "ROSTemplateFormatVersion": "2015-09-01",
      "Parameters": {
        "ScalingGroupId": {
          "Type": "String",
          "AssociationProperty": "ALIYUN::ESS::AutoScalingGroup::AutoScalingGroupId"
        }
      },
      "Resources": {
        "LifecycleHook": {
          "Type": "ALIYUN::ESS::LifecycleHook",
          "Properties": {
            "LifecycleHookName": "Demo997",
            "NotificationArn": {
              "Fn::Join": [
                "",
                [
                  "acs:ess:",
                  {
                    "Ref": "ALIYUN::Region"
                  },
                  ":",
                  {
                    "Ref": "ALIYUN::TenantId"
                  },
                  ":",
                  "oos/ACS-ESS-LifeCycleRunCommand"
                ]
              ]
            },
            "ScalingGroupId": {
              "Ref": "ScalingGroupId"
            },
            "LifecycleTransition": "SCALE_OUT",
            "HeartbeatTimeout": 30,
            "NotificationMetadata": {
              "Fn::Join": [
                "",
                [
                  "{\n  \"commandContent\": \"python /home/test.py\",\n  \"commandType\": \"RunShellScript\""
                ]
              ]
            }
          }
        }
      },
      "Outputs": {
        "LifecycleHookId": {
          "Description": "The lifecycle hook ID",
          "Value": {
            "Fn::GetAtt": [
              "LifecycleHook",
              "LifecycleHookId"
            ]
          }
        }
      }
    }