Lifecycle hooks enable you to flexibly control creation and removal of ECS instances in AS groups and manage the lifecycle of ECS instances in AS groups. Figure 1 shows the instance lifecycle when no lifecycle hook is added to the AS group.
Figure 2 shows the instance lifecycle when a lifecycle hook is added to the AS group.
When the AS group performs a scaling action and triggers the lifecycle hook, the scaling action is suspended and the instance that is being added to or removed from the AS group is set to waiting state, as shown in 2 and 6 in Figure 2. During this period, you can perform some custom operations on the instance. For example, you can install or configure software on an instance to be added to the AS group. The suspension of a scaling action will be ended in either of the following scenarios:
After added to an AS group, a lifecycle hook works as follows:
After an instance is added to an AS group and initialized, a lifecycle hook of the Instance adding type is automatically triggered. The instance enters the Wait (Adding to AS group) state, that is, the instance is suspended by the lifecycle hook. If you have configured a notification object, the system sends a message to the object. After receiving the message, you can perform custom operations, for example, installing software on the instance. After finishing the custom operations, you can perform a callback operation to end the instance waiting state. Alternatively, you can wait until the timeout duration ends, when the system automatically ends the instance waiting state. After the instance waiting state ends, two types of Default Callback Action are available, Continue and Abandon.
If you have configured multiple Instance adding lifecycle hooks, all of them will be triggered when an instance is added to the AS group. If the Default Callback Action of one lifecycle hook is Abandon, the instance will be deleted and a new instance will be created. If the Default Callback Action of all lifecycle hooks is Continue, the instance is added to the AS group after suspension by the last lifecycle hook is complete.
When an instance is removed from an AS group, the instance enters the Removing from AS group state. After a lifecycle hook is triggered, the instance enters the Wait (Removing from AS group) state. The system sends messages to the configured notification object. After receiving the message, you can perform custom operations, such as uninstalling software and backing up data. After finishing the custom operations, you can perform the default callback operation or wait for the system to end the instance waiting state when the timeout duration expires. After the instance waiting state ends, two types of Default Callback Action are available, Continue and Abandon.
If there are multiple lifecycle hooks, Continue allows suspension by other lifecycle hooks to time out. The instance will be removed from the AS group only when the status of all lifecycle hooks is Continue. If the Default Callback Action of any lifecycle hook is Abandon, the instance will be directly removed from the AS group.
Parameter |
Description |
Example Value |
---|---|---|
Hook Name |
Specifies the lifecycle hook name. The name is a string of 1 and 32 characters and can contain letters, digits, underscores (_), and hyphens (-). |
we12_w |
Hook Type |
Specifies the lifecycle hook type. The value can be Instance adding or Instance removal. Instance adding sets an instance that is being added to an AS group to Wait (Adding to AS group) state. Instance removal sets an instance that is being removed from an AS group Wait (Removing from AS group) state. |
Instance adding |
Default Callback Action |
Specifies the default system action when the waiting duration of an instance expires.
When an instance is being added to an AS group, the default callback action can be
Continue or
Abandon:
When an instance is being removed from an AS group, the default callback action can be
Continue or
Abandon:
|
Continue |
Timeout (s) |
Specifies the instance waiting duration by default. Value range: 300s to 86400s You can prolong the timeout duration or perform the Continue or Abandon operation before the timeout duration expires. For more information about callback actions, see Perform a Callback Action. |
3600 |
Notification Topic |
Specifies a notification object for a lifecycle hook. For details, see section "Configuring a Topic Policy" in Simple Message Notification User Guide. After the configuration, when an instance is suspended by the lifecycle hook, the system sends a notification to the object. This notification contains the basic instance information, your customized notification content, and the token for controlling lifecycle operations. An example notification is as follows: { "service": "AutoScaling", "tenant_id": "93075aa73f6a4fc0a3209490cc57181a", "lifecycle_hook_type": "INSTANCE_LAUNCHING", "lifecycle_hook_name": "test02", "lifecycle_action_key": "4c76c562-9688-45c6-b685-7fd732df310a", "notification_metadata": "xxxxxxxxxxxxx", "scaling_instance": { "instance_id": "89b421e4-5fa6-4733-bf40-6b07a8657256", "instance_name": "as-config-kxeg_RM6OCREY", "instance_ip": "192.168.0.202" }, "scaling_group": { "scaling_group_id": "fe376277-50a6-4e36-bdb0-685da85f1a82", "scaling_group_name": "as-group-wyz01", "scaling_config_id": "16ca8027-b6cc-45fc-af2d-5a79996f685d", "scaling_config_name": "as-config-kxeg" } } |
N/A |
Notification Message |
After a notification object is configured, the system sends your customized notification to the object. |
N/A |
The added lifecycle hook is displayed on the Lifecycle Hooks page.
Callback operations can only be performed on instances that have been suspended by a lifecycle hook.
Callback actions include:
If you have performed customized operations before the timeout duration expires, select Continue or Abandon to complete the lifecycle operations. For details about Continue and Abandon, see Table 1. If you require more time for customizing operations, select Extend timeout to prolong the timeout duration. Then, the instance waiting duration will be prolonged by 3600 sections each time.
On the Lifecycle Hooks page, locate the target lifecycle hook and click Modify in the Operation column. You can modify the parameter except Hook Name, such as Hook Type, Default Callback Action, and Timeout Duration.
On the Lifecycle Hooks page, locate the target lifecycle hook and click Delete in the Operation column.