Creates a scaling rule.

Description

A scaling rule defines a specific scaling activity, such as adding or removing N instances. If the number of Elastic Compute Service (ECS) instances in a scaling group is less than the minimum number allowed or greater than the maximum number allowed after a scaling rule is executed, Auto Scaling adjusts the number of ECS instances to add or remove. This way, the number of ECS instances can be maintained within the specified range after the scaling rule is executed. The number of ECS instances that is specified in the scaling rule remains unchanged. Examples:

  • If your scaling group contains two ECS instances and allows up to three ECS instances, only one ECS instance is added to your scaling group after you execute a scale-out rule in which three ECS instances are specified. The number of ECS instances that is specified in the scaling rule remains unchanged.
  • If your scaling group contains three ECS instances and requires at least two ECS instances, only one ECS instance is removed from your scaling group after you execute a scale-in rule in which five ECS instances are specified. The number of ECS instances that is specified in the scaling rule remains unchanged.

Before you call this operation, take note of the following items:

  • If you set the AdjustmentType parameter to TotalCapacity, the number of ECS instances in the scaling group is adjusted to the specified value. The value of the AdjustmentValue parameter must be greater than or equal to 0.
  • If you set the AdjustmentType parameter to QuantityChangeInCapacity or PercentChangeInCapacity, a positive value of AdjustmentValue specifies the number of ECS instances that are added to the scaling group, and a negative value of AdjustmentValue specifies the number of ECS instances that are removed from the scaling group.
  • If you set the AdjustmentType parameter to PercentChangeInCapacity, Auto Scaling uses the following formula to calculate a value, and then rounds the value to the nearest integer to obtain the number of ECS instances that need to be scaled: Value of TotalCapacity × Value of AdjustmentValue/100.
  • If the cooldown time (Cooldown) is specified in a scaling rule, the specified time applies to the scaling group after the rule is executed. Otherwise, the value of the DefaultCooldown parameter of the scaling group applies to the scaling group.
  • You can create only a limited number of scaling rules for a scaling group. For more information, see Limits.
  • The following API operations use the unique identifier of a scaling rule (ScalingRuleAri) returned by CreateScalingRule:
    • ExecuteScalingRule: You can call this operation to manually execute a specific scaling rule by setting ScalingRuleAri to the unique identifier.
    • CreateScheduledTask: You can call this operation to create a scheduled task for a specific scaling rule by setting ScheduledAction to the unique identifier.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes CreateScalingRule

The operation that you want to perform. Set the value to 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 (.). It must start with a letter or a digit. The name of a scaling rule must be unique in the scaling group to which the scaling rule belongs within an Alibaba Cloud account.

If you do not specify this parameter, the ScalingRuleId value is used.

Cooldown Integer No 60

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

By default, this parameter is left empty.

MinAdjustmentMagnitude Integer No 1

The minimum number of instances that need to be scaled when the adjustment type is PercentChangeInCapacity. This parameter is available only if you set the ScalingRuleType parameter to SimpleScalingRule or StepScalingRule.

AdjustmentType String No QuantityChangeInCapacity

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

  • QuantityChangeInCapacity: adds the specified number of ECS instances to or removes the specified number of ECS instances from the scaling group.
  • PercentChangeInCapacity: adds the specified percentage of ECS instances to or removes the specified 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 need to be scaled based on the scaling rule. This parameter is required only if you set the ScalingRuleType parameter to SimpleScalingRule or StepScalingRule. The number of ECS instances that need to be scaled in a single scaling activity cannot exceed 1,000. Valid values based on the AdjustmentType value:

  • -1000 to 1000 if you set the AdjustmentType parameter to QuantityChangeInCapacity.
  • -100 to 10000 if you set the AdjustmentType parameter to PercentChangeInCapacity.
  • 0 to 2000 if you set the AdjustmentType parameter to TotalCapacity.
ScalingRuleType String No SimpleScalingRule

