CreateApplicationScalingRule

Updated at:

Creates an elastic policy for an application.

Operation description

Before you begin

  • You can create up to 5 auto-scaling policies for a single application.

  • You can create up to 20 trigger time points within a single day for a single scheduled auto-elastic policy.

  • When an auto-elastic policy is enabled, do not manually perform application lifecycle management operations, such as scaling the application, deploying the application, changing specifications, restarting the application, or stopping the application. If you need to perform these operations, disable the auto-elastic policy first.

  • If the application is currently being scaled, deployed (in a single batch, in multiple batches, or in a canary release), having its specifications changed, restarted, or stopped, you cannot add or start an auto-elastic policy for the application.

  • If a single application needs to scale out to more than 50 instances, contact Serverless App Engine (SAE) technical support and apply for a 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 custom name of the elastic policy. The policy name must be unique within the application, start with a lowercase letter, and contain only lowercase letters, digits, and hyphens (-). It can be up to 32 characters in length.

Note

After the elastic policy is created, the policy name cannot be modified.

timer-0800-2100

ScalingRuleType

string

Yes

The type of the elastic policy. Valid values:

  • timing: scheduled elastic scaling.

  • metric: metric-based elastic scaling.

  • mix: mixed elastic scaling.

Note
  • If you select scheduled elastic scaling, the ScalingRuleTimer parameter is required.

  • If you select metric-based elastic scaling, the ScalingRuleMetric parameter is required.

  • If you select mixed elastic scaling, the ScalingRuleMetric parameter is required. You can also specify the ScalingRuleTimer and ScalingRuleMetric parameters as needed.

timing

ScalingRuleTimer

string

No

The configuration of the scheduled elastic policy. This parameter is required when you select a scheduled elastic policy or use SDK settings.

Parameter description:

  • beginDate and endDate: beginDate specifies the start date, and endDate specifies the end date. These parameters are used to configure the time range for the scheduled elastic policy. Valid values:

    • If both values are null, the policy is executed on a long-term basis. This is the default value.

    • If specific dates are specified, for example, beginDate is 2021-03-25 and endDate is 2021-04-25, the policy is valid for one month.

  • period: the epoch for executing the scheduled elastic policy. Valid values:

    • * * *: executes the scheduled policy at the specified time every day.

    • * * Fri,Mon: executes the scheduled policy at the specified time on specified days of the week. Multiple days are supported. 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 * *: executes the scheduled policy at the specified time on specified days of the month. Multiple days are supported. Valid values: [1,31]. If the current month does not have the 31st day, the scheduled policy is skipped on that day.

  • schedules: the trigger time of the elastic policy and the number of application instances to maintain during this time period. Up to 20 time points are supported. Parameters:

    • atTime: the trigger time point. The format is HH:mm, for example, 08:00.

    • targetReplicas: the number of instances for the application, or the minimum number of surviving instances for each deployment. Valid values: [1,50].
      Note

      Set the minimum number of surviving instances for each rolling deployment to a value greater than or equal to 1 to ensure service continuity. If you set this parameter to 0, services are interrupted during the application upgrade procedure.

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

ScalingRuleMetric

string

No

The configuration of the elastic policy based on monitoring metrics. This parameter is required when you select the elastic policy based on monitoring metrics.

The parameter descriptions are as follows:

  • maxReplicas: The maximum number of instances for the application.

  • minReplicas: The minimum number of instances for the application.

  • metricType: The trigger condition for the monitoring metric. Valid values:
    • CPU: CPU utilization.

    • MEMORY: Memory utilization.

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

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

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

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

    • SLB_RT: The average response time of the Internet-facing SLB within 15 seconds.

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

    • INTRANET_SLB_RT: The average response time of the internal-facing SLB within 15 seconds.

  • metricTargetAverageUtilization: The target value of the corresponding monitoring metric based on the metricType.
    • The target CPU utilization, in percentage.

    • The target memory utilization, in percentage.

    • The target QPS.

    • The response time, in milliseconds.

    • The average number of active TCP connections, in connections per second.

    • The Internet-facing SLB QPS.

    • The Internet-facing SLB response time, in milliseconds.

    • The internal-facing SLB QPS.

    • The internal-facing SLB response time, in milliseconds.

  • slbId: The ID of the SLB instance.

  • slbProject: The Simple Log Service project.

  • slbLogstore: The Simple Log Service Logstore.

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

  • scaleUpRules: The scale-up rules for the application.

  • scaleDownRules: The scale-down rules for the application.

  • step: The step size for elastic scale-up or scale-down. The maximum number of instances that can be scaled up or down per unit of time.

  • disabled: Specifies whether to disable scale-down. If enabled, the instances of the application are never scaled down. This effectively prevents business risks caused by scale-down during traffic peaks. Valid values:
    • true: Enabled.

    • false: Disabled. Default value.

  • stabilizationWindowSeconds: The cooldown period for scale-up or scale-down. Valid values: [0, 3600]. Unit: seconds. Default value: 0.

Note

You can configure one or more monitoring metrics. When multiple monitoring metrics are configured, the application scales up if any metric is greater than or equal to the target value, and the number of instances after the scale-up does not exceed the maximum number of instances for the application. If all metrics are less than the target value, the application scales down, and the number of instances after the scale-down is not less than the minimum number of instances for the application.

