CreateApplicationScalingRule

更新时间:
复制 MD 格式

Create an application auto scaling policy.

Operation description

Usage notes

  • You can create up to five elasticity policies per application.

  • For each scheduled elasticity policy, you can create up to 20 trigger points per day.

  • While an elasticity policy is enabled, do not manually perform operations on the application, such as scaling, deployment, changing specifications, restarting, or stopping. To perform these operations, disable the policy first.

  • You cannot add or enable an elasticity policy for an application that is undergoing a scale-out, scale-in, deployment (single-batch, phased, or canary), specification change, restart, or stop.

  • To scale out an application to more than 50 instances, contact SAE technical support 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, start with a lowercase letter, and contain only lowercase letters, digits, and hyphens (-). The name can be up to 32 characters long.

Note

The policy name cannot be changed after creation.

timer-0800-2100

ScalingRuleType

string

Yes

The type of the auto scaling policy. Valid values:

  • timing: scheduled auto scaling.

  • metric: metric-based auto scaling.

  • mix: mixed auto scaling.

Note
  • If you set this parameter to timing, the ScalingRuleTimer parameter is required.

  • If you set this parameter to metric, the ScalingRuleMetric parameter is required.

  • If you set this parameter to mix, the ScalingRuleMetric parameter is required. You can also configure the ScalingRuleTimer parameter as needed.

timing

ScalingRuleTimer

string

No

Configurations for the scheduled auto scaling policy. This parameter is required if ScalingRuleType is set to timing or if you use an SDK.

The parameter is a JSON string that contains the following fields:

  • beginDate and endDate: The start and end dates of the policy's effective period.

    • If both fields are set to null (default), the policy is effective indefinitely.

    • If you specify a date range, for example, beginDate is 2021-03-25 and endDate is 2021-04-25, the policy is effective for one month.

  • period: The recurrence rule for the scheduled auto scaling policy.

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

    • * * Fri,Mon: The policy is executed at a specified time on specific days of the week. You can select multiple days. The time is 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 policy is executed at a specified time on specific days of a month. You can select multiple days. The value can be from 1 to 31. If a month does not have the specified day, for example, the 31st, the policy is not executed on that day for that month.

  • schedules: The trigger times and the corresponding target number of instances. You can specify a maximum of 20 schedules. The parameter includes the following fields:

    • atTime: The trigger time in HH:mm format. For example, 08:00.

    • targetReplicas: The target number of application instances. Valid values: 1 to 50.
      Note

      During a rolling deployment, we recommend that you set the minimum number of ready instances to 1 or more to prevent service interruptions. If you set the minimum number of ready instances to 0, your application will be interrupted during an update.

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

ScalingRuleMetric

string

No

Configurations for the metric-based auto scaling policy. This parameter is required if ScalingRuleType is set to metric or mix.

The parameter is a JSON string that contains the following fields:

  • maxReplicas: The maximum number of application instances.

  • minReplicas: The minimum number of application instances.

  • metricType: The metric that triggers the auto scaling policy. Valid values:
    • CPU: CPU utilization.

    • MEMORY: Memory utilization.

    • QPS: The average queries per second (QPS) per instance for a Java application over a 1-minute period.

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

    • tcpActiveConn: The average number of active TCP connections per instance over a 30-second period.

    • SLB_QPS: The average QPS per instance for a public-facing SLB instance over a 15-second period.

    • SLB_RT: The average RT of a public-facing SLB instance over a 15-second period.

    • INTRANET_SLB_QPS: The average QPS per instance for an internal-facing SLB instance over a 15-second period.

    • INTRANET_SLB_RT: The average RT of an internal-facing SLB instance over a 15-second period.

  • metricTargetAverageUtilization: The target value for the metric specified by metricType. The unit of this value depends on metricType.
    • Target CPU utilization, in percentage.

    • Target memory utilization, in percentage.

    • Target QPS, in requests per second.

    • Target response time, in milliseconds.

    • Average number of active TCP connections.

    • Target public-facing SLB QPS, in requests per second.

    • Target public-facing SLB response time, in milliseconds.

    • Target internal-facing SLB QPS, in requests per second.

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

  • slbId: The SLB instance ID.

  • slbProject: The Log Service project.

  • slbLogstore: The Log Service Logstore.

  • vport: The SLB listener port. The HTTP and HTTPS protocols are supported.

  • scaleUpRules: The rules to scale out the application.

  • scaleDownRules: The rules to scale in the application.

  • step: The step size for scaling out or scaling in. This is the maximum number of instances that can be added or removed in a single scaling activity.

  • disabled: Specifies whether to prevent the application from scaling in. If set to true, the number of application instances is never reduced. This can prevent business risks caused by scaling in during peak hours.
    • true: Scale-in is disabled.

    • false: Scale-in is enabled. This is the default value.

  • stabilizationWindowSeconds: The cooldown period for scaling out or scaling in, in seconds. Valid values: 0 to 3600. The default value is 0.

Note

You can configure one or more metrics. If you configure multiple metrics, the application scales out when any of the metrics meets or exceeds its target value, up to the specified maximum number of instances. The application scales in only when all metrics are below their target values, down to the specified minimum number of 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 ready instances. Valid values:

  • If you set this parameter to 0, the application is interrupted during an update.

  • If you set this parameter to -1, the system sets the value to 25% of the current number of instances, rounded up. For example, if the application has 5 instances, the minimum number of ready instances is 2 (5 × 25% = 1.25, rounded up to 2).

