tencent cloud

Feedback

CreateScalingPolicy

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

    1. API Description

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

    This API (CreateScalingPolicy) is used to create an alarm trigger policy.

    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: CreateScalingPolicy.
    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.
    ScalingPolicyName Yes String Alarm trigger policy name.
    ScalingPolicyType No String Scaling policy type. Valid values:
  • SIMPLE (default): A simple policy
  • TARGET_TRACKING: A target tracking policy
  • .
    AdjustmentType No String The method to adjust the desired capacity after the alarm is triggered. It’s only available when ScalingPolicyType is Simple. Valid values:
  • CHANGE_IN_CAPACITY: Increase or decrease the desired capacity
  • EXACT_CAPACITY: Adjust to the specified desired capacity
  • PERCENT_CHANGE_IN_CAPACITY: Adjust the desired capacity by percentage
  • AdjustmentValue No Integer Specifies how to adjust the number of desired capacity when the alarm is triggered. It’s only available when ScalingPolicyType is Simple. Values:
  • AdjustmentType=CHANGE_IN_CAPACITY: Number of instances to add (positive number) or remove (negative number).
  • AdjustmentType=EXACT_CAPACITY: Set the desired capacity to the specified number. It must be ≥ 0.
  • AdjustmentType=PERCENT_CHANGE_IN_CAPACITY: Percentage of instance number. Add instances (positive value) or remove instances (negative value) accordingly.
  • Cooldown No Integer Cooldown period (in seconds). This parameter is only applicable to a simple policy. Default value: 300.
    MetricAlarm No MetricAlarm Alarm monitoring metric. It’s only available when ScalingPolicyType is Simple.
    PredefinedMetricType No String Preset monitoring item. It’s only available when ScalingPolicyType is TARGET_TRACKING. Valid values:
  • ASG_AVG_CPU_UTILIZATION: Average CPU utilization
  • ASG_AVG_LAN_TRAFFIC_OUT: Average private bandwidth out
  • ASG_AVG_LAN_TRAFFIC_IN: Average private bandwidth in
  • ASG_AVG_WAN_TRAFFIC_OUT: Average public bandwidth out
  • ASG_AVG_WAN_TRAFFIC_IN: Average public bandwidth in
  • TargetValue No Integer Target value. It’s only available when ScalingPolicyType is TARGET_TRACKING. Value ranges:
  • ASG_AVG_CPU_UTILIZATION (in %): [1, 100)
  • ASG_AVG_LAN_TRAFFIC_OUT (in Mbps): >0
  • ASG_AVG_LAN_TRAFFIC_IN (in Mbps): >0
  • ASG_AVG_WAN_TRAFFIC_OUT (in Mbps): >0
  • ASG_AVG_WAN_TRAFFIC_IN (in Mbps): >0
  • EstimatedInstanceWarmup No Integer Instance warm-up period (in seconds). It’s only available when ScalingPolicyType is TARGET_TRACKING. Value range: 0-3600. Default value: 300.
    DisableScaleIn No Boolean Whether to disable scale-in. It’s only available when ScalingPolicyType is TARGET_TRACKING. Valid values:
  • true: Do not scale in
  • false (default): Both scale-out and scale-in can be triggered.
  • NotificationUserGroupIds.N No Array of String This parameter is diused. Please use CreateNotificationConfiguration instead.
    Notification group ID, which is the set of user group IDs.

    3. Output Parameters

    Parameter Name Type Description
    AutoScalingPolicyId String Alarm trigger policy 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 Simple Policy: Average CPU Utilization

    This example shows you how to increase the expected instance number by 1 when the average CPU utilization exceeds 50% for five consecutive times within 1 minute.

    Input Example

    POST / HTTP/1.1
    Host: as.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateScalingPolicy
    <Common request parameters>
    
    {
        "AutoScalingGroupId": "asg-12wjuh0s",
        "Cooldown": "60",
        "ScalingPolicyType": "SIMPLE",
        "ScalingPolicyName": "cpu_policy_test",
        "AdjustmentType": " CHANGE_IN_CAPACITY",
        "MetricAlarm": {
            "Period": "60",
            "ContinuousTime": "5",
            "ComparisonOperator": "GREATER_THAN",
            "Statistic": "AVERAGE",
            "Threshold": "50",
            "MetricName": "CPU_UTILIZATION"
        },
        "NotificationUserGroupIds": [
            "1678"
        ],
        "AdjustmentValue": "1"
    }
    

    Output Example

    {
        "Response": {
            "AutoScalingPolicyId": "asp-iir70sxv",
            "RequestId": "fb02c8bd-5f38-4786-91b6-0c6e06a88832"
        }
    }
    

    Example2 Creating a Simple Policy: Average Memory Utilization

    This example shows you how to decrease the expected instance number by 50% when the average CPU utilization falls below 35% for five consecutive times within 1 minute.

    Input Example

    POST / HTTP/1.1
    Host: as.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateScalingPolicy
    <Common request parameters>
    
    {
        "AutoScalingGroupId": "asg-12wjuh0s",
        "Cooldown": "300",
        "ScalingPolicyType": "SIMPLE",
        "ScalingPolicyName": "mem_policy_test",
        "AdjustmentType": " PERCENT_CHANGE_IN_CAPACITY",
        "MetricAlarm": {
            "Period": "60",
            "ContinuousTime": "5",
            "ComparisonOperator": "LESS_THAN",
            "Statistic": "AVERAGE",
            "Threshold": "50",
            "MetricName": "MEM_UTILIZATION"
        },
        "NotificationUserGroupIds": [
            "1678"
        ],
        "AdjustmentValue": "-50"
    }
    

    Output Example

    {
        "Response": {
            "AutoScalingPolicyId": "asp-f59pppuh",
            "RequestId": "116213d6-2269-44cc-af76-c4a8dc7dbdf9"
        }
    }
    

    Example3 Creating a Target Tracking Policy: Average CPU Utilization

    This example shows you how to keep the average CPU utilization of the scaling group close to 60%, how to set the parameter for scale-out instance preheating to 300 after the alarm is triggered, and how to set the disabling scale-in parameter value to false.

    Input Example

    POST / HTTP/1.1
    Host: as.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateScalingPolicy
    <Common request parameters>
    
    {
        "AutoScalingGroupId": "asg-9dn1a5y6",
        "ScalingPolicyName": "cpu_target_tracking_test",
        "ScalingPolicyType": "TARGET_TRACKING",
        "PredefinedMetricType": "ASG_AVG_CPU_UTILIZATION",
        "EstimatedInstanceWarmup": 300,
        "DisableScaleIn": false,
        "TargetValue": 60
    }
    

    Output Example

    {
        "Response": {
            "AutoScalingPolicyId": "asp-ljr51ssq",
            "RequestId": "58a8ac17-e864-4bf6-81c7-c5dc63b0057d"
        }
    }
    

    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.CallMonitorError Monitor API call failed.
    InternalError.CallNotificationError The notification service API call failed.
    InternalError.RequestError An internal request error occurred.
    InvalidParameter.ActionNotFound Invalid Action request.
    InvalidParameterValue.InvalidAutoScalingGroupId Invalid scaling group ID.
    InvalidParameterValue.InvalidNotificationUserGroupId The notification group ID should be a numeric string.
    InvalidParameterValue.LimitExceeded The value exceeds the limit.
    InvalidParameterValue.Range The value is outside the specified range.
    InvalidParameterValue.ScalingPolicyNameDuplicate The alarm policy name already exists.
    InvalidParameterValue.ThresholdOutOfRange The specified threshold must be within the valid range.
    InvalidParameterValue.TooLong Too many values.
    InvalidParameterValue.UserGroupIdNotFound The user group does not exist.
    LimitExceeded.QuotaNotEnough You are short of the quota.
    LimitExceeded.TargetTrackingScalingPolicy Only one target tracking policy can be created for a scaling group.
    ResourceNotFound.AutoScalingGroupNotFound The scaling group does not exist.