All Products
Search
Document Center

Serverless App Engine:CreateApplicationScalingRule

Last Updated:Mar 17, 2026

Creates an elastic scaling policy for an application.

Operation description

Usage notes

  • You can create a maximum of 5 elastic policies for a single application.

  • For a single scheduled scaling policy, you can create a maximum of 20 trigger time points per day.

  • When an elastic policy is enabled, do not manually manage the application lifecycle. This includes scaling, deploying, changing specifications, restarting, or stopping the application. To perform these operations, you must first disable the elastic policy.

  • Do not add or enable an elastic policy for an application that is currently scaling, deploying, changing specifications, restarting, or stopping.

  • If a single application needs to scale out to more than 50 instances, contact SAE technical support and request to be added to the whitelist. For more information, see Contact us.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

sae:CreateApplicationScalingRule

create

*All Resource

*

None None

Request syntax

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

Request parameters

Parameter

Type

Required

Description

Example

AppId

string

Yes

The application ID.

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

ScalingRuleName

string

Yes

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

Note

The policy name cannot be modified after the policy is created.

timer-0800-2100

ScalingRuleType

string

Yes

The type of auto scaling policy. Valid values:

  • timing: a scheduled scaling policy.

  • metric: a metric-based scaling policy.

  • mix: a hybrid scaling policy.

Note
  • If you set the value to timing, you must configure the ScalingRuleTimer parameter.

  • If you set the value to metric, you must configure the ScalingRuleMetric parameter.

  • If you set the value to mix, you must configure the ScalingRuleMetric parameter. You can also configure the ScalingRuleTimer parameter as needed.

timing

ScalingRuleTimer

string

No

The configurations of the scheduled scaling policy. This parameter is required if you set ScalingRuleType to timing or use an SDK.

Parameter descriptions:

  • beginDate and endDate: The beginDate parameter specifies the start date and the endDate parameter specifies the end date. You can use these parameters to configure the time for a scheduled scaling policy. Valid values:

    • If you leave both parameters empty, the policy is a long-term policy. This is the default value.

    • If you specify dates for the parameters, such as 2021-03-25 for beginDate and 2021-04-25 for endDate, the policy is a short-term policy and is effective for one month.

  • period: The period in which the scheduled scaling policy is executed. Valid values:

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

    • * * Fri,Mon: The scheduled policy is executed at a specified time point on one or more specified days of the week. The days are in the GMT+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 policy is executed at a specified time point on one or more specified days of the month. You can specify multiple days. The value ranges from 1 to 31. If a month does not have the 31st day, the policy is not executed on that day.

  • schedules: The trigger of the auto scaling policy and the number of application instances that you want to maintain during that period. You can specify a maximum of 20 time points. Parameter descriptions:

    • atTime: The time point when the policy is triggered. Format: HH:mm. Example: 08:00.

    • targetReplicas
      Note

      For each rolling deployment, the minimum number of active instances should be greater than or equal to 1 to ensure business continuity. If set to 0, the application will experience service interruptions during upgrades.

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

ScalingRuleMetric

string

No

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

Parameter descriptions:

  • maxReplicas: The maximum number of application instances.

  • minReplicas: The minimum number of application instances.

  • metricType: The metric that is used to trigger the policy.
    • CPU: the CPU utilization.

    • MEMORY: the memory usage.

    • QPS: the average queries per second (QPS) of a single instance of a Java application within 1 minute.

    • RT: the average response time (RT) of all service interfaces of a Java application within 1 minute.

    • tcpActiveConn: the average number of active TCP connections of a single instance within 30 seconds.

    • SLB_QPS: the average QPS of a single instance for an Internet-facing Server Load Balancer (SLB) instance within 15 seconds.

    • SLB_RT: the average RT of an Internet-facing SLB instance within 15 seconds.

    • INTRANET_SLB_QPS: the average QPS of a single instance for an internal-facing SLB instance within 15 seconds.

    • INTRANET_SLB_RT: the average RT of an internal-facing SLB instance within 15 seconds.

  • metricTargetAverageUtilization: The target value of the metric.
    • The target CPU utilization. Unit: percentage.

    • The target memory usage. Unit: percentage.

    • The target QPS. Unit: requests per second.

    • The target RT. Unit: milliseconds.

    • The average number of active TCP connections. Unit: connections per second.

    • The QPS of an Internet-facing SLB instance. Unit: requests per second.

    • The RT of an Internet-facing SLB instance. Unit: milliseconds.

    • The QPS of an internal-facing SLB instance. Unit: requests per second.

    • The RT of an internal-facing SLB instance. Unit: milliseconds.

  • slbId: The ID of the SLB instance.

  • slbProject: The Simple Log Service project.

  • slbLogstore: The Logstore in Simple Log Service.

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

  • scaleUpRules: The scale-out rules.

  • scaleDownRules: The scale-in rules.

  • step: The step size for a scale-out or scale-in. This is the maximum number of instances that can be scaled out or in at a time.

  • disabled: Specifies whether to disable scale-in. If this parameter is set to true, scale-in is disabled. This prevents business risks that are caused by scale-in during peak hours.
    • true: enabled.

    • false: disabled. This is the default value.

  • stabilizationWindowSeconds: The cooldown period for a scale-out or scale-in. The value must be an integer from 0 to 3,600. Unit: seconds. The default value is 0.

