Creates an auto scaling policy for an application.

Usage notes

  • You can create up to five auto scaling policies for one application.
  • You can create up to 20 trigger points within one day in a scheduled auto scaling policy.
  • If an auto scaling policy is enabled for an application, you cannot manually manage the lifecycle of the application. For example, you cannot scale, deploy (including single-batch release, phased release, and canary release), stop, or restart the application, or change the instance type. If you want to perform the preceding operations on the application, disable the auto scaling policy and then manually perform the operations.
  • If an application is in the process of scale-out, scale-in, deployment (including single-batch release, phased release, and canary release), instance type change, restart, or stop, you cannot add or enable an auto scaling policy for the application.
  • If you want to configure more than 50 instances for an application, you must contact SAE technical support to add your account to the whitelist. For more information, see Contact Us.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request headers

This operation uses only common request headers and does not have operation-specific request headers. For more information, see Common request and response headers.

Request syntax

POST /pop/v1/sam/scale/applicationScalingRule HTTP/1.1

Request parameters

ParameterTypePositionRequiredExampleDescription
AppIdStringQueryYes7171a6ca-d1cd-4928-8642-7d5cfe69****

The application ID.

ScalingRuleNameStringQueryYestimer-0800-2100

The custom name of the auto scaling policy. The name must be unique in an application. The name must start with a lowercase letter and can contain only lowercase letters, digits, and hyphens (-). It cannot exceed 32 characters in length.

Note After you create an auto scaling policy, you cannot change the name of the auto scaling policy.
ScalingRuleTypeStringQueryYestiming

The type of the auto scaling policy. Valid values:

  • timing: a scheduled auto scaling policy
  • metric: a metric-based auto scaling policy
ScalingRuleTimerStringQueryNo{"beginDate":null,"endDate":null,"period":"* * *","schedules":[{"atTime":"08:00","targetReplicas":10},{"atTime":"20:00","targetReplicas":3}]}

The configurations of the scheduled auto scaling policy. This parameter is required if you set the ScalingRuleType parameter to timing or you want to create a scheduled auto scaling policy by using an SDK.

The following parameters are involved:

  • beginDate and endDate: specifies the validity period of the scheduled auto scaling policy. beginDate specifies the start date and endDate specifies the end date. Valid values:
    • If the two parameters are set to null, the scheduled auto scaling policy is a long-term policy. Default value of beginDate or endDate: null.
    • If the two parameters are set to specific dates, the scheduled auto scaling policy can be triggered during the period between the two dates. For example, if you set the beginDate parameter to 2021-03-25 and the endDate parameter to 2021-04-25, the auto scaling policy is valid for one month.
  • period: the frequency at which the scheduled auto scaling policy is executed. Valid values:
    • * * *: The scheduled auto scaling policy is executed at a specified point in time every day.
    • * * Fri,Mon: The scheduled auto scaling policy is executed at a specified point in time on one or more specified days of each week. The time is in the UTC+8 time zone. Valid values:
      • Sun: Sunday
      • Mon: Monday
      • Tue: Tuesday
      • Wed: Wednesday
      • Thu: Thursday
      • Fri: Friday
      • Sat: Saturday
    • 1,2,3,28,31 * *: The scheduled auto scaling policy is executed at a specified point in time on one or more dates of each month. Valid values: 1 to 31. If a month does not have the 31st day, the auto scaling policy is executed on the specified days other than the 31st day.
  • schedules: the point in time at which the scheduled auto scaling policy is triggered and the number of application instances that are retained during the corresponding period of time. You can specify up to 20 points in time. The following parameters are involved:
    • atTime: the point in time at which the policy is triggered. Format: Hour:Minute. Example: 08:00.
    • targetReplicas: the number of application instances that you want to retain during the corresponding period of time. You can set this parameter to the minimum number of available instances that are required each time the application is deployed. Valid values: 1 to 50.
      Note To ensure business continuity, make sure that at least one instance is available during application deployment and rollback. We recommend that you set this parameter to a value that is greater than or equal to 1. If you set the value to 0, business interruptions occur when the application is upgraded.