The type of the scaling rule. Valid values:

  • SimpleScalingRule: scales the number of ECS instances based on the AdjustmentType and AdjustmentValue values.
  • TargetTrackingScalingRule: calculates the number of ECS instances that need to be scaled and attempts to maintain the value of a predefined metric close to the TargetValue value.
  • StepScalingRule: scales ECS instances in steps based on the specified thresholds and metric values.
  • PredictiveScalingRule: uses machine learning to analyze historical monitoring data of the scaling group and predicts the future values of metrics. Then, 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 the ScalingRuleType parameter to TargetTrackingScalingRule or PredictiveScalingRule. Auto Scaling adds ECS instances that are in the warmup state to a scaling group but does not report monitoring data to CloudMonitor during the warmup period.

Note Auto Scaling calculates the number of ECS instances that need to be scaled. ECS instances in the warmup state are not counted towards 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 required only if you set the ScalingRuleType parameter to TargetTrackingScalingRule or PredictiveScalingRule.

Valid values if you set the ScalingRuleType parameter to TargetTrackingScalingRule:

  • CpuUtilization: the average CPU utilization
  • ClassicInternetRx: the average inbound Internet traffic over the classic network
  • ClassicInternetTx: the average outbound Internet traffic over the classic network
  • VpcInternetRx: the average inbound Internet traffic over the virtual private cloud (VPC)
  • VpcInternetTx: the average outbound Internet traffic over the VPC
  • IntranetRx: the average inbound traffic over the internal network
  • IntranetTx: the average outbound traffic over the internal network

Valid values if you set the ScalingRuleType parameter to PredictiveScalingRule:

  • CpuUtilization: the average CPU utilization
  • IntranetRx: the average inbound traffic over the internal network
  • IntranetTx: the average outbound traffic over the internal network
TargetValue Float No 0.125

The target value. This parameter is required only if you set ScalingRuleType 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 the ScalingRuleType parameter to TargetTrackingScalingRule.

Default value: false.

ScaleInEvaluationCount Integer No 15

The number of consecutive times that the event-triggered task created for scale-in activities meets the threshold conditions before an alert is triggered. After a target tracking scaling rule is created, an event-triggered task is automatically created and then associated with the target tracking scaling rule.

Default value: 15.

ScaleOutEvaluationCount Integer No 3

The number of consecutive times that the event-triggered task created for scale-out activities meets the threshold conditions before an alert is triggered. After a target tracking scaling rule is created, an event-triggered task is automatically created and then associated with the target tracking scaling rule.

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 to take 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 percentage of the increment to the predicted value when the PredictiveValueBehavior parameter is set to PredictiveValueOverrideMaxWithBuffer. If the predicted value increased by this percentage is greater than the initial maximum capacity, the increased value is used as the maximum value for prediction tasks. Valid values: 0 to 100.

Default value: 0.

PredictiveTaskBufferTime Integer No 30

The amount of buffer time before the prediction task is executed. By default, all scheduled tasks that are automatically created for a predictive scaling rule are executed on the hour. You can specify a 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 in the scaling group. This parameter is used together with the PredictiveValueBehavior parameter.

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

RegionId String No cn-hangzhou

The ID of the region where the scaling group resides.

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 need to be scaled in a step adjustment. This parameter is available only if you set the ScalingRuleType parameter 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.

Response parameters

Parameter 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-A3DC0DE3C83E

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

Sample requests

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
&<Common request parameters>

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-A3DC0DE3C83E</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-A3DC0DE3C83E",
  "ScalingRuleId" : "asr-bp1dvirgwkoowxk7****"
}

Error codes

For a list of error codes, visit the API Error Center.

HTTP status code

Error code

Error message

Description

404

InvalidScalingGroupId.NotFound

The specified scaling group does not exist.

The error message returned because 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 error message returned because 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 error message returned because the target tracking scaling rules do 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 the MinAdjustmentMagnitude parameter does not support the adjustment method that you specify for 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 value of a step adjustment is negative, and step adjustments that do not have a lower limit value are unavailable.

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 value of a step adjustment is positive, and step adjustments that do not have an upper limit value are unavailable.

400

InvalidStepAdjustments.Gap

StepAdjustment intervals can not have gaps between them.

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

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 an upper limit value or a lower limit value must be specified for a step adjustment.

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 upper limit value or lower limit value specified for a step adjustment is invalid.