All Products
Search
Document Center

Auto Scaling:CreateScalingRule

更新時間:Nov 11, 2024

Creates a scaling rule. The purpose of a scaling rule varies based on its type. You can use a scaling rule to trigger a scaling activity or adjust the boundary values for a scaling group. You can call the CreateScalingRule operation to create different types of scaling rules based on your business requirements. For example, if your business requires only automatic adjustment of the boundary values for your scaling group, you can call this operation to create a predictive scaling rule.

Operation description

A scaling rule defines the specific scaling action. For example, you can use a scaling rule to define N instances to add or remove. If the execution of a scaling rule causes the total number of Elastic Compute Service (ECS) instances or elastic container instances in the scaling group to drop below the value of MinSize or to exceed the value of MaxSize, Auto Scaling adjusts the number of instances to add or remove, which ensures that the total number of instances stays within the valid range. Take note that Auto Scaling does not adjust the number of instances that you defined in the scaling rule. Examples:

  • The maximum number of instances (MaxSize) that can be contained in a scaling group is 3 and the current number of instances (Total Capacity) in the scaling group is 2. In this example, the Add3 scaling rule is created to add three ECS instances to the scaling group. However, after you execute Add3, Auto Scaling adds only one ECS instance to the scaling group. In addition, the number of ECS instances to add in the Add3 scaling rule remains unchanged.
  • The minimum number of instances (MinSize) that must be contained in a scaling group is 2 and the current number of instances (Total Capacity) is 3. In this example, the Remove5 scaling rule is created to remove five ECS instances from the scaling group. However, after you execute Remove5, Auto Scaling only removes one ECS instance from the scaling group. In addition, the number of ECS instances to remove in the Remove5 scaling rule remains unchanged.

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

  • If you set AdjustmentType to TotalCapacity, the total number of ECS instances or elastic container instances in your scaling group will be adjusted to a specified number when the scaling rule that you create by calling this operation is executed. You must set AdjustmentValue to an integer that is greater than 0.

  • If you set AdjustmentType to QuantityChangeInCapacity or PercentChangeInCapacity, a positive value of AdjustmentValue specifies that a specific number of ECS instances or elastic container instances will be added to your scaling group, and a negative value of AdjustmentValue specifies that a specific number of ECS instances or elastic container instances will be removed from the scaling group.

  • If you set AdjustmentType to 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 AdjustmentValue divided by 100, rounding off the result to determine the final adjustment count.

  • If you specify a cooldown period for a scaling rule, the cooldown period of the scaling rule takes effect after you execute the scaling rule. If you do not specify a cooldown period for a scaling rule, the value of DefaultCooldown of the scaling group takes effect after you execute the scaling rule.

  • You can create only a limited number of scaling rules for a scaling group. For more information, see Limits .

  • The following API operations may use the unique identifier of a scaling rule (ScalingRuleAri) that is returned after you call the CreateScalingRule operation:

    • ExecuteScalingRule: You can call this operation to manually execute a scaling rule. In this operation, you can set ScalingRuleAri to the unique identifier of the scaling rule that you want to execute.
    • CreateScheduledTask: You can call this operation to create a scheduled task for a scaling rule. In this operation, you can set ScalingRuleAri to the unique identifier of the scaling rule for which you want to create a scheduled task.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
ess:CreateScalingRulecreate
  • All Resources
    *
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
ScalingGroupIdstringYes

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

asg-bp1ffogfdauy0jw0****
ScalingRuleNamestringNo

The name of the scaling rule. The name 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 under the same account within a region.

If you leave this parameter empty, the scaling rule ID is used.

scalingrule****
CooldownintegerNo

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.

60
MinAdjustmentMagnitudeintegerNo

The minimum number of instances that must be scaled when the AdjustmentType parameter is set to PercentChangeInCapacity. This parameter takes effect only if you set the ScalingRuleType parameter to SimpleScalingRule or StepScalingRule.

1
AdjustmentTypestringNo

The scaling 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.
QuantityChangeInCapacity
AdjustmentValueintegerNo