ScalingRuleMetricStringQueryNo{"maxReplicas":3,"minReplicas":1,"metrics":[{"metricType":"CPU","metricTargetAverageUtilization":20},{"metricType":"MEMORY","metricTargetAverageUtilization":30},{"metricType":"tcpActiveConn","metricTargetAverageUtilization":20},{"metricType":"SLB_QPS","MetricTargetAverageUtilization":25,"slbId":"lb-xxx","slbProject":"aliyun-fc-cn-hangzhou-d95881d9-5d3c-5f26-a6b8-************","slbLogstore":"function-log","vport":"80"},{"metricType":"SLB_RT","MetricTargetAverageUtilization":35,"slbId":"lb-xxx","slbProject":"aliyun-fc-cn-hangzhou-d95881d9-5d3c-5f26-a6b8-************","slbLogstore":"function-log","vport":"80"}],"scaleUpRules":{"step":"100","disabled":false,"stabilizationWindowSeconds":0},"scaleDownRules":{"step":"100","disabled":false,"stabilizationWindowSeconds":300}}

The configurations of the metric-based auto scaling policy. This parameter is required if you set the ScalingRuleType parameter to metric.

The following parameters are involved:

  • maxReplicas: the maximum number of instances in the application.
  • minReplicas: the minimum number of instances in the application.
  • metricType: the metric that is used to trigger the auto scaling policy.
    • CPU: the CPU utilization.
    • MEMORY: the memory usage.
    • QPS: the average queries per second (QPS) of a Java application instance per minute.
    • RT: the average response time of all API operations in the Java application per minute.
    • tcpActiveConn: the average number of active TCP connections of an application instance within 30 seconds.
    • SLB_QPS: the average QPS of the Internet-facing SLB instance associated with an application instance within 15 seconds.
    • SLB_RT: the average response time of the Internet-facing SLB instance within 15 seconds.
    • INTRANET_SLB_QPS: the average QPS of the internal-facing SLB instance associated with an application instance within 15 seconds.
    • INTRANET_SLB_RT: the average response time of the internal-facing SLB instance within 15 seconds.
  • metricTargetAverageUtilization: the limit on the metric that is specified by the metricType parameter.
    • The limit on the CPU utilization. Unit: percentage.
    • The limit on the memory usage. Unit: percentage.
    • The limit on the QPS. Unit: seconds.
    • The limit on the response time. Unit: milliseconds.
    • The limit on the average number of active TCP connections per second. Unit: connections per second.
    • The limit on the QPS of the Internet-facing SLB instance. Unit: seconds.
    • The limit on the response time of the Internet-facing SLB instance. Unit: milliseconds.
    • The limit on the QPS of the internal-facing SLB instance. Unit: seconds.
    • The limit on the response time of the internal-facing SLB instance. Unit: milliseconds.
  • slbId: the SLB ID.
  • slbProject: the Log Service project.
  • slbLogstore: the Log Service Logstore.
  • vport: the listener port of the SLB instance. HTTP and HTTPS are supported.
  • scaleUpRules: the scale-out rule.
  • scaleDownRules: the scale-in rule.
  • step: the scale-out or scale-in step size. This parameter specifies the maximum number of instances that can be added or removed per unit time.
  • disabled: specifies whether to disable the application scale-in. If you set this parameter to true, the application instances are never reduced. This prevents business risks during peak hours.
    • true: disables the application scale-in.
    • false: enables the application scale-in. This is the default value.
  • stabilizationWindowSeconds: the cooldown period during which the system is stable and does not perform scale-out or scale-in operations. Valid values: 0 to 3600. Unit: seconds. Default value: 0.
Note You can specify one or more metrics as the trigger conditions of the auto scaling policy. If one of the values of the specified metrics is greater than or equal to the specified limit, the application is scaled out. The number of instances after the scale-out operation is less than or equal to the value of the specified maximum application instances. If the values of all specified metrics are less than the limits, the application is scaled in. The number of instances after the scale-in operation is greater than or equal to the value of the specified minimum application instances.
MinReadyInstancesIntegerQueryNo3

The minimum number of available instances. Valid values:

  • If you set the value to 0, business interruptions occur when the application is upgraded.
  • If you set the value to -1, the minimum number of available instances is automatically set to a system-recommended value. The value is the nearest integer to which the calculated result of the following formula is rounded up: Current number of instances × 25%. For example, if five instances are available, the minimum number of available instances is calculated by using the following formula: 5 × 25% = 1.25. In this case, the minimum number of available instances is 2.
Note To ensure business continuity, make sure that at least one instance is available during application deployment and rollback.
MinReadyInstanceRatioIntegerQueryNo-1

The ratio of the minimum number of available instances to the current number of instances. Valid values:

  • If you set the value to -1, the minimum number of available instances is not determined based on this parameter. This is the default value.
  • If you set the value to a number from 0 to 100, the minimum number of available instances is calculated by using the following formula: Current number of instances × (Value of MinReadyInstanceRatio × 100%). If the calculated result is not an integer, the result is rounded up to the nearest integer. For example, if five instances are available and the MinReadyInstanceRatio parameter is set to 50, the minimum number of available instances is 3.
