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
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
Parameter | Type | Position | Required | Example | Description |
---|---|---|---|---|---|
AppId | String | Query | Yes | 7171a6ca-d1cd-4928-8642-7d5cfe69**** | The application ID. |
ScalingRuleName | String | Query | Yes | timer-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. |
ScalingRuleType | String | Query | Yes | timing | The type of the auto scaling policy. Valid values:
|
ScalingRuleTimer | String | Query | No | {"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:
|
ScalingRuleMetric | String | Query | No | {"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:
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. |
MinReadyInstances | Integer | Query | No | 3 | The minimum number of available instances. Valid values:
Note To ensure business continuity, make sure that at least one instance is available during application deployment and rollback. |
MinReadyInstanceRatio | Integer | Query | No | -1 | The ratio of the minimum number of available instances to the current number of instances. Valid values:
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%. |
ScalingRuleEnable | Boolean | Query | No | true | Specifies whether to enable the auto scaling policy. Valid values:
|
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
RequestId | String | 91F93257-7A4A-4BD3-9A7E-2F6EAE6D**** | The request ID. |
TraceId | String | 0a98a02315955564772843261e**** | The trace ID that is used to query details of the request. |
Data | Object | The returned result. | |
Timer | Object | The details of the scheduled auto scaling policy. | |
EndDate | String | 2021-04-25 | The end date of the validity period of the scheduled auto scaling policy.
|
BeginDate | String | 2021-03-25 | The start date of the validity period of the scheduled auto scaling policy.
|
Schedules | Array of Schedule | The points in time at which the auto scaling policy is triggered within one day. | |
AtTime | String | 08:00 | The point in time. Format: Hour:Minute. |
TargetReplicas | Integer | 3 | The expected number of instances. |
MaxReplicas | Integer | 10 | The maximum number of instances. |
MinReplicas | Integer | 5 | The minimum number of instances. |
Period | String | * * * | The frequency at which the scheduled auto scaling policy is executed. Valid values:
|
UpdateTime | Long | 1616642248938 | The time when the auto scaling policy was updated. Unit: milliseconds. |
AppId | String | 7171a6ca-d1cd-4928-8642-7d5cfe69**** | The application ID. |
CreateTime | Long | 1616642248938 | The time when the auto scaling policy was created. Unit: milliseconds. |
LastDisableTime | Long | 1641882854484 | The time when the auto scaling policy was last disabled. |
ScaleRuleEnabled | Boolean | true | Indicates whether the auto scaling policy is enabled. Valid values:
|
ScaleRuleType | String | timing | The type of the auto scaling policy. Valid values:
|
Metric | Object | The details of the metric-based auto scaling policy. | |
Metrics | Array of Metric | The metrics that are used to trigger the auto scaling policy. | |
MetricTargetAverageUtilization | Integer | 20 | The limit on the metric.
|
MetricType | String | CPU | The metric that is used to trigger the auto scaling policy. Valid values:
|
SlbProject | String | test | The project that stores the SLB access logs. |
SlbLogstore | String | test | The Logstore that stores the SLB access logs. |
Vport | String | 80 | The port number of the SLB instance. |
SlbId | String | lb-xxx | The ID of the SLB instance. |
MaxReplicas | Integer | 3 | The maximum number of instances. |
MinReplicas | Integer | 1 | The minimum number of instances. |
ScaleRuleName | String | test | The name of the auto scaling policy. |
Message | String | success | The returned message. Valid values:
|
ErrorCode | String | Null | The error code. Valid values:
|
Code | String | 200 | The HTTP status code. Valid values:
|
Success | Boolean | true | Indicates whether the application instances were restarted. Valid values:
|
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 code | Error code | Error message | Description |
---|---|---|---|
400 | InstanceExist.ScalingRuleName | The specified ScalingRuleName already exists. | The specified auto scaling policy name already exists. |
400 | InvalidScalingRuleDate.BeginAfterEnd | The specified beginning time is later than the ending time. | The specified start time is later than the end time. |
400 | InvalidScalingRuleDate.Format | The specified date is invalid. | The specified date is invalid. The date must be in the YYYY-MM-DD format. |
400 | InvalidScalingRuleName.NotFound | The specified ScalingRuleName does not exist. | The specified ScalingRuleName does not exist. |
400 | InvalidScalingRuleTime.Conflict | The 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. |
400 | InvalidScalingRuleTime.Format | The specified time is invalid. | The specified point in time is invalid. The point in time must be in the HH:MM format. |
400 | QuotaExceeded.ScalingRule | The maximum number of application scaling rules is exceeded. | The number of auto scaling policies for the application has reached the upper limit. |
400 | QuotaExceeded.ScalingRuleTime | The 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. |
400 | NoComputeResourceQuota.App.Exceed | You 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. |
400 | NoComputeResourceQuota.User.Exceed | Your 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. |
400 | System.Upgrading | The system is being upgraded. Please try again later. | The system is being upgraded. Try again later. |
400 | OperationDenied.SDKNotSupported | Metrics is not supported in SDK | The SDK does not support the configuration of metric-based auto scaling policies. |
400 | MinReadyInstances.Not.Smaller.Replicas | The 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. |
400 | MinReadyInstanceRatio.Invalid | The 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.