The number of instances that must 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 are scaled in a single scaling activity cannot exceed 1,000.

  • Valid values if you set the AdjustmentType parameter to QuantityChangeInCapacity: -1000 to 1000.
  • Valid values if you set the AdjustmentType parameter to PercentChangeInCapacity: -100 to 10000.
  • Valid values if you set the AdjustmentType parameter to TotalCapacity: 0 to 2000.
100
ScalingRuleTypestringNo

The type of the scaling rule. Valid values:

  • SimpleScalingRule: a simple scaling rule. After you execute 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 execute a target tracking scaling rule, Auto Scaling dynamically calculates the number of ECS instances or elastic container instances to scale based on the predefined metric (MetricName) and attempts to maintain the metric value close to the expected value (TargetValue).
  • StepScalingRule: a step scaling rule. After you execute a step scaling rule, Auto Scaling scales instances step by step based on the predefined thresholds and metric values.
  • PredictiveScalingRule: 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 value range for the scaling group.

Default value: SimpleScalingRule

SimpleScalingRule
EstimatedInstanceWarmupintegerNo

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 must 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.

300
MetricNamestringNo

The predefined metric that you want to monitor. If you set ScalingRuleType to TargetTrackingScalingRule or PredictiveScalingRule, you must specify this parameter.

Valid values if you set ScalingRuleType to TargetTrackingScalingRule:

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

Valid values if you set ScalingRuleType to PredictiveScalingRule:

  • 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 Event-triggered tasks of the system monitoring type.

CpuUtilization
TargetValuefloatNo

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.

0.125
DisableScaleInbooleanNo

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

Default value: false.

false
ScaleInEvaluationCountintegerNo

The number of consecutive times that the event-triggered task created for scale-in activities must meet 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.

15
ScaleOutEvaluationCountintegerNo

The number of consecutive times that the event-triggered task created for scale-out activities must meet 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.

3
PredictiveScalingModestringNo

The mode of the predictive scaling rule. Valid values:

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

Default value: PredictAndScale.

PredictAndScale
PredictiveValueBehaviorstringNo

The maximum value for predication tasks. 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. If the predicted value that is increased by the percentage is greater than the initial maximum capacity, the increased value is used as the maximum value for prediction tasks.

Default value: MaxOverridePredictiveValue.

MaxOverridePredictiveValue
PredictiveValueBufferintegerNo

The ratio based on which the predicted value is increased when you set PredictiveValueBehavior to PredictiveValueOverrideMaxWithBuffer. If the predicted value increased by this ratio 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.

50
PredictiveTaskBufferTimeintegerNo

The amount of buffer time before the prediction task is 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 the prediction tasks are executed. Valid values: 0 to 60. Unit: minutes.

Default value: 0.

30
InitialMaxSizeintegerNo

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 MaxSize.

100
StepAdjustmentsarray<object>No

Details of the step adjustments.

objectNo

Details of the step adjustments.

MetricIntervalUpperBoundfloatNo

The upper limit that is specified in a step adjustment. Valid values: -9.999999E18 to 9.999999E18.

5.0
ScalingAdjustmentintegerNo

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

1
MetricIntervalLowerBoundfloatNo

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

1.0
RegionIdstringNo

The region ID of the scaling group.

cn-hangzhou
AlarmDimensionsarray<object>No

The metric dimensions. This parameter is applicable to target tracking scaling rules. If your predefined metric requires extra dimensions, you must specify this parameter. For example, if you use LoadBalancerRealServerAverageQps as your predefined metric, you must use this parameter to specify the rulePool dimension.

objectNo
DimensionKeystringNo

The dimension key of the metric.

rulePool
DimensionValuestringNo

The dimension value of the metric.

sgp-l1cbirz451yxuxxx

Response parameters

ParameterTypeDescriptionExample
object
ScalingRuleAristring

The unique identifier of the scaling rule.

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

The ID of the request.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3****
ScalingRuleIdstring

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

asr-bp1dvirgwkoowxk7****

Examples

Sample success responses

JSONformat

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

Error codes

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2024-09-13The request parameters of the API has changedView Change Details
2023-04-03The request parameters of the API has changedView Change Details