Creates a scaling group.
Operation description
A scaling group is a group of Elastic Compute Service (ECS) instances that can be used in similar business scenarios.
You can create only a limited number of scaling groups in a region. Go to Quota Center to check the quota of the scaling groups.
A scaling group does not immediately take effect after you create the scaling group. You must call the EnableScalingGroup operation to enable the scaling group. After you enable the scaling group, Auto Scaling can execute scaling rules to trigger scaling activities in the scaling group.
The Classic Load Balancer (CLB) instances and ApsaraDB RDS instances that you want to associate with a scaling group must reside in the same region as the scaling group. CLB instances are formerly known as Server Load Balancer (SLB) instances. For more information, see the Regions and zones topic.
If you associate a CLB instance when you create a scaling group, Auto Scaling automatically adds ECS instances in the scaling group to the backend server group of the associated CLB instance. You can specify a server group to which ECS instances can be added. You can add ECS instances to the following types of server groups:
- Default server group: a group of ECS instances that are used to receive requests. If you do not specify a vServer group or a primary/secondary server group for a listener, requests are forwarded to the ECS instances in the default server group.
- vServer group: If you want to forward requests to backend servers that are not in the default server group or configure domain name-based or URL-based forwarding rules, you can use vServer groups.
The default weight of an ECS instance that is added as a backend server of a CLB instance is 50. The CLB instance that you want to associate with your scaling group must meet the following requirements:
- The CLB instance must be in the Active state. You can call the DescribeLoadBalancers operation to query the state of the CLB instance.
- The health check feature must be enabled on all listener ports that are configured for the CLB instance. Otherwise, the scaling group fails to be created.
If you associate an Application Load Balancer (ALB) server group with a scaling group, Auto Scaling automatically adds ECS instances that are in the scaling group to the ALB server group to process requests distributed by the ALB instance to which the ALB server group belongs. You can specify multiple ALB server groups. The server groups must reside in the same virtual private cloud (VPC) as the scaling group. For more information, see the "AttachAlbServerGroups" topic.
If you associate an ApsaraDB RDS instance with a scaling group, Auto Scaling automatically adds the private IP addresses of the ECS instances in the scaling group to the IP address whitelist of the ApsaraDB RDS instance. The ApsaraDB RDS instance that you want to associate with your scaling group must meet the following requirements:
- The ApsaraDB RDS instance must be in the Running state. You can call the DescribeDBInstances operation to query the state of the ApsaraDB RDS instance.
- The number of IP addresses in the IP address whitelist of the ApsaraDB RDS instance cannot exceed the upper limit. For more information, see the "Configure whitelists" topic.
If you set the MultiAZPolicy parameter of the scaling group to COST_OPTIMIZED, take note of the following items:
- You can use the OnDemandBaseCapacity, OnDemandPercentageAboveBaseCapacity, and SpotInstancePools parameters to specify the instance allocation method based on the cost optimization policy. This instance allocation method is prioritized during scaling.
- If you do not specify the OnDemandBaseCapacity, OnDemandPercentageAboveBaseCapacity, or SpotInstancePools parameter, the instance types that are provided at the lowest price are used to create instances based on the cost optimization policy.
If you set the Tags.Propagate
parameter of the scaling group to true, the following rules apply:
- Tags that you add to the scaling group cannot be propagated to existing instances in the scaling group. Tags that you add to the scaling group are propagated to only new instances.
- If you specify instance tags in the scaling configuration that is used to create instances and propagate the tags that you add to the scaling group to the instances, all tags exist at the same time.
- If the tag key that you specify in a scaling configuration and the tag key that you add to the scaling group of the scaling configuration are the same, the tag value that you specify in the scaling configuration is preferentially used.
Debugging
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.
Operation | Access level | Resource type | Condition key | Associated operation |
---|---|---|---|---|
ess:CreateScalingGroup | Write |
|
| none |
Request parameters
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
ScalingGroupName | string | No | The name of the scaling group. The name of each scaling group must be unique in a region. 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. If you do not specify this parameter, the value of the ScalingGroupId parameter is used. | scalinggroup**** |
LaunchTemplateId | string | No | The ID of the launch template that provides instance configurations for Auto Scaling to create instances. | lt-m5e3ofjr1zn1aw7**** |
LaunchTemplateVersion | string | No | The version number of the launch template. Valid values:
| Default |
InstanceId | string | No | The ID of the existing ECS instance that provides instance configurations for Auto Scaling to create a scaling configuration. | i-28wt4**** |
RegionId | string | Yes | The region ID of the scaling group. | cn-qingdao |
MinSize | integer | Yes | The minimum number of ECS instances that must be contained in the scaling group. If the number of ECS instances in the scaling group is less than the value of the MinSize parameter, Auto Scaling adds ECS instances to the scaling group to ensure that the number of ECS instances in the scaling group is equal to the value of the MinSize parameter. Note
The value of the MinSize parameter must be less than or equal to the value of the MaxSize parameter.
| 2 |
MaxSize | integer | Yes | The maximum number of ECS instances that can be contained in the scaling group. If the number of ECS instances in the scaling group is greater than the value of the MaxSize parameter, Auto Scaling removes ECS instances from the scaling group to ensure that the number of ECS instances is equal to the value of the MaxSize parameter. The value range of the MaxSize parameter varies based on the instance quota. You can go to Quota Center to check the maximum number of instances that a scaling group can contain. For example, if the instance quota is 2,000, the value range of the MaxSize parameter is 0 to 2000. | 20 |
DefaultCooldown | integer | No | The cooldown period of the scaling group after a scaling activity is complete. Valid values: 0 to 86400. Unit: seconds. During the cooldown period, Auto Scaling executes only scaling activities that are triggered by CloudMonitor event-triggered tasks. Default value: 300. | 300 |
LoadBalancerIds | string | No | The IDs of the CLB instances that you want to associate with the scaling group. The value can be a JSON array that contains multiple CLB instance IDs. Separate multiple IDs with commas (,). You can associate only a limited number of CLB instances with a scaling group. Go to Quota Center to check the maximum number of CLB instances that you can associate with a scaling group. | ["lb-bp1u7etiogg38yvwz****", "lb-bp168cqrux9ai9l7f****", "lb-bp1jv3m9zvj22ufxp****"] |
DBInstanceIds | string | No | The IDs of the ApsaraDB RDS instances that you want to associate with the scaling group. The value can be a JSON array that contains multiple ApsaraDB RDS instance IDs. Separate multiple IDs with commas (,). You can associate only a limited number of ApsaraDB RDS instances with a scaling group. Go to Quota Center to check the maximum number of ApsaraDB RDS instances that you can associate with a scaling group. | ["rm-bp142f86de0t7****", "rm-bp18l1z42ar4o****", "rm-bp1lqr97h4aqk****"] |
RemovalPolicies | array | No | The instance removal policies. Valid values:
The scaling configuration source specified by the OldestScalingConfiguration setting can be a scaling configuration or a launch template. The CustomPolicy setting takes effect only if you specify it as the first step to remove instances. If you specify CustomPolicy, you must also specify the CustomPolicyARN parameter. Note
The removal of ECS instances from a scaling group is also affected by the value of the MultiAZPolicy parameter. For more information, see the Configure a combination policy for removing instances topic.
| |
string | No | The instance removal policy. Valid values:
The scaling configuration source specified by the OldestScalingConfiguration setting can be a scaling configuration or a launch template. The CustomPolicy setting takes effect only if you specify it as the first step to remove instances. If you specify CustomPolicy, you must also specify the CustomPolicyARN parameter. Note
The removal of ECS instances from a scaling group is also affected by the value of the MultiAZPolicy parameter. For more information, see the Configure a combination policy for removing instances topic.
| OldestScalingConfiguration | |
VSwitchId | string | No | The ID of the vSwitch. If you specify the VSwitchId parameter, the network type of the scaling group is VPC. Note
If you do not specify the VSwitchId or VSwitchIds parameter, the network type of the scaling group is classic network.
| vsw-bp14zolna43z266bq**** |
MultiAZPolicy | string | No | The scaling policy for the multi-zone scaling group that contains ECS instances. Valid values:
Default value: PRIORITY. | PRIORITY |
HealthCheckType | string | No | The health check mode of the scaling group. Valid values:
Default value: ECS. | ECS |
ScalingPolicy | string | No | The reclaim mode of the scaling group. Valid values:
The ScalingPolicy parameter specifies the reclaim mode of the scaling group. The RemovePolicy parameter of the RemoveInstances operation specifies how to remove instances in a specific manner. | recycle |
ClientToken | string | No | The client token that is used to ensure the idempotence of the request. You can use the client to generate the token, but you must make sure that the token is unique among different requests. The token can contain only ASCII characters and cannot exceed 64 characters in length. For more information, see Ensure idempotence. | 123e4567-e89b-12d3-a456-42665544**** |
OnDemandBaseCapacity | integer | No | The minimum number of pay-as-you-go instances that must be contained in the scaling group. Valid values: 0 to 1000. If the number of pay-as-you-go instances is less than the value of this parameter, Auto Scaling preferentially creates pay-as-you-go instances. | 30 |
OnDemandPercentageAboveBaseCapacity | integer | No | The percentage of pay-as-you-go instances in the excess instances when the minimum number of pay-as-you-go instances reaches the requirement. Valid values: 0 to 100. | 20 |
SpotInstanceRemedy | boolean | No | Specifies whether to supplement preemptible instances. If you set this parameter to true, Auto Scaling creates an instance to replace a preemptible instance when Auto Scaling receives a system message which indicates that the preemptible instance is to be reclaimed. | true |
CompensateWithOnDemand | boolean | No | Specifies whether to automatically create pay-as-you-go instances to meet the requirement on the number of ECS instances when the expected capacity of preemptible instances cannot be provided due to reasons such as cost-related issues and insufficient resources. This parameter is available only if you set the MultiAZPolicy parameter to COST_OPTIMIZED. Valid values:
Default value: true. | true |
SpotInstancePools | integer | No | The number of available instance types. Auto Scaling evenly creates preemptible instances of multiple instance types that are provided at the lowest cost in the scaling group. Valid values: 1 to 10. | 5 |
DesiredCapacity | integer | No | The expected number of ECS instances in the scaling group. Auto Scaling automatically maintains the expected number of ECS instances. The value of the DesiredCapacity parameter cannot be greater than the value of the MaxSize parameter and less than the value of the MinSize parameter. | 5 |
GroupDeletionProtection | boolean | No | Specifies whether to enable deletion protection for the scaling group. Valid values:
Default value: false. | true |
GroupType | string | No | The type of the instances that are managed by the scaling group. Valid values:
Default value: ECS. | ECS |
ContainerGroupId | string | No | The ID of the elastic container instance. | eci-uf6fonnghi50u374**** |
VSwitchIds | array | No | The IDs of vSwitches. If you specify the VSwitchIds parameter, the VSwitchId parameter is ignored. If you specify the VSwitchIds parameter, the network type of the scaling group is VPC. If you specify multiple vSwitches, take note of the following items:
Note
If you do not specify the VSwitchId or VSwitchIds parameter, the network type of the scaling group is classic network.
| |
string | No | The ID of the vSwitch. If you specify the VSwitchIds parameter, the VSwitchId parameter is ignored. If you specify the VSwitchIds parameter, the network type of the scaling group is VPC. If you specify multiple vSwitches, take note of the following items:
Note
If you do not specify the VSwitchId or VSwitchIds parameter, the network type of the scaling group is classic network.
| vsw-bp14zolna43z266bq**** | |
LifecycleHooks | object [] | No | The lifecycle hooks. | |
DefaultResult | string | No | The action that Auto Scaling performs after the lifecycle hook of the scaling group times out. Valid values:
If multiple lifecycle hooks in the scaling group are triggered during scale-in activities and you set the LifecycleHook.N.DefaultResult parameter to ABANDON for one of the lifecycle hooks, Auto Scaling immediately performs the action after the lifecycle hook whose DefaultResult parameter is set to ABANDON times out. In this case, other lifecycle hooks time out ahead of schedule. In other cases, Auto Scaling performs the action only after all lifecycle hooks time out. The action that Auto Scaling performs is determined by the value of the DefaultResult parameter that you set for the lifecycle hook that last times out. Default value: CONTINUE. | CONTINUE |
LifecycleHookName | string | No | The name of the lifecycle hook. After you specify this parameter, you cannot change the value of this parameter. If you do not specify this parameter, the ID of the lifecycle hook is used. | lifecyclehook**** |
LifecycleTransition | string | No | The type of the scaling activity for which you create the lifecycle hook. Valid values:
Note
If you create lifecycle hooks for your scaling group, you must specify the LifecycleTransition parameter.
| SCALE_OUT |
NotificationMetadata | string | No | The fixed string that is included in a notification. Auto Scaling sends the notification when the lifecycle hook takes effect. The value of this parameter cannot exceed 4,096 characters in length. Auto Scaling sends the value of the notificationmetadata parameter together with the notification. This way, you can categorize and manage your notifications in an efficient manner. If you specify the notificationmetadata parameter, you must also specify the notificationarn parameter. | Test |
NotificationArn | string | No | The Alibaba Cloud Resource Name (ARN) of the notification method that Auto Scaling uses to send a notification when a lifecycle hook takes effect. This notification method can be a Message Service (MNS) queue or an MNS topic. Specify the value of this parameter in the following format: acs:ess:{region}:{account-id}:{resource-relative-id}.
Examples:
| acs:ess:cn-hangzhou:1111111111:queue/queue2 |
HeartbeatTimeout | integer | No | The period of time before the lifecycle hook times out. When the lifecycle hook times out, Auto Scaling performs the action specified by the DefaultResult parameter. Valid values: 30 to 21600. Unit: seconds. After you create a lifecycle hook, you can call the RecordLifecycleActionHeartbeat operation to extend the timeout period of the lifecycle hook. You can also call the CompleteLifecycleAction operation to end the timeout period ahead of schedule. Default value: 600. | 600 |
VServerGroups | object [] | No | Details of the backend vServer groups that you want to associate with the scaling group. | |
VServerGroupAttributes | object [] | No | The attributes of the backend vServer groups. | |
VServerGroupId | string | No | The ID of the backend vServer group. | rsp-bp1443g77**** |
Weight | integer | No | The weight of an ECS instance after Auto Scaling adds the ECS instance to the backend vServer group as a backend server. If you increase the weight of an ECS instance in the backend vServer group, the number of access requests that are forwarded to the ECS instance also increases. If you set the Weight parameter of an ECS instance in the backend vServer group to 0, no access requests are forwarded to the ECS instance. Valid values: 0 to 100. Default value: 50. | 100 |
Port | integer | No | The port number that is used by an ECS instance after Auto Scaling adds the ECS instance to the backend vServer group. Valid values: 1 to 65535. | 22 |
LoadBalancerId | string | No | The ID of the CLB instance to which the backend vServer group belongs. | lb-bp1u7etiogg38yvwz**** |
Tags | object [] | No | Details of the tags that you want to add to the scaling group. | |
Key | string | No | The tag key that you want to add to the scaling group. | Department |
Value | string | No | The tag value that you want to add to the scaling group. | Finance |
LaunchTemplateOverrides | object [] | No | Details of the instance types that you specify by using the Extended Configurations feature of the launch template. | |
InstanceType | string | No | The instance type that you want to use to override the instance type that is specified in the launch template. If you want to scale instances based on the weighted capacities of the instances, you must specify both the InstanceType and WeightedCapacity parameters. Note
This parameter is available only if you specify the LaunchTemplateId parameter.
You can use the InstanceType parameter to specify only instance types that are available for purchase. | ecs.c5.xlarge |
WeightedCapacity | integer | No | The weight of the instance type. The weight specifies the capacity of an instance of the specified instance type in the scaling group. If you want to scale instances based on the weighted capacities of the instances, you must specify the WeightedCapacity parameter after you specify the InstanceType parameter. A higher weight specifies that a smaller number of instances of the specified instance type are required to meet the expected capacity requirement. Performance metrics, such as the number of vCPUs and the memory size of each instance type, may vary. You can specify different weights for different instance types based on your business requirements. Example:
To meet the expected capacity requirement, Auto Scaling must create and add two ecs.c5.xlarge instances. Note
The capacity of the scaling group cannot exceed the sum of the maximum number of instances that is specified by the MaxSize parameter and the maximum weight of the instance types.
Valid values of the WeightedCapacity parameter: 1 to 500. | 4 |
SpotPriceLimit | float | No | The maximum bid price of the instance type that is specified by the Note
This parameter is available only if you specify the LaunchTemplateId parameter.
| 0.025 |
AlbServerGroups | object [] | No | Details of the Application Load Balancer (ALB) server groups that you want to associate with the scaling group. | |
AlbServerGroupId | string | No | The ID of the ALB server group that you want to associate with the scaling group. You can associate only a limited number of ALB server groups with a scaling group. Go to Quota Center to check the maximum number of ALB server groups that you can associate with a scaling group. | sgp-ddwb0y0g6y9bjm**** |
Weight | integer | No | The weight of an ECS instance after Auto Scaling adds the ECS instance to the ALB server group as a backend server. If you increase the weight of an ECS instance in the ALB server group, the number of access requests that are forwarded to the ECS instance increases. If you set the Weight parameter for an ECS instance in the ALB server group to 0, no access requests are forwarded to the ECS instance. Valid values: 0 to 100. | 100 |
Port | integer | No | The port number that is used by an ECS instance after Auto Scaling adds the ECS instance to the ALB server group. Valid values: 1 to 65535. | 22 |
ServerGroups | object [] | No | Details of the server groups. Note
You cannot use the AlbServerGroups parameter and the ServerGroups parameter to specify the same server group.
| |
ServerGroupId | string | No | The ID of the server group. | sgp-5yc3bd9lfyh***** |
Type | string | No | The type of the server group. Valid values:
| ALB |
Weight | integer | No | The weight of an Elastic Compute Service (ECS) instance in the scaling group as a backend server after Auto Scaling adds the ECS instance to the server group. Valid values: 0 to 100. If you increase the weight of an ECS instance in the server group, the number of access requests that are forwarded to the ECS instance also increases. If you set the Weight parameter of an ECS instance in the server group to 0, no access requests are forwarded to the ECS instance. | 100 |
Port | integer | No | The port number that is used by an ECS instance after Auto Scaling adds the ECS instance to the server group. Valid values: 1 to 65535. | 22 |
AzBalance | boolean | No | Specifies whether to evenly distribute instances in the scaling group across zones. This parameter is available only if you set the
Default value: false. | false |
AllocationStrategy | string | No | The allocation policy of instances. Auto Scaling selects instance types based on the allocation policy to create the required number of instances. The policy can be applied to pay-as-you-go instances and preemptible instances. This parameter takes effect only when you set the
Default value: priority. | priority |
SpotAllocationStrategy | string | No | The allocation policy of preemptible instances. You can use this parameter to individually specify the allocation policy of preemptible instances. This parameter takes effect only if you set the
Default value: priority. | lowestPrice |
SyncAlarmRuleToCms | boolean | No | Note
This parameter is unavailable.
| false |
MaxInstanceLifetime | integer | No | The maximum life span of an instance in the scaling group. Unit: seconds. Valid values: 86400 to the value of the Integer.maxValue parameter. Default value: null. | null |
CustomPolicyARN | string | No | The Alibaba Cloud Resource Name (ARN) of the custom scale-in policy (Function). This parameter is available only if you specify CustomPolicy as the first step to remove instances. | acs:fc:cn-zhangjiakou:16145688****:services/ess_custom_terminate_policy.LATEST/functions/ess_custom_terminate_policy_name |
ResourceGroupId | string | No | The ID of the resource group to which you want to add the scaling group. Note
If you specify this parameter, new scaling groups are added to the specified resource group. If you do not specify this parameter, new scaling groups are added to the default resource group.
| rg-123****** |
HealthCheckTypes | array | No | The health check modes of the scaling group. Valid values:
Default value: ECS. | |
string | No | The health check mode of the scaling group. Valid values:
| ECS |
Response parameters
Examples
Sample success responses
JSON
format
{
"RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****",
"ScalingGroupId": "asg-bp14wlu85wrpchm0****"
}
Error codes
HTTP status code | Error code | Error message |
---|---|---|
404 | ResourceNotAvailable.VPCNetwork | The specified zone does not support vpc network or sold out. |
For a list of error codes, visit the Service error codes.
Change history
Change time | Summary of changes | Operation | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
2024-02-01 | The Error code has changed. The request parameters of the API has changed | see changesets | ||||||||
| ||||||||||
2023-11-14 | The Error code has changed | see changesets | ||||||||
| ||||||||||
2023-03-30 | The Error code has changed. The request parameters of the API has changed | see changesets | ||||||||
| ||||||||||
2022-12-22 | The Error code has changed | see changesets | ||||||||
|