tencent cloud

CreateLifecycleHook
Last updated: 2025-10-30 21:28:22
CreateLifecycleHook
Last updated: 2025-10-30 21:28:22

1. API Description

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

This interface (CreateLifecycleHook) is used for creating a lifecycle hook.

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

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

{
    "Service": "Tencent Cloud Auto Scaling",
    "Time": "2019-03-14T10:15:11Z",
    "AppId": "1251783334",
    "ActivityId": "asa-fznnvrja",
    "AutoScalingGroupId": "asg-ft6y7u8n",
    "LifecycleHookId": "ash-p9i7y6t5",
    "LifecycleHookName": "my-hook",
    "LifecycleActionToken": "3080e1c9-0efe-4dd7-ad3b-90cd6618298f",
    "InstanceId": "ins-y6dr5e43",
    "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 Scaling group ID. obtain available scaling group ids in the following ways:.
  • Query the scaling group ID by logging in to the console.
  • .
  • Specifies the scaling group ID obtained by calling the api DescribeAutoScalingGroups and retrieving the AutoScalingGroupId from the return information.
  • .
    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 performing the lifecycle hook. valid values:.
  • INSTANCE_LAUNCHING: the lifecycle hook is being scaled out.
  • .
  • INSTANCE_TERMINATING: scaling in lifecycle hook
  • .
    DefaultResult No String Action to be taken by the scaling group in case of lifecycle hook timeout or LifecycleCommand execution failure. valid values:.
  • CONTINUE: default value, means continue execution of capacity expansion or reduction
  • .
  • ABANDON: for scale-out hooks, CVM instances with hook timeout or failed LifecycleCommand execution will be released directly or removed. for scale-in hooks, scale-in activities will 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: ""), with a maximum length of 1024 characters. NotificationMetadata and LifecycleCommand are mutually exclusive, and either can be specified.
    NotificationTarget No NotificationTarget Notification target. NotificationTarget and LifecycleCommand cannot be specified at the same time.
    LifecycleTransitionType No String Specifies the scenario type for performing the lifecycle hook. valid values: NORMAL and EXTENSION. default value: NORMAL.
    EXTENSION: the lifecycle hook will be triggered when calling AttachInstances, DetachInstances, removeinstances, StopAutoScalingInstances, StartAutoScalingInstances, or StartInstanceRefresh. NORMAL: the lifecycle hook is not triggered by these apis.
    LifecycleCommand No LifecycleCommand Specifies the remote command execution object. NotificationTarget and NotificationMetadata are mutually exclusive with this parameter. either cannot be specified simultaneously.

    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.intl.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.intl.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.intl.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.intl.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 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.intl.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.
    Was this page helpful?
    You can also Contact Sales or Submit a Ticket for help.
    Yes
    No

    Feedback