All Products
Search
Document Center

Serverless App Engine:CreateApplicationScalingRule

Last Updated:Dec 17, 2025

Creates an auto scaling policy for an application.

Operation description

Precautions

  • 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

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • For mandatory resource types, indicate with a prefix of * .
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
sae:CreateApplicationScalingRulecreate
*All Resources
*
    none
none

Request syntax

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

Request parameters

ParameterTypeRequiredDescriptionExample
AppIdstringYes

The application ID.

7171a6ca-d1cd-4928-8642-7d5cfe69****
ScalingRuleNamestringYes

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

Note You cannot change the names of created auto scaling policies.
timer-0800-2100
ScalingRuleTypestringYes

The type of the auto scaling policy. Take note of the following rules:

  • timing: a scheduled auto scaling policy.
  • metric: a metric-based auto scaling policy.
  • mix: a hybrid auto scaling policy.
Note
  • If you set this parameter to timing, the ScalingRuleTimer parameter must be specified.

  • If you set this parameter to metric, the ScalingRuleMetric parameter must be specified.

  • If you set this parameter to mix, the ScalingRuleMetric parameter must be specified. You can specify the ScalingRuleTimer parameter based on your business requirements.

timing
ScalingRuleTimerstringNo

The configuration of the scheduled elasticity policy. This parameter is required if you select Scheduled Scaling Policy or Use SDK to Set.

The following table describes the parameters.

  • beginDate and endDate: beginDate is the start date and endDate is the end date, which is used to configure the timing Auto Scaling policy. Valid values:

    • If both values are null, long-term execution is performed. This is the default value.
    • If the value is a specific date, for example, the beginDate is 2021-03-25 and the endDate is 2021-04-25, the validity period is one month.
  • period: The period during which the timed Auto Scaling policy is executed. Valid values:

    • * * *: The scheduled policy is executed at a specified time every day.

    • * * Fri,Mon: The scheduled policy is executed at the specified time on the specified number of days per week. You can select multiple time zones. The time zone is GMT +8. 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 points in time at which the scheduled auto scaling policy is triggered and the number of application instances that are retained during the time periods. You can specify up to 20 points in time. The following list describes the involved parameters:

    • atTime: the point in time at which the policy is triggered. targetReplicas: the number of application instances that you want to retain during the corresponding time period or the minimum number of available instances required for each deployment.****

    • Valid values: 1 to 50. Valid values: 1 to 50.

      **

      NoteMake sure that at least one instance is available during the application deployment and rollback to prevent your business from being interrupted. If you set the value to 0, business interruptions occur when the application is updated. If you set the value to 0, business interruptions occur when the application is updated.

{"beginDate":null,"endDate":null,"period":"* * *","schedules":[{"atTime":"08:00","targetReplicas":10},{"atTime":"20:00","targetReplicas":3}]}
ScalingRuleMetricstringNo

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