{"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 surviving instances. Valid values:

  • If you set this parameter to 0, services are interrupted during the application upgrade.

  • If you set this parameter to -1, the system recommended value is used, which is 25% of the current number of instances. For example, if the current number of instances is 5, 5 × 25% = 1.25. After rounding up, the minimum number of surviving instances is 2.

Note

Set the minimum number of surviving instances for each rolling deployment to a value greater than or equal to 1 to ensure service continuity.

3

MinReadyInstanceRatio

integer

No

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

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

  • 0~100: the percentage, rounded up. For example, if you set this parameter to 50 and the current number of instances is 5, the minimum number of surviving instances is 3.

Note

If both MinReadyInstance and MinReadyInstanceRatio are specified, and the value of MinReadyInstanceRatio is not -1, the MinReadyInstanceRatio parameter prevails. For example, if MinReadyInstances is set to 5 and MinReadyInstanceRatio is set to 50, the value 50 is used to calculate the minimum number of surviving instances.

-1

ScalingRuleEnable

boolean

No

Specifies whether to enable the elastic policy. Valid values:

  • true: enabled.

  • false: disabled.

true

EnableIdle

boolean

No

Specifies whether to enable the idle mode.

Response elements

Element

Type

Description

Example

object

The response information.

RequestId

string

The request ID.

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

TraceId

string

The trace ID, which is used to accurately query the call information.

0a98a02315955564772843261e****

Data

object

The returned result.

Timer

object

The scheduled elastic policy configuration.

EndDate

string

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

  • If both BeginDate and EndDate are null, the policy is executed on a long-term basis. This is the default value.

  • If specific dates are specified, for example, BeginDate is 2021-03-25 and EndDate is 2021-04-25, the policy is valid for one month.

2021-04-25

BeginDate

string

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

  • If both BeginDate and EndDate are null, the policy is executed on a long-term basis. This is the default value.

  • If specific dates are specified, for example, BeginDate is 2021-03-25 and EndDate is 2021-04-25, the policy is valid for one month.

2021-03-25

Schedules

array<object>

The trigger time points within a single day.

object

The time point data.

AtTime

string

The time point. Format: HH:mm.

08:00

TargetReplicas

integer

The number of target instances.

3

MaxReplicas

integer

The maximum number of instances.

10

MinReplicas

integer

The minimum number of instances.

5

Period

string

The epoch for executing the scheduled elastic policy. Valid values:

  • * * *: executes the scheduled policy at the specified time every day.

  • * * Fri,Mon: executes the scheduled policy at the specified time on specified days of the week. Multiple days are supported. 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 * *: executes the scheduled policy at the specified time on specified days of the month. Multiple days are supported. Valid values: [1,31]. If the current month does not have the 31st day, the scheduled policy is skipped on that day.

* * Fri,Mon

UpdateTime

integer

The time when the elastic policy was updated. Unit: milliseconds.

1616642248938

AppId

string

The application ID.

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

CreateTime

integer

The time when the elastic policy was created. Unit: milliseconds.

1616642248938

LastDisableTime

integer

The time when the elastic policy was last disabled.

1641882854484

ScaleRuleEnabled

boolean

Specifies whether the elastic policy is enabled. Valid values:

  • true: enabled.

  • false: disabled.

true

ScaleRuleType

string

The type of the elastic policy. Valid values:

  • timing: scheduled elastic scaling.

  • metric: metric-based elastic scaling.

  • mix: mixed elastic scaling.

timing

Metric

object

The metric-based elastic policy configuration.

Metrics

array<object>

The list of metric-based elastic policy configurations.

object

The monitoring metrics data.

MetricTargetAverageUtilization

integer

The target value of the monitoring metric.

  • The target CPU utilization, in percent.

  • The target memory utilization, in percent.

  • QPS.

  • Response time, in milliseconds.

  • The average number of active TCP connections, in connections per second.

  • QPS of the Internet-facing SLB.

  • Response time of the Internet-facing SLB, in milliseconds.

  • QPS of the internal-facing SLB.

  • Response time of the internal-facing SLB, in milliseconds.

20

MetricType

string

The trigger condition for the monitoring metrics. Valid values:

  • CPU: CPU utilization.

  • MEMORY: memory utilization.

  • 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 public-facing Server Load Balancer (SLB) QPS of a single instance within 15 seconds.

  • SLB_RT: the average public-Internet-facing SLB response time within 15 seconds.

  • INTRANET_SLB_QPS: the average private network SLB QPS of a single instance within 15 seconds.

  • INTRANET_SLB_RT: the average private network SLB response time within 15 seconds.

CPU

SlbProject

string

The Simple Log Service project for SLB access logs.

test

SlbLogstore

string

The Simple Log Service Logstore for SLB access logs.

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 elastic policy.

test

EnableIdle

boolean

Indicates whether the idle mode is enabled.

Message

string

The additional information. Valid values:

  • If the request is normal, success is returned.

  • If the request is abnormal, a specific error code is returned.

success

ErrorCode

string

The error code. Valid values:

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

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

InstanceExist.ScalingRuleName

Code

string

The API status code or POP error code. Valid values:

  • 2xx: success.

  • 3xx: redirection.

  • 4xx: request error.

  • 5xx: server error.

200

Success

boolean

Indicates whether the application instance was restarted successfully. Valid values:

  • true: The restart was successful.

  • false: The 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": "InstanceExist.ScalingRuleName",
  "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. The system is being upgraded. Try again later.
400 OperationDenied.SDKNotSupported Metrics is not supported in SDK The SDK does not support metric-based elastic scaling rules.
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. The minimum surviving instance ratio must be between 0 and 100.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.