All Products
Search
Document Center

Auto Scaling:CreateScalingRule

Last Updated:Feb 28, 2025

A scaling rule's purpose is defined by its type and can be used to initiate a scaling activity or to intelligently define boundary values for a scaling group. You can use the CreateScalingRule API operation to establish various types of scaling rules to meet your business needs. For instance, to set boundary values for a scaling group, you might create a predictive scaling rule.

API Description

Consider the following parameters:

  • When AdjustmentType is set to TotalCapacity, the total number of ECS instances or elastic container instances in the scaling group is adjusted to a specified number. AdjustmentValue must be an integer that is greater than or equal to 0.
  • When AdjustmentType is set to QuantityChangeInCapacity or PercentChangeInCapacity, a positive AdjustmentValue adds a specific number of instances, while a negative value removes them.
  • For PercentChangeInCapacity, Auto Scaling calculates the number of ECS instances or elastic container instances to add or remove by multiplying the current capacity of the scaling group (Total Capacity) by the AdjustmentValue percentage, rounding the result to the nearest whole number.
  • Specifying a cooldown period (Cooldown) for a scaling rule means that period takes effect after the rule is applied. If no cooldown period is specified, the scaling group's default cooldown period (DefaultCooldown) applies after the rule is applied.
  • There is a limit to the number of scaling rules you can create within a scaling group. For more information, see Limits.
  • The unique identifier of the scaling rule (ScalingRuleAri) returned can be used in the following operations:
    • As the ScalingRuleAri parameter in the ExecuteScalingRule operation to manually execute the scaling rule.
    • As the ScheduledAction parameter in the CreateScheduledTask operation to schedule the scaling rule's execution.

Debugging

Run this operation directly in OpenAPI Explorer to avoid calculating signatures. OpenAPI Explorer can also automatically generate SDK code samples after a successful run.

Request parameters

Name

Type

Required

Example

Description

Action String Yes CreateScalingRule

Required parameter. Valid value: CreateScalingRule.

ScalingGroupId String Yes asg-bp1ffogfdauy0jw0****

The ID of the scaling group to which the scaling rule belongs.

ScalingRuleName String No scalingrule****

The name of the scaling rule. It must be 2 to 64 characters in length, and can contain letters, digits, underscores (_), hyphens (-), and periods (.). The name must start with a letter or a digit.

The name of each scaling rule must be unique within the same account and region.

Note If you do not specify this parameter, the value of the ScalingRuleId parameter is used.
Cooldown Integer No 60

The cooldown period of the scaling rule. This parameter is available only if you set ScalingRuleType to SimpleScalingRule. Valid values: 0 to 86400. Unit: seconds.

By default, this parameter is empty.

MinAdjustmentMagnitude Integer No 1

The minimum number of instances that must be scaled. This is effective only when the scaling rule type is SimpleScalingRule or StepScalingRule, and AdjustmentType is PercentChangeInCapacity.

AdjustmentType String No QuantityChangeInCapacity

The adjustment method of the scaling rule. This parameter is required only if you set ScalingRuleType to SimpleScalingRule or StepScalingRule. Valid values:

  • QuantityChangeInCapacity: adds a specific number of ECS instances to or removes a specific number of ECS instances from the scaling group.
  • PercentChangeInCapacity: adds a specific percentage of ECS instances to or removes a specific percentage of ECS instances from the scaling group.
  • TotalCapacity: adjusts the number of ECS instances in the scaling group to a specified number.
AdjustmentValue Integer No 100

The number of instances that must be scaled based on the scaling rule. This parameter is required only if you set ScalingRuleType to SimpleScalingRule or StepScalingRule. The number of ECS instances that can be added or removed in a single scaling operation cannot exceed 1,000. Valid values vary based on the value of AdjustmentType:

  • QuantityChangeInCapacity: -1000 to 1000.
  • PercentChangeInCapacity: -100 to 10000.
  • TotalCapacity: 0 to 2000.
ScalingRuleType String No SimpleScalingRule