The following list describes the involved parameters:

  • 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 QPS within 1 minute per Java application instance.
    • RT: the average response time of all API operations within 1 minute in the Java application.
    • tcpActiveConn: the average number of active TCP connections within 30 seconds per instance.
    • SLB_QPS: the average QPS of the Internet-facing SLB instance within 15 seconds per instance.
    • 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 within 15 seconds per instance.
    • 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 metricType. You can specify following limits:

    • The limit on the CPU utilization. Unit: percentage.
    • The limit on the memory usage. Unit: percentage.
    • The limit on the QPS.
    • The limit on the response time. Unit: milliseconds.
    • The limit on the average number of active TCP connections per second.
    • The limit on the QPS of the Internet-facing SLB instance.
    • 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.
    • The limit on the response time of the internal-facing SLB instance. Unit: milliseconds.
  • slbId: the ID of the SLB instance.

  • slbProject: the Simple Log Service (SLS) project.

  • slbLogstore: the SLS Logstore.

  • vport: the listener port of the SLB instance. HTTP and HTTPS are supported.

  • scaleUpRules: the scale-out rules.

  • 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. Default value: false.
  • 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 NoteYou 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.
{"maxReplicas":3,"minReplicas":1,"metrics":[{"metricType":"CPU","metricTargetAverageUtilization":20},{"metricType":"MEMORY","metricTargetAverageUtilization":30},{"metricType":"tcpActiveConn","metricTargetAverageUtilization":20},{"metricType":"SLB_QPS","MetricTargetAverageUtilization":25,"SlbProject":"aliyun-fc-cn-hangzhou-d95881d9-5d3c-5f26-a6b8-************","SlbLogstore":"function-log","Vport":"80"},{"metricType":"SLB_RT","MetricTargetAverageUtilization":35,"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}}
MinReadyInstancesintegerNo

The minimum number of available instances. Special values:

  • If you set the value to 0, business is interrupted when the application is updated.
  • If you set this property to -1, the system calculates a recommended value as the minimum number of available instances by using the following formula: Recommended value = Number of existing instances × 25%. The calculation result is rounded up to the nearest integer. For example, if the number of existing instances is 5, the recommended value 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.
3
MinReadyInstanceRatiointegerNo

The percentage of the minimum number of available instances. Valid values:

  • -1 (default value): The minimum number of available instances is not determined based on this parameter.
  • 0 to 100: The minimum number of available instances is calculated by using the following formula: Number of existing instances × Value of MinReadyInstanceRatio × 100%. The calculation result is rounded up to the nearest integer. For example, if the number of existing instances is 5 and MinReadyInstanceRatio is set to 50, the minimum number of available instances is 3.
Note When MinReadyInstance and MinReadyInstanceRatio are passed at the same time and the MinReadyInstanceRatio value is not **-1**, the MinReadyInstanceRatio parameter takes precedence. NoteWhen both MinReadyInstance and MinReadyInstanceRatio are specified and MinReadyInstanceRatio is set to a number from 0 to 100, the value of MinReadyInstanceRatio takes precedence.
-1
ScalingRuleEnablebooleanNo

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

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

Response parameters

ParameterTypeDescriptionExample
object

The returned information.

RequestIdstring

Request ID.

91F93257-7A4A-4BD3-9A7E-2F6EAE6D****
TraceIdstring

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

0a98a02315955564772843261e****
Dataobject

The returned result.

Timerobject

The details of the scheduled auto scaling policy.

EndDatestring

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

  • null (default): If you set BeginDate and EndDate to null, the scheduled auto scaling policy can always be triggered.
  • 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 BeginDate is set to 2021-03-25 and EndDate is set to 2021-04-25, the auto scaling policy is valid for one month.
2021-04-25
BeginDatestring

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

  • null (default): If you set BeginDate and EndDate to null, the scheduled auto scaling policy can always be triggered.
  • 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 BeginDate is set to 2021-03-25 and EndDate is set to 2021-04-25, the auto scaling policy is valid for one month.
2021-03-25
Schedulesarray<object>

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

Scheduleobject

The information about the point in time.

AtTimestring

The point in time. Format: Hour:Minute.

08:00
TargetReplicasinteger

The expected number of instances.

3
MaxReplicasinteger

The maximum number of instances.

10
MinReplicasinteger

The minimum number of instances.

5
Periodstring

The days on which the scheduled auto scaling policy takes effect. 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 days every week. The time must be in GMT+8. 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.

* * *
UpdateTimelong

null null

1616642248938
AppIdstring

null

7171a6ca-d1cd-4928-8642-7d5cfe69****
CreateTimelong

null null

1616642248938
LastDisableTimelong

null

1641882854484
ScaleRuleEnabledboolean

null null

  • null
  • null
true
ScaleRuleTypestring

null null

  • null
  • metric: a metric-based auto scaling policy.
  • mix: a hybrid auto scaling policy.
timing
Metricobject

The details of the metric-based auto scaling policy.

Metricsarray<object>

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

Metricobject

The information about the metric.

MetricTargetAverageUtilizationinteger

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 queries per second (QPS). Unit: seconds.
  • The limit on the response time. Unit: milliseconds.
  • The limit on the average number of active TCP connections per second.
  • The limit on the QPS of the Internet-facing SLB instance.
  • 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.
  • The limit on the response time of the internal-facing SLB instance. Unit: milliseconds.
20
MetricTypestring

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

  • CPU: the CPU utilization.
  • MEMORY: the memory usage.
  • QPS: the average QPS within 1 minute per Java application instance.
  • RT: the average response time of all API operations within 1 minute in the Java application.
  • tcpActiveConn: the average number of active TCP connections within 30 seconds per instance.
  • SLB_QPS: the average QPS of the Internet-facing SLB instance within 15 seconds per instance.
  • 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 within 15 seconds per instance.
  • INTRANET_SLB_RT: the average response time of the internal-facing SLB instance within 15 seconds.
CPU
SlbProjectstring

The project that stores the SLB access logs.

test
SlbLogstorestring

The Logstore that stores the SLB access logs.

test
Vportstring

The port number of the SLB instance.

80
SlbIdstring

The ID of the SLB instance.

lb-xxx
MaxReplicasinteger

The maximum number of Elastic Compute Service (ECS) instances supported by the node pool.

3
MinReplicasinteger

The minimum number of instances.

1
ScaleRuleNamestring

The name of the auto scaling policy.

test
Messagestring

The message returned. The following limits are imposed on the ID:

  • If the request was successful, success is returned.
  • An error code is returned when a request failed.
success
ErrorCodestring

The status code. Value values:

  • If the request was successful, ErrorCode is not returned.
  • If the request failed, ErrorCode is returned. For more information, see Error codes in this topic.
Codestring

The HTTP status code or the error code. Valid values:

  • 2xx: The request was successful.
  • 3xx: The request was redirected.
  • 4xx: The request failed.
  • 5xx: A server error occurred.
200
Successboolean

Indicates whether the application instances were restarted. Valid values:

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

Examples

Sample success responses

JSONformat

{
  "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",
    "EnableIdle": true
  },
  "Message": "success",
  "ErrorCode": "",
  "Code": 200,
  "Success": true
}

Error codes

HTTP status codeError codeError messageDescription
400InstanceExist.ScalingRuleNameThe specified ScalingRuleName already exists.The specified ScalingRuleName already exists.
400InvalidScalingRuleDate.BeginAfterEndThe specified beginning time is later than the ending time.The specified begin date is later than the end date.
400InvalidScalingRuleDate.FormatThe specified date is invalid.The specified date is invalid. The correct format is yyyy-MM-dd .
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 scaling rule time is invalid. Another schedule has been set for the specified time range. Please set a different time.
400InvalidScalingRuleTime.FormatThe specified time is invalid.The specified time is invalid. The correct format is HH:mm .
400QuotaExceeded.ScalingRuleThe maximum number of application scaling rules is exceeded.The maximum number of application scaling rules is exceeded.
400QuotaExceeded.ScalingRuleTimeThe maximum number of scaling policy trigger time is exceeded.Scaling rule time quota exceeded.
400NoComputeResourceQuota.App.ExceedYou can create %s instances for each application. Please submit a ticket to raise the quota.You can create %s instances for each application. please join the DingTalk group 32874633 for technical support.
400NoComputeResourceQuota.ExceedYour compute resource is insufficient. Please contact us to raise the quota.-
400NoComputeResourceQuota.User.ExceedYour account is limited to create %s instances. Please submit a ticket to raise the quota.Your account is limited to create %s instances. please join the DingTalk group 32874633 for technical support.
400System.UpgradingThe system is being upgraded. Please try again later.-
400OperationDenied.SDKNotSupportedMetrics is not supported in SDK-
400MinReadyInstances.Not.Smaller.ReplicasThe minimum number of available instances must be less than the number of application instances.The minimum number of available instances must be less than the number of application instances.
400MinReadyInstanceRatio.InvalidThe ratio of minimum available instances must be between 0 and 100.-

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2024-08-30The Error code has changed. The request parameters of the API has changed. The response structure of the API has changedView Change Details
2023-05-24The Error code has changed. The response structure of the API has changedView Change Details
2023-05-23The Error code has changed. The response structure of the API has changedView Change Details
2022-12-19The Error code has changed. The response structure of the API has changedView Change Details