Note If the MinReadyInstance and MinReadyInstanceRatio parameters are configured and the MinReadyInstanceRatio parameter is set to a number from 0 to 100, the value of the MinReadyInstanceRatio parameter takes precedence. For example, if the MinReadyInstances parameter is set to 5, and the MinReadyInstanceRatio parameter is set to 50, the minimum number of available instances is set to the nearest integer rounded up from the calculated result of the following formula: Current number of instances × 50%.
ScalingRuleEnableBooleanQueryNotrue

Specifies whether to enable the auto scaling policy. Valid values:

  • true: enables the auto scaling policy.
  • false: disables the auto scaling policy.

Response parameters

ParameterTypeExampleDescription
RequestIdString91F93257-7A4A-4BD3-9A7E-2F6EAE6D****

The request ID.

TraceIdString0a98a02315955564772843261e****

The trace ID that is used to query details of the request.

DataObject

The returned result.

TimerObject

The details of the scheduled auto scaling policy.

EndDateString2021-04-25

The end date of the validity period of the scheduled auto scaling policy.

  • If the BeginDate and EndDate parameters are set to null, the auto scaling policy is a long-term policy. Default value of BeginDate or EndDate: null.
  • If the two parameters are set to specific dates, the scheduled auto scaling policy can be triggered during the period between the two dates. For example, if you set the BeginDate parameter to 2021-03-25 and the EndDate parameter to 2021-04-25, the auto scaling policy is valid for one month.
BeginDateString2021-03-25

The start date of the validity period of the scheduled auto scaling policy.

  • If the BeginDate and EndDate parameters are set to null, the auto scaling policy is a long-term policy. Default value of BeginDate or EndDate: null.
  • If the two parameters are set to specific dates, the scheduled auto scaling policy can be triggered during the period between the two dates. For example, if you set the BeginDate parameter to 2021-03-25 and the EndDate parameter to 2021-04-25, the auto scaling policy is valid for one month.
SchedulesArray of Schedule

The points in time at which the auto scaling policy is triggered within one day.

AtTimeString08:00

The point in time. Format: Hour:Minute.

TargetReplicasInteger3

The expected number of instances.

MaxReplicasInteger10

The maximum number of instances.

MinReplicasInteger5

The minimum number of instances.

PeriodString* * *

The frequency at which the scheduled auto scaling policy is executed. Valid values:

  • * * *: The scheduled auto scaling policy is executed at a specified point in time every day.
  • * * Fri,Mon: The scheduled auto scaling policy is executed at a specified point in time on one or more specified days of each week. The time is in the UTC+8 time zone. Valid values:
    • Sun: Sunday
    • Mon: Monday
    • Tue: Tuesday
    • Wed: Wednesday
    • Thu: Thursday
    • Fri: Friday
    • Sat: Saturday
  • 1,2,3,28,31 * *: The scheduled auto scaling policy is executed at a specified point in time on one or more dates of each month. Valid values: 1 to 31. If a month does not have the 31st day, the auto scaling policy is executed on the specified days other than the 31st day.
UpdateTimeLong1616642248938

The time when the auto scaling policy was updated. Unit: milliseconds.

AppIdString7171a6ca-d1cd-4928-8642-7d5cfe69****

The application ID.

CreateTimeLong1616642248938

The time when the auto scaling policy was created. Unit: milliseconds.

LastDisableTimeLong1641882854484

The time when the auto scaling policy was last disabled.

ScaleRuleEnabledBooleantrue

Indicates whether the auto scaling policy is enabled. Valid values:

  • true: The auto scaling policy is enabled.
  • false: The auto scaling policy is disabled.
ScaleRuleTypeStringtiming

The type of the auto scaling policy. Valid values:

  • timing: a scheduled auto scaling policy
  • metric: a metric-based auto scaling policy
  • mix: a hybrid auto scaling policy
MetricObject

The details of the metric-based auto scaling policy.

MetricsArray of Metric

The metrics that are used to trigger the auto scaling policy.

MetricTargetAverageUtilizationInteger20

The limit on the metric.

  • The limit on the CPU utilization. Unit: percentage.
  • The limit on the memory usage. Unit: percentage.
  • The limit on the QPS. Unit: seconds.
  • The limit on the response time. Unit: milliseconds.
  • The limit on the average number of active TCP connections per second. Unit: connections per second.
  • The limit on the QPS of the Internet-facing SLB instance. Unit: seconds.
  • The limit on the response time of the Internet-facing SLB instance. Unit: milliseconds.
  • The limit on the QPS of the internal-facing SLB instance. Unit: seconds.
  • The limit on the response time of the internal-facing SLB instance. Unit: milliseconds.
