tencent cloud

Feedback

CreateLifecycleHook

Last updated: 2024-10-25 15:16:23

    1. API Description

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

    This API is used to create a lifecycle hook.

    • You can configure notifications or automation commands (TAT) for the lifecycle hook.

    If you configured a notification, Auto Scaling will notify the TDMQ queue of the following information:

    {
        "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.

    We recommend you to use API Explorer
    Try it
    API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

    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 Params. The value used for this API: CreateLifecycleHook.
    Version Yes String Common Params. The value used for this API: 2018-04-19.
    Region Yes String Common Params. 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-7200. Default value: 300
    NotificationMetadata No String Additional information of a notification that Auto Scaling sends to targets. This parameter is set when you configure a notification (default value: ""). Up to 1024 characters are allowed.
    NotificationTarget No NotificationTarget Notification target. NotificationTarget and LifecycleCommand cannot be specified at the same time.
    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.
    LifecycleCommand No LifecycleCommand Remote command execution object. NotificationTarget and LifecycleCommand cannot be specified at the same time.

    3. Output Parameters

    Parameter Name Type Description
    LifecycleHookId String Lifecycle hook ID
    RequestId String The unique request ID, generated by the server, will be returned for every request (if the request fails to reach the server for other reasons, the request will not obtain a RequestId). RequestId is required for locating a problem.

    4. Example

    Example1 Creating a Lifecycle Hook

    This example shows you how to create a lifecycle hook that takes effect in the scenario of instance creation, where DefaultResult is set to ABANDON and HeartbeatTimeout is set to 360 seconds.

    Input Example

    POST / HTTP/1.1
    Host: as.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateLifecycleHook
    <Common request parameters>
    
    {
        "AutoScalingGroupId": "asg-8fbozqja",
        "DefaultResult": "ABANDON",
        "LifecycleHookName": "one-hook",
        "LifecycleTransition": "INSTANCE_LAUNCHING",
        "HeartbeatTimeout": "360"
    }
    

    Output Example

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

    Example2 Creating a Lifecycle Hook with the Default Value

    This example shows you how to create a lifecycle hook that takes effect in the scenario of instance creation, where DefaultResult takes the default value CONTINUE and HeartbeatTimeout takes the default value 300 seconds.

    Input Example

    POST / HTTP/1.1
    Host: as.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateLifecycleHook
    <Common request parameters>
    
    {
        "AutoScalingGroupId": "asg-8fbozqja",
        "LifecycleHookName": "one-hook-default",
        "LifecycleTransition": "INSTANCE_LAUNCHING"
    }
    

    Output Example

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

    Example3 Creating a Lifecycle Hook to Notify the TDMQ Topic Model

    This example shows you how to create a lifecycle hook that takes effect in the scenario of instance termination, where DefaultResult is set to ABANDON and HeartbeatTimeout is set to 120 seconds, to notify the TDMQ topic model named one-topic.

    Input Example

    POST / HTTP/1.1
    Host: as.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateLifecycleHook
    <Common request parameters>
    
    {
        "HeartbeatTimeout": "120",
        "AutoScalingGroupId": "asg-8fbozqja",
        "LifecycleHookName": "terminate-topic",
        "NotificationMetadata": "topic",
        "NotificationTarget": {
            "TargetType": "TDMQ_TOPIC",
            "TopicName": "one-topic"
        },
        "DefaultResult": "ABANDON",
        "LifecycleTransition": "INSTANCE_TERMINATING"
    }
    

    Output Example

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

    Example4 Creating a Lifecycle Hook to Notify the TDMQ Model

    This example shows you how to create a lifecycle hook that takes effect in the scenario of instance creation, where DefaultResult is set to CONTINUE and HeartbeatTimeout is set to 120 seconds, to notify the TDMQ model named one-queue.

    Input Example

    POST / HTTP/1.1
    Host: as.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateLifecycleHook
    <Common request parameters>
    
    {
        "HeartbeatTimeout": "120",
        "AutoScalingGroupId": "asg-8fbozqja",
        "LifecycleHookName": "launch-queue",
        "NotificationMetadata": "queue",
        "NotificationTarget": {
            "TargetType": "TDMQ_QUEUE",
            "QueueName": "one-queue"
        },
        "DefaultResult": "CONTINUE",
        "LifecycleTransition": "INSTANCE_LAUNCHING"
    }
    

    Output Example

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

    Example5 Creating a Lifecycle Hook to Execute TAT Commands

    This example shows you how to create a lifecycle hook that takes effect upon instance creation, where DefaultResult takes the default value CONTINUE and HeartbeatTimeout takes the default value 300 seconds.

    Input Example

    POST / HTTP/1.1
    Host: as.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateLifecycleHook
    <Common request parameters>
    
    {
        "HeartbeatTimeout": "300",
        "AutoScalingGroupId": "asg-mp5ydedh",
        "LifecycleCommand": {
            "CommandId": "cmd-id9u919l",
            "Parameters": "{\"var1\":\"ck\"}"
        },
        "LifecycleHookName": "demo2",
        "DefaultResult": "CONTINUE",
        "LifecycleTransition": "INSTANCE_LAUNCHING"
    }
    

    Output Example

    {
        "Response": {
            "LifecycleHookId": "ash-kjurq12y",
            "RequestId": "08f7bea5-3e0a-4280-9970-5d959a922b0b"
        }
    }
    

    5. Developer Resources

    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 An internal error occurred.
    InternalError.CallCmqError The CMQ API call failed.
    InternalError.CallTATError Failed to call the Tencent Automation Tools (TAT) API.
    InternalError.CalleeError Exceptions occurred while invoking other services.
    InvalidParameter Invalid parameter.
    InvalidParameter.ActionNotFound Invalid Action request.
    InvalidParameter.Conflict Multiple parameters specified conflict and cannot co-exist.
    InvalidParameterValue Wrong parameter value.
    InvalidParameterValue.Filter Invalid filter.
    InvalidParameterValue.InvalidAutoScalingGroupId Invalid scaling group ID.
    InvalidParameterValue.LifecycleHookNameDuplicated The lifecycle hook name already exists.
    InvalidParameterValue.Range The value is outside the specified range.
    LimitExceeded.QuotaNotEnough You are short of the quota.
    MissingParameter Parameter missing.
    ResourceNotFound.AutoScalingGroupNotFound The scaling group does not exist.
    ResourceNotFound.CmqQueueNotFound The specified CMQ queue does not exist.
    ResourceNotFound.CommandNotFound The command does not exist.
    ResourceNotFound.TDMQCMQQueueNotFound The TDMQ-CMQ queue doesn't exist.
    ResourceNotFound.TDMQCMQTopicNotFound The TDMQ-CMQ topic doesn't exist.
    ResourceUnavailable.CmqTopicHasNoSubscriber There are no subscribers for the specified CMQ topic.
    ResourceUnavailable.TDMQCMQTopicHasNoSubscriber The TDMQ-CMQ topic is not subscribed.