Creates lifecycle hooks.
Usage notes
- You can create up to six lifecycle hooks for each scaling group. Elastic Compute Service (ECS) instances are not immediately added to or removed from scaling groups that have effective lifecycle hooks during scaling activities. The instances are added to or removed from the scaling groups only after the lifecycle hooks time out. The timeout period of a lifecycle hook is specified by HeartbeatTimeout. Before lifecycle hooks time out, you can initialize the configurations of ECS instances and query data on the instances.
- For scale-outs, the private IP addresses of ECS instances are added to the IP address whitelists of the associated ApsaraDB RDS instances and the ECS instances are added to the backend server groups of the associated Server Load Balancer (SLB) instances only after the lifecycle hooks time out. For scale-ins, the private IP addresses of ECS instances are removed from the IP address whitelists of the associated ApsaraDB RDS instances and the ECS instances are removed from the backend server groups of the associated SLB instances only after the lifecycle hooks time out.
- You can specify a notification method for a lifecycle hook. When the lifecycle hook takes effect, a notification can be sent by using a Message Service (MNS) topic, an MNS queue, or an Operation Orchestration Service (OOS) template. If you want to configure an OOS template, you must create a Resource Access Management (RAM) role for OOS. For more information, see Grant RAM permissions to OOS.
Debugging
Request parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
Action | String | Yes | CreateLifecycleHook | The operation that you want to perform. Set the value to CreateLifecycleHook. |
ScalingGroupId | String | Yes | asg-bp1eyv4qn8ssgv43**** | The ID of the scaling group. |
LifecycleHookName | String | No | lifecyclehook**** | The name of the lifecycle hook. Each lifecycle hook name must be unique in a scaling group. The name must be 2 to 64 characters in length and can contain letters, digits, underscores (_), hyphens (-), and periods (.). The name must start with a letter or a digit. If you do not specify this parameter, the value of LifecycleHookId is used. |
LifecycleTransition | String | Yes | SCALE_OUT | The type of scaling activity to which you want to apply the lifecycle hook. Valid values:
|
DefaultResult | String | No | CONTINUE | The action that Auto Scaling performs after the lifecycle hook times out. Valid values:
If a scaling group has multiple lifecycle hooks in effect and you set Default value: CONTINUE. |
HeartbeatTimeout | Integer | No | 600 | The timeout period of the lifecycle hook. When the lifecycle hook times out, Auto Scaling performs the action that is specified by DefaultResult. Valid values: 30 to 21600. Unit: seconds. Note After you create a lifecycle hook, you can call the RecordLifecycleActionHeartbeat operation to extend the timeout period of the lifecycle hook. You can also call the CompleteLifecycleAction operation to end the timeout period ahead of schedule. Default value: 600. |
NotificationMetadata | String | No | Test lifecycle hook. | The fixed string that is included in a notification that Auto Scaling sends when the lifecycle hook takes effect. Auto Scaling sends the value of If you use For example, your OOS template includes the following parameters:
|
NotificationArn | String | No | acs:mns:cn-beijing:161456884340****:queue/modifyLifecycleHo**** | The Alibaba Cloud Resource Name (ARN) of the notification method. If you do not specify this parameter, no notification is sent when the lifecycle hook takes effect. If you specify this parameter, the following rules apply:
The variables in the preceding value formats have the following meanings:
|
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
RequestId | String | 473469C7-AA6F-4DC5-B3DB-A3DC0DE3**** | The ID of the request. |
LifecycleHookId | String | ash-bp1at9ufhmcf9cmy**** | The ID of the lifecycle hook. |
Examples
Sample requests
http(s)://ess.aliyuncs.com/?Action=CreateLifecycleHook
&ScalingGroupId=asg-bp1eyv4qn8ssgv43****
&LifecycleHookName=lifecyclehook****
&LifecycleTransition=SCALE_OUT
&DefaultResult=CONTINUE
&HeartbeatTimeout=600
&NotificationMetadata=Test lifecycle hook.
&NotificationArn=acs:mns:cn-beijing:161456884340****:queue/modifyLifecycleHo****
&<Common request parameters>
Sample success responses
XML
format
HTTP/1.1 200 OK
Content-Type:application/xml
<CreateLifecycleHookResponse>
<RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3****</RequestId>
<LifecycleHookId>ash-bp1at9ufhmcf9cmy****</LifecycleHookId>
</CreateLifecycleHookResponse>
JSON
format
HTTP/1.1 200 OK
Content-Type:application/json
{
"RequestId" : "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****",
"LifecycleHookId" : "ash-bp1at9ufhmcf9cmy****"
}
HTTP status code
For a list of error codes, see Service error codes.
HTTP status code | Error code | Error message | Description |
---|---|---|---|
400 | InvalidParamter | The specified value of parameter is not valid. | The value of a parameter is invalid. |
400 | InvalidNotificationArn | The specified parameter notificationArn is invalid. | The value of NotificationArn is invalid. |
400 | UnsupportedNotificationType.CurrentRegion | The notificationType is not supported in the special region which scalingGroup belongs to. | The notification type is not supported in the region where the scaling group resides. |
400 | QueueNotExist | The specified queue does not exist. | The MNS queue does not exist. |
400 | TopicNotExist | The specified topic does not exist. | The MNS topic does not exist. |
400 | InvalidLifecycleHookName.Duplicate | The specified value of parameter lifecycleHookName is duplicated. | The name of the lifecycle hook already exists. |
400 | QuotaExceeded.LifecycleHook | Lifecycle hook quota exceeded in the specified scaling group. | The maximum number of lifecycle hooks that you can create has been reached. |