The type of the scaling rule. Valid values:

  • SimpleScalingRule: a simple scaling rule. After you apply a simple scaling rule, Auto Scaling adjusts the number of ECS instances or elastic container instances in the scaling group based on the values of AdjustmentType and AdjustmentValue.
  • TargetTrackingScalingRule: a target tracking scaling rule. After you apply a target tracking scaling rule, Auto Scaling dynamically calculates the number of ECS instances or elastic container instances to scale based on a predefined metric (MetricName) and attempts to maintain the metric value close to the specified target value (TargetValue).
  • StepScalingRule: a step scaling rule. After you apply a step scaling rule, Auto Scaling scales instances step by step based on predefined thresholds and metric values.
  • PredictiveScalingRule: a predictive scaling rule. After you apply a predictive scaling rule, Auto Scaling uses machine learning to analyze historical monitoring data of the scaling group and predicts the future values of metrics. In addition, Auto Scaling automatically creates scheduled tasks to specify the boundary values for the scaling group.

Default value: SimpleScalingRule.

EstimatedInstanceWarmup Integer No 300

The warmup period of an instance. This parameter is available only if you set ScalingRuleType to TargetTrackingScalingRule or StepScalingRule. ECS instances that are in the Warmup state are added to a scaling group but do not report monitoring data to CloudMonitor during the warmup period.

Note When Auto Scaling calculates the number of ECS instances that must be scaled, ECS instances in the Warmup state are not counted toward the current capacity of the scaling group.

Valid values: 0 to 86400. Unit: seconds.

Default value: 300.

MetricName String No CpuUtilization

The predefined metric that you want to monitor. This parameter is valid and required only when the ScalingRuleType parameter is set to TargetTrackingScalingRule or PredictiveScalingRule.

Valid values for target tracking scaling rules:

  • CpuUtilizationAgent (recommended): the CPU utilization.
  • MemoryUtilization (recommended): the memory usage.
  • CpuUtilization: the average CPU utilization.
  • IntranetTx: the average outbound traffic over an internal network.
  • IntranetRx: the average inbound traffic over an internal network.
  • VpcInternetTx: the average outbound traffic from a virtual private cloud (VPC) to the Internet.
  • VpcInternetRx: the average inbound traffic from the Internet to a VPC.
  • LoadBalancerRealServerAverageQps: the queries per second (QPS) per Application Load Balancer (ALB) server group.

Valid values for predictive scaling rules:

  • CpuUtilization: the average CPU utilization.
  • IntranetRx: the average inbound traffic over an internal network.
  • IntranetTx: the average outbound traffic over an internal network.

For more information, see system monitoring alert tasks.

TargetValue Float No 0.125

The target value. This parameter is required only if you set the ScalingRuleType parameter to TargetTrackingScalingRule or PredictiveScalingRule. The value must be greater than 0 and can have up to three decimal places.

DisableScaleIn Boolean No false

Specifies whether to disable scale-in. This parameter is available only if you set ScalingRuleType to TargetTrackingScalingRule.

Default value: false.

ScaleInEvaluationCount Integer No 15

After you create a target tracking scaling rule, an event-triggered task is automatically created. This parameter defines the number of consecutive times the alert condition must be satisfied before the event-triggered task initiates a scale-in operation.

Default value: 15.

ScaleOutEvaluationCount Integer No 3

After you create a target tracking scaling rule, an event-triggered task is automatically created. This parameter defines the number of consecutive times the alert condition must be satisfied before the event-triggered task initiates a scale-out operation.

Default value: 3.

PredictiveScalingMode String No PredictAndScale

The mode of the predictive scaling rule. Valid values:

  • PredictAndScale: provides predictions and creates prediction tasks.
  • PredictOnly: provides predictions but does not create prediction tasks.

Default value: PredictAndScale.

PredictiveValueBehavior String No MaxOverridePredictiveValue

The action on the predicted maximum value. Valid values:

  • MaxOverridePredictiveValue: uses the initial maximum capacity as the maximum value for prediction tasks if the predicted value is greater than the initial maximum capacity.
  • PredictiveValueOverrideMax: uses the predicted value as the maximum value for prediction tasks if the predicted value is greater than the initial maximum capacity.
  • PredictiveValueOverrideMaxWithBuffer: increases the predicted value by a percentage that is specified by the PredictiveValueBuffer parameter, and uses the increased value as the maximum value for prediction tasks if the predicted value increased by this percentage is greater than the initial maximum capacity.

Default value: MaxOverridePredictiveValue.

PredictiveValueBuffer Integer No 50

The PredictiveValueBehavior takes effect when it is set to PredictiveValueOverrideMaxWithBuffer. The predictive value will increase according to this ratio. If the increased value is greater than the initial maximum value, the increased value will be used. The value range is 0 to 100.