Note

You can set one or more metrics. If you set multiple metrics, the application scales out if any of the metrics reaches its threshold. The number of instances after a scale-out cannot exceed the maximum number of application instances. The application scales in if all the metrics are below their thresholds. The number of instances after a scale-in cannot be less than the minimum number of application instances.

{"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

integer

No

The minimum number of available instances. Valid values:

  • If you set the value to 0, the application may be interrupted during an upgrade.

  • If you set the value to -1, the system recommends a value for the minimum number of available instances, which is 25% of the current number of instances. For example, if the current number of instances is 5, the minimum number of available instances is 5 × 25% = 1.25. The value is rounded up to 2.

Note

For each rolling deployment, the minimum number of available instances must be 1 or more to ensure business continuity.

3

MinReadyInstanceRatio

integer

No

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

  • -1: This is the initial value, which indicates that a percentage is not used.

  • 0 to 100: The value is a percentage that is rounded up to the nearest integer. For example, if you set the value to 50% and the current number of instances is 5, the minimum number of available instances is 3.

Note

If you specify both MinReadyInstances and MinReadyInstanceRatio, and MinReadyInstanceRatio is not -1, MinReadyInstanceRatio takes precedence. For example, if MinReadyInstances is 5 and MinReadyInstanceRatio is 50, the minimum number of available instances is calculated based on 50%.

-1

ScalingRuleEnable

boolean

No

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

  • true: enabled.

  • false: disabled.

true

EnableIdle

boolean

No

Response elements

Element

Type

Description

Example

object

The returned information.

RequestId

string

The request ID.

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

TraceId

string

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

0a98a02315955564772843261e****

Data

object

The returned result.

Timer

object

The scheduled scaling policy.

EndDate

string

The end date of the short-term scheduled scaling policy.

  • If you leave both BeginDate and EndDate empty, the policy is a long-term policy. This is the default value.

  • If you specify dates for the parameters, such as 2021-03-25 for BeginDate and 2021-04-25 for EndDate, the policy is a short-term policy and is effective for one month.

2021-04-25

BeginDate

string

The start date of the short-term scheduled scaling policy.

  • If you leave both BeginDate and EndDate empty, the policy is a long-term policy. This is the default value.

  • If you specify dates for the parameters, such as 2021-03-25 for BeginDate and 2021-04-25 for EndDate, the policy is a short-term policy and is effective for one month.

2021-03-25

Schedules

array<object>

The time points when the policy is triggered in a day.

object

The data of a time point.

AtTime

string

The time point. Format: HH:mm.

08:00

TargetReplicas

integer

The target number of instances.

3

MaxReplicas

integer

The maximum number of instances.

10

MinReplicas

integer

The minimum number of instances.

5

Period

string

The period in which the scheduled scaling policy is executed. Valid values:

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

  • * * Fri,Mon: The scheduled policy is executed at a specified time point on one or more specified days of the week. The days are in the GMT+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 policy is executed at a specified time point on one or more specified days of the month. You can specify multiple days. The value ranges from 1 to 31. If a month does not have the 31st day, the policy is not executed on that day.

* * *

UpdateTime

integer

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

1616642248938

AppId

string

The application ID.

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

CreateTime

integer

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

1616642248938

LastDisableTime

integer

The last time when the auto scaling policy was disabled.

1641882854484

ScaleRuleEnabled

boolean

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

  • true: enabled.

  • false: disabled.

true

ScaleRuleType

string

The type of auto scaling policy. Valid values:

  • timing: a scheduled scaling policy.

  • metric: a metric-based scaling policy.

  • mix: a hybrid scaling policy.

timing

Metric

object

The metric-based scaling policy.

Metrics

array<object>

The list of metric-based scaling policies.

object

The metric data.

MetricTargetAverageUtilization

integer

The target value of the metric.

  • The target CPU utilization. Unit: percentage.

  • The target memory usage. Unit: percentage.

  • The target QPS. Unit: requests per second.

  • The target RT. Unit: milliseconds.

  • The average number of active TCP connections. Unit: connections per second.

  • The QPS of an Internet-facing SLB instance. Unit: requests per second.

  • The RT of an Internet-facing SLB instance. Unit: milliseconds.

  • The QPS of an internal-facing SLB instance. Unit: requests per second.

  • The RT of an internal-facing SLB instance. Unit: milliseconds.

20

MetricType

string

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

  • CPU: the CPU utilization.

  • MEMORY: the memory usage.

  • QPS: the average QPS of a single instance of a Java application within 1 minute.

  • RT: the average RT of all service interfaces of a Java application within 1 minute.

  • tcpActiveConn: the average number of active TCP connections of a single instance within 30 seconds.

  • SLB_QPS: the average QPS of a single instance for an Internet-facing SLB instance within 15 seconds.

  • SLB_RT: the average RT of an Internet-facing SLB instance within 15 seconds.

  • INTRANET_SLB_QPS: the average QPS of a single instance for an internal-facing SLB instance within 15 seconds.

  • INTRANET_SLB_RT: the average RT of an internal-facing SLB instance within 15 seconds.

CPU

SlbProject

string

The SLB access log project.

test

SlbLogstore

string

The SLB access log Logstore.

test

Vport

string

The SLB port.

80

SlbId

string

The SLB instance ID.

lb-xxx

MaxReplicas

integer

The maximum number of instances.

3

MinReplicas

integer

The minimum number of instances.

1

ScaleRuleName

string

The name of the auto scaling policy.

test

EnableIdle

boolean

Message

string

The returned message. Valid values:

  • If the request is successful, success is returned.

  • If the request fails, an error code is returned.

success

ErrorCode

string

The error code. Valid values:

  • If the request is successful, this parameter is not returned.

  • If the request fails, this parameter is returned. For more information, see the "Error codes" section of this topic.

Code

string

The HTTP status code or an error code for the API call. Valid values:

  • 2xx: The request was successful.

  • 3xx: The request was redirected.

  • 4xx: The request was invalid.

  • 5xx: A server error occurred.

200

Success

boolean

This parameter indicates whether the application instance restarted successfully. The possible values are:

  • true: Restart successful.

  • false: Restart failed.

true

Examples

Success response

JSON format

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

Error codes

HTTP status code

Error code

Error message

Description

400 InstanceExist.ScalingRuleName The specified ScalingRuleName already exists. The specified ScalingRuleName already exists.
400 InvalidScalingRuleDate.BeginAfterEnd The specified beginning time is later than the ending time. The specified begin date is later than the end date.
400 InvalidScalingRuleDate.Format The specified date is invalid. The specified date is invalid. The correct format is yyyy-MM-dd .
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 scaling rule time is invalid. Another schedule has been set for the specified time range. Please set a different time.
400 InvalidScalingRuleTime.Format The specified time is invalid. The specified time is invalid. The correct format is HH:mm .
400 QuotaExceeded.ScalingRule The maximum number of application scaling rules is exceeded. The maximum number of application scaling rules is exceeded.
400 QuotaExceeded.ScalingRuleTime The maximum number of scaling policy trigger time is exceeded. Scaling rule time quota exceeded.
400 NoComputeResourceQuota.App.Exceed You 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.
400 NoComputeResourceQuota.Exceed Your compute resource is insufficient. Please contact us to raise the quota.
400 NoComputeResourceQuota.User.Exceed Your 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.
400 System.Upgrading The system is being upgraded. Please try again later.
400 OperationDenied.SDKNotSupported Metrics is not supported in SDK
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 must be less than the number of application instances.
400 MinReadyInstanceRatio.Invalid The ratio of minimum available instances must be between 0 and 100.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.