Note

To ensure service continuity during a rolling deployment, we recommend setting the minimum number of ready instances to 1 or more.

3

MinReadyInstanceRatio

integer

No

The minimum number of ready instances, specified as a percentage of the total number of instances. Valid values:

  • -1: Indicates that a percentage is not used. In this case, the value of MinReadyInstances is used.

  • 0~100: A percentage. The result is rounded up. For example, if you set this parameter to 50 (%) and the application has 5 instances, the minimum number of ready instances is 3.

Note

If you specify both MinReadyInstances and a MinReadyInstanceRatio other than -1, MinReadyInstanceRatio takes precedence. For example, if MinReadyInstances is set to 5 and MinReadyInstanceRatio is set to 50, the system uses 50 (%) to calculate the minimum number of ready instances.

-1

ScalingRuleEnable

boolean

No

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

  • true: Enabled.

  • false: Disabled.

true

EnableIdle

boolean

No

Specifies whether to enable idle mode for the application.

Response elements

Element

Type

Description

Example

object

The response object.

RequestId

string

The request ID.

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

TraceId

string

The trace ID. You can use this ID to query the details of a request.

0a98a02315955564772843261e****

Data

object

The returned data.

Timer

object

The configurations for the scheduled auto scaling policy.

EndDate

string

The end date of the scheduled auto scaling policy.

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

  • For example, if you set BeginDate to 2021-03-25 and EndDate to 2021-04-25, the policy is active for one month.

2021-04-25

BeginDate

string

The start date of the scheduled auto scaling policy.

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

  • For example, if you set BeginDate to 2021-03-25 and EndDate to 2021-04-25, the policy is active for one month.

2021-03-25

Schedules

array<object>

The trigger points for the scheduled auto scaling policy.

object

The configuration for a single trigger within the schedule.

AtTime

string

The trigger time. The format is 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 recurrence pattern for the scheduled auto scaling policy. Valid values:

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

  • * * Fri,Mon: The policy is executed at a specified time on specific days of the week. You can select multiple days. The time is 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 policy is executed at a specified time on specific days of a month. You can select multiple days. The value can be from 1 to 31. If a specified day does not exist in a given month (for example, the 31st), the policy is not executed on that day.

* * *

UpdateTime

integer

The time when the policy was last updated, in milliseconds.

1616642248938

AppId

string

The ID of the application.

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

CreateTime

integer

The time when the policy was created, in milliseconds.

1616642248938

LastDisableTime

integer

The time when the auto scaling policy was last disabled, in milliseconds.

1641882854484

ScaleRuleEnabled

boolean

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

  • true: The policy is enabled.

  • false: The policy is disabled.

true

ScaleRuleType

string

The type of the auto scaling policy. Valid values:

  • timing: scheduled auto scaling.

  • metric: metric-based auto scaling.

  • mix: mixed auto scaling.

timing

Metric

object

The configurations for the metric-based auto scaling policy.

Metrics

array<object>

An array of objects that define the metrics for the metric-based auto scaling policy.

object

The configuration for a single metric.

MetricTargetAverageUtilization

integer

The target value for the metric.

  • The target CPU utilization, in percentage.

  • The target memory utilization, in percentage.

  • The target QPS.

  • The target response time, in milliseconds.

  • The target average number of active TCP connections per second.

  • The target QPS for a public-facing SLB instance.

  • The target response time for a public-facing SLB instance, in milliseconds.

  • The target QPS for an internal-facing SLB instance.

  • The target response time for an internal-facing SLB instance, in milliseconds.

20

MetricType

string

The type of the metric that triggers the auto scaling policy. Valid values:

  • CPU: CPU utilization.

  • MEMORY: memory utilization.

  • QPS: The average QPS per instance over 1 minute for a Java application.

  • RT: The average response time across all service endpoints over 1 minute for a Java application.

  • tcpActiveConn: The average number of TCP active connections per instance over 30 seconds.

  • SLB_QPS: The average QPS per instance for a public SLB instance, measured over 15 seconds.

  • SLB_RT: The average response time for a public SLB instance, measured over 15 seconds.

  • INTRANET_SLB_QPS: The average QPS per instance for an internal-facing SLB instance, measured over 15 seconds.

  • INTRANET_SLB_RT: The average response time for an internal-facing SLB instance, measured over 15 seconds.

CPU

SlbProject

string

The Log Service project for SLB access logs.

test

SlbLogstore

string

The Log Service Logstore for SLB access logs.

test

Vport

string

The port of the SLB instance.

80

SlbId

string

The ID of the SLB instance.

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

Indicates whether idle mode is enabled.

Message

string

The response message. Valid values:

  • Returns success if the request is successful.

  • Returns an error message if the request fails.

success

ErrorCode

string

The error code. Valid values:

  • This parameter is not returned if the request is successful.

  • An error code is returned if the request fails. For more information, see the Error codes section in this topic.

Code

string

The HTTP status code. Valid values:

  • 2xx: The request was successful.

  • 3xx: The request was redirected.

  • 4xx: A client error occurred.

  • 5xx: A server error occurred.

200

Success

boolean

Indicates whether the request was successful. Valid values:

  • true: The API call was successful.

  • false: The API call 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.