CreateLifecycleHook

Last updated: 2020-03-16 10:38:16

1. API Description

Domain name for API request: as.tencentcloudapi.com.

This API (CreateLifeCycleHook) is used to create a lifecycle hook.

  • You can configure message notifications in the following format for lifecycle hooks, which will be sent to your CMQ queue by AS:
{
    "Service": "Tencent Cloud Auto Scaling",
    "Time": "2019-03-14T10:15:11Z",
    "AppId": "1251783334",
    "ActivityId": "asa-fznnvrja",
    "AutoScalingGroupId": "asg-rrrrtttt",
    "LifecycleHookId": "ash-xxxxyyyy",
    "LifecycleHookName": "my-hook",
    "LifecycleActionToken": "3080e1c9-0efe-4dd7-ad3b-90cd6618298f",
    "InstanceId": "ins-aaaabbbb",
    "LifecycleTransition": "INSTANCE_LAUNCHING",
    "NotificationMetadata": ""
}

A maximum of 20 requests can be initiated per second for this API.

Note: This API supports Finance regions. If the common parameter Region is a Finance region, a domain name with the Finance region needs to be specified, for example: as.ap-shanghai-fsi.tencentcloudapi.com

2. Input Parameters

The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

Parameter Name Required Type Description
Action Yes String Common parameter. The value used for this API: CreateLifecycleHook.
Version Yes String Common parameter. The value used for this API: 2018-04-19.
Region Yes String Common parameter. For more information, please see the list of regions supported by the product.
AutoScalingGroupId Yes String Auto scaling group ID
LifecycleHookName Yes String Lifecycle hook name, which can contain Chinese characters, letters, numbers, underscores (_), hyphens (-), and periods (.) with a maximum length of 128 bytes.
LifecycleTransition Yes String Scenario for the lifecycle hook. Valid values: "INSTANCE_LAUNCHING" and "INSTANCE_TERMINATING"
DefaultResult No String Defined actions when lifecycle hook times out. Valid values: "CONTINUE" and "ABANDON". Default value: "CONTINUE"
HeartbeatTimeout No Integer The maximum length of time (in seconds) that can elapse before the lifecycle hook times out. Value range: 30-3,600. Default value: 300
NotificationMetadata No String Additional information sent by Auto Scaling to the notification target. Default value is “”. Maximum length is 1024 characters.
NotificationTarget No NotificationTarget Notification target
LifecycleTransitionType No String The scenario where the lifecycle hook is applied. EXTENSION: the lifecycle hook will be triggered when AttachInstances, DetachInstances or RemoveInstaces is called. NORMAL: the lifecycle hook is not triggered by the above APIs.

3. Output Parameters

Parameter Name Type Description
LifecycleHookId String Lifecycle hook ID
RequestId String The unique request ID, which is returned for each request. RequestId is required for locating a problem.

4. Example

Example1 Creating a Lifecycle Hook with Default Values

Create a lifecycle hook that takes effect during instance creation, where DefaultResult takes the default value of CONTINUE and HeartbeatTimeout takes the default value of 300 seconds.

Input Example

https://as.tencentcloudapi.com/?Action=CreateLifecycleHook
&AutoScalingGroupId=asg-8fbozqja
&LifecycleHookName=one-hook-default
&LifecycleTransition=INSTANCE_LAUNCHING
&<common request parameters>

Output Example

{
  "Response": {
    "LifecycleHookId": "ash-8azjzxj9",
    "RequestId": "4fa9fd2e-5b6c-49fe-9ba7-ed2ee62d8271"
  }
}

Example2 Creating a Lifecycle Hook

Create a lifecycle hook that takes effect during instance creation, where DefaultResult is set to ABANDON and HeartbeatTimeout is set to 360 seconds.

Input Example

https://as.tencentcloudapi.com/?Action=CreateLifecycleHook
&AutoScalingGroupId=asg-8fbozqja
&DefaultResult=ABANDON
&HeartbeatTimeout=360
&LifecycleHookName=one-hook
&LifecycleTransition=INSTANCE_LAUNCHING
&<common request parameters>

Output Example

{
  "Response": {
    "LifecycleHookId": "ash-heyubibl",
    "RequestId": "5e414011-3359-45bd-8ba4-5b503d3fd3f6"
  }
}

Example3 Creating a Lifecycle Hook to Notify a CMQ Queuing Model

Create a lifecycle hook that takes effect during instance creation, where the DefaultResult is set to CONTINUE and the HeartbeatTimeout is set to 120 seconds to notify the CMQ queuing model named "one-queue".

Input Example

https://as.tencentcloudapi.com/?Action=CreateLifecycleHook
&AutoScalingGroupId=asg-8fbozqja
&DefaultResult=CONTINUE
&HeartbeatTimeout=120
&LifecycleHookName=launch-queue
&LifecycleTransition=INSTANCE_LAUNCHING
&NotificationMetadata=queue
&NotificationTarget.TargetType=CMQ_QUEUE
&NotificationTarget.QueueName=one-queue
&<common request parameters>

Output Example

{
  "Response": {
    "LifecycleHookId": "ash-fbjiexz7",
    "RequestId": "d3cf27b7-3090-4317-9107-d2eac986a446"
  }
}

Example4 Creating a Lifecycle Hook to Notify a CMQ Topic Model

Create a lifecycle hook that takes effect during instance termination, where the DefaultResult is set to ABANDON and the HeartbeatTimeout is set to 120 seconds to notify the CMQ topic model named "one-topic".

Input Example

https://as.tencentcloudapi.com/?Action=CreateLifecycleHook
&AutoScalingGroupId=asg-8fbozqja
&DefaultResult=ABANDON
&HeartbeatTimeout=120
&LifecycleHookName=terminate-topic
&LifecycleTransition=INSTANCE_TERMINATING
&NotificationMetadata=topic
&NotificationTarget.TargetType=CMQ_TOPIC
&NotificationTarget.TopicName=one-topic
&<common request parameters>

Output Example

{
  "Response": {
    "LifecycleHookId": "ash-oq76wsrx",
    "RequestId": "cdb7670b-0412-444f-9d2f-0da9cd07c410"
  }
}

5. Developer Resources

API Explorer

This tool allows online call, signature authentication, SDK code generation and quick search of APIs to greatly improve the efficiency of using TencentCloud APIs.

SDK

TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

Command Line Interface

6. Error Code

The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

Error Code Description
InternalError Internal error.
InvalidParameter Invalid parameter.
InvalidParameter.Conflict Multiple parameters specified conflict and cannot co-exist.
InvalidParameterValue Wrong parameter value.
InvalidParameterValue.Filter Invalid filter.
InvalidParameterValue.LifecycleHookNameDuplicated The lifecycle hook name already exists.
MissingParameter Missing parameter.