Default value: 0.

PredictiveTaskBufferTime Integer No 30

The amount of buffer time before prediction tasks are executed. By default, all prediction tasks that are automatically created for a predictive scaling rule are executed on the hour. You can specify an amount of buffer time for resource preparation before prediction tasks are executed. Valid values: 0 to 60. Unit: minutes.

Default value: 0.

InitialMaxSize Integer No 100

The maximum number of ECS instances that can be contained in the scaling group. If you specify InitialMaxSize, you must specify PredictiveValueBehavior.

The default value of this parameter is the value of the MaxSize parameter.

StepAdjustment.N.MetricIntervalUpperBound Float No 5.0

The upper limit value specified in a step adjustment. This parameter is available only if you set ScalingRuleType to StepScalingRule. Valid values: -9.999999E18 to 9.999999E18.

StepAdjustment.N.ScalingAdjustment Integer No 1

The number of ECS instances that you want to scale in each step adjustment. This parameter is available only if you set ScalingRuleType to StepScalingRule.

StepAdjustment.N.MetricIntervalLowerBound Float No 1.0

The lower limit value specified in a step adjustment. This parameter is available only if you set ScalingRuleType to StepScalingRule. Valid values: -9.999999E18 to 9.999999E18.

RegionId String No cn-hangzhou

The region ID of the scaling group.

AlarmDimension.N.DimensionKey String No rulePool

The key of the dimension that is associated with the metric.

AlarmDimension.N.DimensionValue String No sgp-l1cbirz451yxu2****

The value of the dimension that is associated with the metric.

MetricType String No system

The type of the metric. Valid values:

  • system: system metrics of CloudMonitor.
  • custom: custom metrics that are reported to CloudMonitor.
  • hybrid: metrics of Hybrid Cloud Monitoring.
HybridMonitorNamespace String No aliyun-test

The ID of the Hybrid Cloud Monitoring metric repository.

For more information about how to manage metric repositories, see manage metric repositories.

HybridMetrics.N.Id String No a

The reference ID of the metric in the metric expression.

HybridMetrics.N.Expression String No (a+b)/2

The metric expression that consists of multiple Hybrid Cloud Monitoring metrics. It calculates a result used to trigger scaling events.

The expression must comply with the Reverse Polish Notation (RPN) specification, and the operators can only be + - × /.

HybridMetrics.N.MetricName String No AliyunSmq_NumberOfMessagesVisible

The name of the Hybrid Cloud Monitoring metric.

HybridMetrics.N.Statistic String No Average

The statistical method of the metric value. Valid values:

  • Average: calculates the average value of all metric values within a specified interval.
  • Minimum: calculates the minimum value of all metric values within a specified interval.
  • Maximum: calculates the maximum value of all metric values within a specified interval.
HybridMetrics.N.Dimensions.N.DimensionKey String No queue

The key of the metric dimension.

HybridMetrics.N.Dimensions.N.DimensionValue String No testQueue

The value of the metric dimension.

Return data

Name

Type

Example

Description

ScalingRuleAri String ari:acs:ess:cn-hangzhou:140692647406****:scalingrule/asr-bp1dvirgwkoowxk7****

The unique identifier of the scaling rule.

RequestId String 473469C7-AA6F-4DC5-B3DB-A3DC0DE3****

The ID of the request.

ScalingRuleId String asr-bp1dvirgwkoowxk7****

The ID of the scaling rule, which is generated by the system and is globally unique.

Examples

Request example

http(s)://ess.aliyuncs.com/?Action=CreateScalingRule
&ScalingGroupId=asg-bp1ffogfdauy0jw0****
&ScalingRuleName=scalingrule****
&Cooldown=60
&MinAdjustmentMagnitude=1
&AdjustmentType=QuantityChangeInCapacity
&AdjustmentValue=100
&ScalingRuleType=SimpleScalingRule
&EstimatedInstanceWarmup=300
&MetricName=CpuUtilization
&TargetValue=0.125
&DisableScaleIn=false
&ScaleInEvaluationCount=15
&ScaleOutEvaluationCount=3
&PredictiveScalingMode=PredictAndScale
&PredictiveValueBehavior=MaxOverridePredictiveValue
&PredictiveValueBuffer=50
&PredictiveTaskBufferTime=30
&InitialMaxSize=100
&StepAdjustment=[{"MetricIntervalUpperBound":5.0,"ScalingAdjustment":1,"MetricIntervalLowerBound":1.0}]
&RegionId=cn-hangzhou
&AlarmDimension=[{"DimensionKey":"rulePool","DimensionValue":"sgp-l1cbirz451yxu2****"}]
&MetricType=system
&HybridMonitorNamespace=aliyun-test
&HybridMetrics=[{"Id":"a","MetricName":"AliyunSmq_NumberOfMessagesVisible","Statistic":"Average","Dimensions":[{"DimensionKey":"queue","DimensionValue":"testQueue"}]}]
&公共请求参数

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateScalingRuleResponse>
    <ScalingRuleAri>ari:acs:ess:cn-hangzhou:140692647406****:scalingrule/asr-bp1dvirgwkoowxk7****</ScalingRuleAri>
    <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3****</RequestId>
    <ScalingRuleId>asr-bp1dvirgwkoowxk7****</ScalingRuleId>
</CreateScalingRuleResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "ScalingRuleAri" : "ari:acs:ess:cn-hangzhou:140692647406****:scalingrule/asr-bp1dvirgwkoowxk7****",
  "RequestId" : "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****",
  "ScalingRuleId" : "asr-bp1dvirgwkoowxk7****"
}

Error codes

Visit the Error Center for more error codes.

HttpCode

Error code

Error message

Description

404

InvalidScalingGroupId.NotFound

The specified scaling group does not exist.

The specified scaling group does not exist within the Alibaba Cloud account.

400

InvalidScalingRuleName.Duplicate

The specified value of parameter <parameter name> is duplicated.

The error message returned because the specified scaling rule name already exists.

400

QuotaExceeded.ScalingRule

Scaling rule quota exceeded in the specified scaling group.

The maximum number of scaling rules in the scaling group has been reached.

400

TargetTrackingScalingRule.UnsupportedMetric

Specific metric is not supported for target tracking scaling rule.

The target tracking scaling rule does not support the specified metric.

400

TargetTrackingScalingRule.DumplicateMetric

Only one TargetTrackingScaling rule for a given metric specification is allowed.

The error message returned because the metric is already specified for a target tracking scaling rule in the scaling group.

400

InvalidMinAdjustmentMagnitudeMismatchAdjustmentType

MinAdjustmentMagnitude is not supported by the specified adjustment type.

The error message returned because MinAdjustmentMagnitude cannot take effect for the adjustment method of the scaling rule.

400

InvalidStepAdjustments.MultipleNullUpperBound

At most one StepAdjustment may have an unspecified upper bound.

The error message returned because a step adjustment that does not have an upper limit value already exists.

400

InvalidStepAdjustments.MultipleNullLowerBound

At most one StepAdjustment may have an unspecified lower bound.

The error message returned because a step adjustment that does not have a lower limit value already exists.

400

InvalidStepAdjustments.NoNullLowerBound

There must be a StepAdjustment with an unspecified lower bound when one StepAdjustment has a negative lower bound.

The error message returned because the lower limit of a step adjustment is a negative value, but a different step adjustment without a lower limit does not exist.

400

InvalidStepAdjustments.NoNullUpperBound

There must be a StepAdjustment with an unspecified upper bound when one StepAdjustment has a positive upper bound.

The error message returned because the upper limit of a step adjustment is a positive value, but a different step adjustment without an upper limit does not exist.

400

InvalidStepAdjustments.Gap

StepAdjustment intervals can not have gaps between them.

The error message returned because the specified ranges of step adjustments have gaps between them.

400

InvalidStepAdjustments.Overlap

StepAdjustment intervals can not overlap.

The error message returned because the specified ranges of step adjustments overlap.

400

InvalidStepAdjustments.LowerGtUpper

LowerBound must be less than the UpperBound for StepAdjustment :%s.

The error message returned because the lower limit value of a step adjustment is greater than or equal to the upper limit value.

400

InvalidStepAdjustments.BothNull

Both lower and upper bounds of a StepAdjustment can not be left unspecified.

The error message returned because the upper limit value or the lower limit value for a step adjustment must be specified.

400

InvalidStepAdjustments.MaxNum

Your scaling rule can have at most %s StepAdjustments.

The error message returned because the maximum number of step adjustments in a scaling group has been reached.

400

StepBeyondPermitRange

Specific parameter "%s" beyond permit range.

The error message returned because the specified upper limit or lower limit for a step adjustment is invalid.