MetricTypeStringCPU

The metric that is used to trigger the auto scaling policy. Valid values:

  • CPU: the CPU utilization.
  • MEMORY: the memory usage.
  • QPS: the average queries per second (QPS) of a Java application instance per minute.
  • RT: the average response time of all API operations in the Java application per minute.
  • tcpActiveConn: the average number of active TCP connections of an application instance within 30 seconds.
  • SLB_QPS: the average QPS of the Internet-facing SLB instance associated with an application instance within 15 seconds.
  • SLB_RT: the average response time of the Internet-facing SLB instance within 15 seconds.
  • INTRANET_SLB_QPS: the average QPS of the internal-facing SLB instance associated with an application instance within 15 seconds.
  • INTRANET_SLB_RT: the average response time of the internal-facing SLB instance within 15 seconds.
SlbProjectStringtest

The project that stores the SLB access logs.

SlbLogstoreStringtest

The Logstore that stores the SLB access logs.

VportString80

The port number of the SLB instance.

SlbIdStringlb-xxx

The ID of the SLB instance.

MaxReplicasInteger3

The maximum number of instances.

MinReplicasInteger1

The minimum number of instances.

ScaleRuleNameStringtest

The name of the auto scaling policy.

MessageStringsuccess

The returned message. Valid values:

  • success: If the call is successful, success is returned.
  • An error code: If the call fails, an error code is returned.
ErrorCodeStringNull

The error code. Valid values:

  • If the call is successful, the ErrorCode parameter is not returned.
  • If the call fails, the ErrorCode parameter is returned. For more information, see the "Error codes" section in this topic.
CodeString200

The HTTP status code. Valid values:

  • 2xx: The call was successful.
  • 3xx: The call was redirected.
  • 4xx: The call failed.
  • 5xx: A server error occurred.
SuccessBooleantrue

Indicates whether the application instances were restarted. Valid values:

  • true: The application instances were restarted.
  • false: The application instances failed to be restarted.

Examples

Sample requests

POST /pop/v1/sam/scale/applicationScalingRule?AppId=7171a6ca-d1cd-4928-8642-7d5cfe69****&ScalingRuleName=timer-0800-2100&ScalingRuleType=timing&ScalingRuleTimer={"beginDate":null,"endDate":null,"period":"* * *","schedules":[{"atTime":"08:00","targetReplicas":10},{"atTime":"20:00","targetReplicas":3}]}&ScalingRuleMetric={"maxReplicas":3,"minReplicas":1,"metrics":[{"metricType":"CPU","metricTargetAverageUtilization":20},{"metricType":"MEMORY","metricTargetAverageUtilization":30},{"metricType":"tcpActiveConn","metricTargetAverageUtilization":20},{"metricType":"SLB_QPS","MetricTargetAverageUtilization":25,"slbId":"lb-xxx","slbProject":"aliyun-fc-cn-hangzhou-d95881d9-5d3c-5f26-a6b8-************","slbLogstore":"function-log","Vport":"80"},{"metricType":"SLB_RT","MetricTargetAverageUtilization":35,"slbId":"lb-xxx","slbProject":"aliyun-fc-cn-hangzhou-d95881d9-5d3c-5f26-a6b8-************","slbLogstore":"function-log","Vport":"80"}],"scaleUpRules":{"step":"100","disabled":false,"stabilizationWindowSeconds":0},"scaleDownRules":{"step":"100","disabled":false,"stabilizationWindowSeconds":300}}&MinReadyInstances=3&MinReadyInstanceRatio=-1&ScalingRuleEnable=true HTTP/1.1
Host:sae.aliyuncs.com
Content-Type:application/json

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateApplicationScalingRuleResponse>
    <RequestId>91F93257-7A4A-4BD3-9A7E-2F6EAE6D****</RequestId>
    <TraceId>0a98a02315955564772843261e****</TraceId>
    <Data>
        <Timer>
            <EndDate>2021-04-25</EndDate>
            <BeginDate>2021-03-25</BeginDate>
            <Schedules>
                <AtTime>08:00</AtTime>
                <TargetReplicas>3</TargetReplicas>
                <MaxReplicas>10</MaxReplicas>
                <MinReplicas>5</MinReplicas>
            </Schedules>
            <Period>* * *</Period>
        </Timer>
        <UpdateTime>1616642248938</UpdateTime>
        <AppId>7171a6ca-d1cd-4928-8642-7d5cfe69****</AppId>
        <CreateTime>1616642248938</CreateTime>
        <LastDisableTime>1641882854484</LastDisableTime>
        <ScaleRuleEnabled>true</ScaleRuleEnabled>
        <ScaleRuleType>timing</ScaleRuleType>
        <Metric>
            <Metrics>
                <MetricTargetAverageUtilization>20</MetricTargetAverageUtilization>
                <MetricType>CPU</MetricType>
                <SlbProject>test</SlbProject>
                <SlbLogstore>test</SlbLogstore>
                <Vport>80</Vport>
                <SlbId>lb-xxx</SlbId>
            </Metrics>
            <MaxReplicas>3</MaxReplicas>
            <MinReplicas>1</MinReplicas>
        </Metric>
        <ScaleRuleName>test</ScaleRuleName>
    </Data>
    <Message>success</Message>
    <Code>200</Code>
    <Success>true</Success>
</CreateApplicationScalingRuleResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "91F93257-7A4A-4BD3-9A7E-2F6EAE6D****",
  "TraceId" : "0a98a02315955564772843261e****",
  "Data" : {
    "Timer" : {
      "EndDate" : "2021-04-25",
      "BeginDate" : "2021-03-25",
      "Schedules" : [ {
        "AtTime" : "08:00",
        "TargetReplicas" : 3,
        "MaxReplicas" : 10,
        "MinReplicas" : 5
      } ],
      "Period" : "* * *"
    },
    "UpdateTime" : 1616642248938,
    "AppId" : "7171a6ca-d1cd-4928-8642-7d5cfe69****",
    "CreateTime" : 1616642248938,
    "LastDisableTime" : 1641882854484,
    "ScaleRuleEnabled" : true,
    "ScaleRuleType" : "timing",
    "Metric" : {
      "Metrics" : [ {
        "MetricTargetAverageUtilization" : 20,
        "MetricType" : "CPU",
        "SlbProject" : "test",
        "SlbLogstore" : "test",
        "Vport" : "80",
        "SlbId" : "lb-xxx"
      } ],
      "MaxReplicas" : 3,
      "MinReplicas" : 1
    },
    "ScaleRuleName" : "test"
  },
  "Message" : "success",
  "Code" : "200",
  "Success" : true
}

Error codes

HTTP status codeError codeError messageDescription
400InstanceExist.ScalingRuleNameThe specified ScalingRuleName already exists.The specified auto scaling policy name already exists.
400InvalidScalingRuleDate.BeginAfterEndThe specified beginning time is later than the ending time.The specified start time is later than the end time.
400InvalidScalingRuleDate.FormatThe specified date is invalid.The specified date is invalid. The date must be in the YYYY-MM-DD format.
400InvalidScalingRuleName.NotFoundThe specified ScalingRuleName does not exist.The specified ScalingRuleName does not exist.
400InvalidScalingRuleTime.ConflictThe specified scaling rule time is invalid. Another schedule has been set for the specified time range. Please set a different time.The specified validity period of the auto scaling policy is invalid. A scheduled auto scaling policy is valid in the specified period. Specify a different period.
400InvalidScalingRuleTime.FormatThe specified time is invalid.The specified point in time is invalid. The point in time must be in the HH:MM format.
400QuotaExceeded.ScalingRuleThe maximum number of application scaling rules is exceeded.The number of auto scaling policies for the application has reached the upper limit.
400QuotaExceeded.ScalingRuleTimeThe maximum number of scaling policy trigger time is exceeded.The number of points in time when the auto scaling policy is triggered has reached the upper limit.
400NoComputeResourceQuota.App.ExceedYou can create %s instances for each application. Please submit a ticket to raise the quota.A maximum of %s instances can be created for each application. Join the DingTalk group 32874633 for technical support.
400NoComputeResourceQuota.User.ExceedYour account is limited to create %s instances. Please submit a ticket to raise the quota.A maximum of %s instances can be created within your account. Join the DingTalk group 32874633 for technical support.
400System.UpgradingThe system is being upgraded. Please try again later.The system is being upgraded. Try again later.
400OperationDenied.SDKNotSupportedMetrics is not supported in SDKThe SDK does not support the configuration of metric-based auto scaling policies.
400MinReadyInstances.Not.Smaller.ReplicasThe minimum number of available instances must be less than the number of application instances.The minimum number of available instances is larger than or equal to the total number of instances.
400MinReadyInstanceRatio.InvalidThe ratio of minimum available instances must be between 0 and 100.The value of the MinReadyInstanceRatio parameter is invalid. The parameter value must be an integer from 0 to 100.

For a list of error codes, see Service error codes.