Creates one or more lifecycle hooks for a scaling group.
Operation description
Operation description
-
You can create up to six lifecycle hooks for a scaling group. When a scaling activity occurs in a scaling group that has lifecycle hooks, the lifecycle hooks pause the scaling activity for a period of time. You can specify the wait time by using the HeartbeatTimeout parameter. During the wait time, you can perform operations such as initializing ECS instance configurations and obtaining ECS instance data.
-
During a scale-out activity, ECS instances enter the wait state after they are added to the whitelist of an ApsaraDB RDS instance. After the wait state ends, the ECS instances are added to the backend server group of a Server Load Balancer (SLB) instance. During a scale-in activity, ECS instances enter the wait state after they are removed from the backend server group of an SLB instance. After the wait state ends, the ECS instances are removed from the whitelist of the ApsaraDB RDS instance.
-
You can configure a notification method for a lifecycle hook. Supported notification methods include Message Service (MNS) topics, MNS queues, and Operation Orchestration Service (OOS) templates. If you configure an OOS template, you must create a Resource Access Management (RAM) role for OOS. For more information, see Grant RAM permissions to OOS.
If the scaling group contains existing ECS instances and the configured OOS template is used to add the instances to or remove the instances from the whitelist of a cloud database other than ApsaraDB RDS, you must manually add the existing ECS instances to the whitelist of the cloud database.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
ess:CreateLifecycleHook |
create |
*ScalingGroup
|
None | None |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| ScalingGroupId |
string |
Yes |
The ID of the scaling group. |
asg-bp1eyv4qn8ssgv43**** |
| LifecycleHookName |
string |
No |
The name of the lifecycle hook. The name must be unique among all lifecycle hooks in the current scaling group. It must be 2 to 64 characters in length, start with a digit, a letter, or a Chinese character, and can contain digits, underscores (_), hyphens (-), and periods (.). Default value: the value of LifecycleHookId. |
lifecyclehook**** |
| LifecycleTransition |
string |
Yes |
The type of scaling activity to which the lifecycle hook applies. Valid values:
|
SCALE_OUT |
| DefaultResult |
string |
No |
The action to be performed after the wait state ends. Valid values:
When a scale-in activity (SCALE_IN) occurs in the scaling group and multiple lifecycle hooks are triggered, if the Default value: CONTINUE. |
CONTINUE |
| HeartbeatTimeout |
integer |
No |
The wait time set by the lifecycle hook for the scaling activity. After the wait state times out, the next action is performed. Valid values: 30 to 21600. Unit: seconds. After you create a lifecycle hook, you can call RecordLifecycleActionHeartbeat to extend the wait time of ECS instances, or call CompleteLifecycleAction to end the wait state of the scaling activity in advance. Default value: 600. |
600 |
| NotificationMetadata |
string |
No |
The notification message that is pushed to the NotificationArn (notification recipient) when the lifecycle hook pauses the scaling activity. This parameter is used to manage and mark different types of notification messages. You must specify NotificationArn together with this parameter. The value can be up to 4,096 characters in length. If NotificationArn is set to an OOS template, including a public template or a custom template, NotificationMetadata must be set to a JSON string that matches the parameters of the OOS template. For example, {"dbInstanceId": "dds-bp17661e0135****", "modifyMode": "Append"}. dbInstanceId and modifyMode are parameters defined in the OOS template. Some parameters of the OOS template have default values. You must specify the parameters that do not have default values in NotificationMetadata. If you specify a parameter that has a default value, the original default value is overwritten. However, keep the default values for the following parameters to obtain relevant information when the scaling activity is running:
Note
|
Test lifecycle hook. |
| NotificationArn |
string |
No |
The identifier of the notification recipient for the lifecycle hook. If you do not specify this parameter, no notifications are sent. If you specify this parameter, the following notification methods are supported:
The variables in the formats have the following meanings:
|
acs:mns:cn-beijing:161456884340****:queue/modifyLifecycleHo**** |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
|||
| LifecycleHookId |
string |
The ID of the lifecycle hook. |
ash-bp1at9ufhmcf9cmy**** |
| RequestId |
string |
The ID of the request. |
473469C7-AA6F-4DC5-B3DB-A3DC0DE3**** |
Examples
Success response
JSON format
{
"LifecycleHookId": "ash-bp1at9ufhmcf9cmy****",
"RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****"
}
Error codes
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.