All Products
Search
Document Center

Auto Scaling:ModifyScalingGroup

更新时间:Dec 15, 2025

A scaling group automatically adjusts your computing capacity by adding or removing instances based on your business needs and policies. If the properties of a scaling group no longer meet your business requirements, you can call the ModifyScalingGroup operation to modify properties such as the maximum, minimum, or expected number of instances. This saves time and resources because you do not need to create and reconfigure a new scaling group.

Usage notes

  • You cannot modify the following parameters:

  • You can call this operation only when the scaling group is in the Active or Inactive state.

  • Enabling a new scaling configuration does not affect running Elastic Compute Service (ECS) or Elastic Container Instance (ECI) instances that were created based on a previous scaling configuration.

  • If you modify MaxSize, and the number of ECS or ECI instances in the scaling group exceeds the new MaxSize, Auto Scaling automatically removes instances until the number of instances is equal to MaxSize.

  • If you modify MinSize, and the number of ECS or ECI instances in the scaling group is less than the new MinSize, Auto Scaling automatically adds instances until the number of instances is equal to MinSize.

  • If you modify DesiredCapacity, and the number of ECS or ECI instances in the scaling group does not match the new DesiredCapacity, Auto Scaling automatically adds or removes instances until the number of instances is equal to DesiredCapacity.

Try it now

You can call this operation directly in OpenAPI Explorer. This eliminates the need to calculate signatures. After a successful call, OpenAPI Explorer automatically generates sample code for different SDKs.

Request parameters

Parameter

Type

Required

Example

Description

Action

String

Yes

ModifyScalingGroup

A required parameter. Set the value to ModifyScalingGroup.

ScalingGroupId

String

Yes

asg-bp1ffogfdauy0jw0****

The ID of the scaling group to modify.

ScalingGroupName

String

No

scalinggroup****

The name of the scaling group. The name must be unique within a region. The name must be 2 to 64 characters in length. It must start with a digit, an uppercase or lowercase letter, or a Chinese character. It can contain digits, underscores (_), hyphens (-), and periods (.).

MinSize

Integer

No

1

The minimum number of ECS or ECI instances in the scaling group. If the number of instances in the scaling group is less than the value of MinSize, Auto Scaling automatically creates ECS or ECI instances.

Note

MinSize must be less than or equal to the value of MaxSize.

MaxSize

Integer

No

99

The maximum number of ECS or ECI instances in the scaling group. If the number of instances in the scaling group is greater than the value of MaxSize, Auto Scaling automatically removes ECS or ECI instances.

The value range of MaxSize depends on your Auto Scaling usage. Go to Quota Center to view the quota for the Maximum number of instances in a scaling group.

For example, if the quota for the Maximum number of instances in a scaling group is 2000, the value range of MaxSize is 0 to 2000.

DefaultCooldown

Integer

No

600

The cooldown period after a scaling activity that adds or removes ECS or ECI instances is complete. Valid values: 0 to 86400. Unit: seconds.

During the cooldown period, the scaling group does not execute other scaling activities. This applies only to scaling activities triggered by event-triggered tasks from CloudMonitor.

RemovalPolicy.1

String

No

OldestScalingConfiguration

The first removal policy for ECS instances. Valid values:

  • OldestInstance: Removes the ECS instance that was added to the scaling group earliest.

  • NewestInstance: Removes the ECS instance that was added to the scaling group most recently.

  • OldestScalingConfiguration: Removes ECS instances that were created from the earliest scaling configuration.

  • CustomPolicy: Removes ECS instances based on a custom scale-in policy function.

Note

The instance configuration source mentioned in OldestScalingConfiguration refers to either a scaling configuration or a launch template. CustomPolicy can only be set as the first removal policy. If you set this policy, you must also specify the CustomPolicyARN parameter.

RemovalPolicy.2

String

No

NewestInstance

The second removal policy for ECS instances. Valid values:

  • OldestInstance: Removes the ECS instance that was added to the scaling group earliest.

  • NewestInstance: Removes the ECS instance that was added to the scaling group most recently.

  • OldestScalingConfiguration: Removes ECS instances that were created from the earliest scaling configuration.

    Note

    The instance configuration source mentioned in OldestScalingConfiguration refers to either a scaling configuration or a launch template.

RemovalPolicy.3

String

No

OldestInstance

The third removal policy for ECS instances. Valid values:

  • OldestInstance: Removes the ECS instance that was added to the scaling group earliest.

  • NewestInstance: Removes the ECS instance that was added to the scaling group most recently.

  • OldestScalingConfiguration: Removes ECS instances that were created from the earliest scaling configuration.

Note

The instance configuration source mentioned in OldestScalingConfiguration refers to either a scaling configuration or a launch template.

ActiveScalingConfigurationId

String

No

asc-bp17pelvl720x5ub****

The ID of the active scaling configuration in the scaling group.

HealthCheckType

String

No

ECS

The health check mode of the scaling group. Valid values:

  • NONE: No health checks are performed.

  • ECS: Health checks are performed on instances in the scaling group. Use this value to enable instance health checks for both ECS and ECI scaling groups.

  • LOAD_BALANCER: The health status of an instance is determined by the health check results of the load balancer. Classic Load Balancer (CLB) instances are not supported.

Default value: ECS.

Note

To enable both instance health checks and load balancer health checks, use the HealthCheckTypes parameter.

LaunchTemplateId

String

No

lt-m5e3ofjr1zn1aw7****

The ID of the launch template. The scaling group uses the launch template to obtain configuration information for creating instances.

LaunchTemplateVersion

String

No

Default

The version of the launch template. Valid values:

  • A fixed template version number.

  • Default: The default version of the template is always used.

  • Latest: The latest version of the template is always used.

OnDemandBaseCapacity

Integer

No

30

The minimum number of on-demand instances required in the scaling group. Valid values: 0 to 1000. When the number of on-demand instances is less than this value, on-demand instances are created first.

When the MultiAZPolicy parameter is set to the COMPOSABLE policy, the default value is 0.

OnDemandPercentageAboveBaseCapacity

Integer

No

20

The percentage of on-demand instances among the instances that exceed the OnDemandBaseCapacity. This applies after the minimum number of on-demand instances is met. Valid values: 0 to 100.

When the MultiAZPolicy parameter is set to the COMPOSABLE policy, the default value is 100.

SpotInstanceRemedy

Boolean

No

true

Specifies whether to supplement spot instances. If enabled, when the system receives a message that a spot instance is about to be reclaimed, the scaling group attempts to create a new instance to replace it.

CompensateWithOnDemand

Boolean

No

true

When the MultiAZPolicy of the CreateScalingGroup API is set to COST_OPTIMIZED, this parameter specifies whether to automatically try to create on-demand instances to meet the required number of ECS instances if creating enough spot instances fails due to price or inventory issues. Valid values:

  • true: Yes.

  • false: No.

SpotInstancePools

Integer

No

5

The number of available instance types. The scaling group creates spot instances of multiple types that have the lowest cost in a balanced manner. Valid values: 0 to 10.

When the MultiAZPolicy parameter is set to the COMPOSABLE policy, the default value is 2.

DesiredCapacity

Integer

No

5

The expected number of ECS or ECI instances in the scaling group. Setting this parameter enables the expected number of instances feature. The scaling group automatically maintains the number of instances at this value. The value must be between MaxSize and MinSize, inclusive.

Note

If you disable and then re-enable the expected number of instances feature, you must set the DesiredCapacity value again.

GroupDeletionProtection

Boolean

No

true

Specifies whether to enable deletion protection for the scaling group. Valid values:

  • true: Enables deletion protection for the scaling group. The scaling group cannot be deleted.

  • false: Disables deletion protection for the scaling group.

MultiAZPolicy

String

No

PRIORITY

The scaling policy for a multi-zone scaling group of ECS instances. Valid values:

  • PRIORITY: Scales instances based on the priority of the vSwitches (VSwitchIds.N). Auto Scaling first tries to scale instances in the zone of the highest-priority vSwitch. If this fails, it automatically tries the zone of the next-highest priority vSwitch.

  • COST_OPTIMIZED: During scale-outs, Auto Scaling tries to create ECS instances with the lowest vCPU unit price. During scale-ins, it tries to remove ECS instances with the highest vCPU unit price. If the scaling configuration includes multiple instance types with a preemptible billing method, it creates the corresponding spot instances first. You can use the CompensateWithOnDemand parameter to specify whether to automatically create on-demand instances when spot instances cannot be created.

    Note

    COST_OPTIMIZED is effective only when the scaling configuration is set with multiple instance types or uses spot instances.

  • BALANCE: Evenly distributes ECS instances across the specified zones of the scaling group. If the zones become unbalanced due to issues such as insufficient inventory, you can call the RebalanceInstance API to rebalance the resources.

  • COMPOSABLE: A composite policy. You can combine the preceding policies as needed for scaling ECS instances in a multi-zone scaling group.

VSwitchIds.N

String

No

vsw-bp1oo2a7isyrb8igf****

The ID of one or more vSwitches. Valid values of N: 1 to 5.

This parameter is effective only when the network type of the scaling group is VPC. The specified vSwitches must belong to the same VPC as the scaling group.

The vSwitches can be in different zones. The priority of the vSwitches is sorted in ascending order. A value of 1 indicates the highest priority. If an ECS instance cannot be created in the zone of a higher-priority vSwitch, the system automatically tries to create the instance in the zone of the next-highest priority vSwitch.

LaunchTemplateOverride.N.InstanceType

String

No

ecs.c5.xlarge

To scale a scaling group based on instance type capacity, specify both this parameter and LaunchTemplateOverride.N.WeightedCapacity.

This parameter specifies an instance type that overwrites the instance type in the launch template. You can specify N parameters to extend the launch template to support N instance types. Valid values of N: 1 to 20.

Note

This parameter is effective only when the LaunchTemplateId parameter specifies a launch template.

For a list of available ECS instance types, see Instance families.

LaunchTemplateOverride.N.WeightedCapacity

Integer

No

4

After you specify LaunchTemplateOverride.N.InstanceType, specify this parameter to scale the group based on instance type capacity. The value of N must be the same for both parameters.

This parameter specifies the weight of the instance type. The weight represents the capacity of a single instance of this type in the scaling group.

A higher weight means that fewer instances of this type are needed to meet the expected capacity.

Performance metrics, such as the number of vCPUs and memory size, can vary between instance types. You can set different weights for different instance types based on your needs.

For example:

  • Current capacity: 0.

  • Expected capacity: 6.

  • Capacity of ecs.c5.xlarge: 4.

To meet the expected capacity, the scaling group will scale out two ecs.c5.xlarge instances.

Note

During a scale-out, the capacity of the scaling group cannot exceed the sum of the maximum capacity (MaxSize) and the highest weight of an instance type.

Valid values for WeightedCapacity: 1 to 500.

LaunchTemplateOverride.N.SpotPriceLimit

Float

No

0.025

The maximum bid price for the instance type specified by LaunchTemplateOverride.N.InstanceType. You can specify N parameters to extend the launch template to support N instance types. Valid values of N: 1 to 20.

Note

This parameter is effective only when the LaunchTemplateId parameter specifies a launch template.

AzBalance

Boolean

No

false

Specifies whether to evenly distribute the capacity of the scaling group across multiple zones. This parameter is effective only when MultiAZPolicy is set to COMPOSABLE. Valid values:

  • true: The capacity of the scaling group is evenly distributed across multiple zones.

  • false: The capacity of the scaling group is not evenly distributed across multiple zones.

Default value: false.

AllocationStrategy

String

No

priority

The capacity allocation policy. It determines how the scaling group selects available instance types to meet the capacity requirements. This policy applies to both on-demand and spot capacity. This parameter is effective only when MultiAZPolicy is set to COMPOSABLE. Valid values:

  • priority: Creates instances in the order of the configured instance types.

  • lowestPrice: Creates instances from the instance types with the lowest vCPU unit price.

Default value: priority.

SpotAllocationStrategy

String

No

lowestPrice

The distribution policy for spot capacity. You can use this parameter to separately specify the distribution policy for spot capacity. This parameter is effective only when MultiAZPolicy is set to COMPOSABLE. Valid values:

  • priority: Creates instances in the order of the configured instance types.

  • lowestPrice: Creates instances from the instance types with the lowest vCPU unit price.

Default value: priority.

MaxInstanceLifetime

Integer

No

null

The maximum lifetime of an instance in the scaling group. Unit: seconds.

Valid values: 0 or a value in the range of [86400, Integer.maxValue]. A value of 0 clears the previously set MaxInstanceLifetime, which means the instance has an unlimited lifetime.

Default value: null.

Note

This parameter is not supported for scaling groups of the ECI type or for scaling groups with Economical Mode enabled.

CustomPolicyARN

String

No

acs:fc:cn-zhangjiakou:16145688****:services/ess_custom_terminate_policy.LATEST/functions/ess_custom_terminate_policy_name

The ARN of the custom scale-in policy function. This is effective only when the first removal policy in RemovalPolicies is set to CustomPolicy.

DisableDesiredCapacity

Boolean

No

false

Specifies whether to disable the expected number of instances feature for the scaling group. Valid values:

  • false: Enables the expected number of instances feature.

  • true: Disables the expected number of instances feature.

    Note

    You can set this parameter to true only when the scaling group has no ongoing scaling activities. If you set this parameter to true, the DesiredCapacity property of the scaling group is cleared, but the current number of instances in the scaling group does not change.

ScalingPolicy

String

No

recycle

The reclamation mode of the scaling group. Valid values:

  • recycle: The reclamation mode is Economical Mode.

  • release: The reclamation mode is Release Mode.

  • forcerelease: The reclamation mode is Forced Release Mode.

    Note

    If you select forcerelease, the system forcibly releases Running instances during a scale-in activity. A forced release is like a power-off operation. It erases the data in the memory and ephemeral storage of the instance, and the data cannot be recovered. Use this option with caution.

  • forcerecycle: The reclamation mode is Forced Economical Mode.

    Note

    If you select forcerecycle, the system forcibly shuts down Running instances during a scale-in activity. A forced shutdown is like a power-off operation. It erases the data in the memory and ephemeral storage of the instance, and the data cannot be recovered. Use this option with caution.

ScalingPolicy specifies the reclamation mode of the scaling group. The specific action taken when an instance is removed from the scaling group is determined by the RemovePolicy parameter of the RemoveInstances API. For more information, see RemoveInstances.

HealthCheckTypes.N

String

No

ECS

A list of health check modes for the scaling group. Valid values:

  • NONE: No health checks are performed.

  • ECS: Health checks are performed on instances in the scaling group. Use this value to enable instance health checks for both ECS and ECI scaling groups.

  • LOAD_BALANCER: The health status of an instance is determined by the health check results of the load balancer. Classic Load Balancer (CLB) instances are not supported.

Default value: ECS.

StopInstanceTimeout

Integer

No

60

The timeout period for an ECS instance to be successfully stopped during a scale-in process. Unit: seconds.

Valid values: 30 to 240.

Note
  • This parameter is effective only during a scale-in process when ScalingPolicy is set to release.

  • If you set this parameter, the system waits for the instance to be successfully stopped for a maximum of StopInstanceTimeout. After the timeout, the scale-in continues regardless of whether the instance was stopped.

  • If you do not set this parameter, the system waits for a long time for the instance to be successfully stopped. The scale-in continues only after the instance is stopped. If the instance fails to stop, the scale-in process is rolled back and fails.

  • Setting this parameter to 0 cancels the configuration.

CapacityOptions.OnDemandBaseCapacity

Integer

No

30

The minimum number of on-demand instances required in an existing scaling group. When the number of on-demand instances in the scaling group is less than this value, the system creates on-demand instances first. Valid values: 0 to 1000.

When the MultiAZPolicy parameter is set to the COMPOSABLE policy, the default value is 0.

CapacityOptions.OnDemandPercentageAboveBaseCapacity

Integer

No

20

The percentage of on-demand instances among the instances that exceed the OnDemandBaseCapacity. This applies after the minimum number of on-demand instances is met. Valid values: 0 to 100.

When the MultiAZPolicy parameter is set to the COMPOSABLE policy, the default value is 100.

CapacityOptions.CompensateWithOnDemand

Boolean

No

true

When the MultiAZPolicy of the CreateScalingGroup API is set to COST_OPTIMIZED, this parameter specifies whether to automatically try to create on-demand instances to meet the required number of ECS instances if creating enough spot instances fails due to price or inventory issues. Valid values:

  • true: Yes.

  • false: No.

CapacityOptions.SpotAutoReplaceOnDemand

Boolean

No

true

After CompensateWithOnDemand is enabled, if the proportion of on-demand instances exceeds the OnDemandPercentageAboveBaseCapacity, the system attempts to replace on-demand capacity with spot capacity. A common scenario is when CompensateWithOnDemand downgrades to on-demand instances due to spot inventory or price issues. To avoid keeping these on-demand instances for a long time, the system attempts to replace the excess on-demand capacity with spot capacity. Valid values:

  • true: Yes.

  • false: No.

Default value: false.

CapacityOptions.PriceComparisonMode

String

No

PricePerUnit

The price comparison mode for the scaling group's cost optimization policy. Valid values:

  • PricePerUnit: Compares prices per unit of capacity.

    The capacity of an instance in a scaling group is equal to the weight set for its instance type. The default is 1, meaning one ECS instance has a capacity of 1.

  • PricePerVCpu: Compares prices per vCPU unit.

Default value: PricePerUnit.

BalanceMode

String

No

BalancedBestEffort

The zone balancing mode. This is effective only when zone balancing is enabled. Valid values:

  • BalancedBestEffort:

    If resource creation fails in a zone, the system falls back to other zones to ensure best-effort resource delivery.

  • BalancedOnly:

    If resource creation fails in a zone, the system does not fall back to other zones. The scale-out activity is partially successful to prevent severe imbalances between zones.

Default value: BalancedBestEffort.

AutoRebalance

Boolean

No

false

Specifies whether to enable automatic rebalancing for the scaling group. This is effective only when BalancedOnly is enabled for a zone-balanced scaling group. Valid values:

  • false: Do not enable automatic rebalancing.

  • true: Enable automatic rebalancing. The scaling group automatically detects capacity across zones. If the capacity is imbalanced, it initiates scale-out or scale-in activities to rebalance the capacity.

Default value: false.

Response parameters

Parameter

Type

Example

Description

RequestId

String

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

The request ID.

Examples

Sample request

http(s)://ess.aliyuncs.com/?Action=ModifyScalingGroup
&ScalingGroupId=asg-bp1ffogfdauy0jw0****
&ScalingGroupName=scalinggroup****
&MinSize=1
&MaxSize=99
&DefaultCooldown=600
&RemovalPolicy.1=OldestScalingConfiguration
&RemovalPolicy.2=NewestInstance
&RemovalPolicy.3=OldestInstance
&ActiveScalingConfigurationId=asc-bp17pelvl720x5ub****
&HealthCheckType=ECS
&LaunchTemplateId=lt-m5e3ofjr1zn1aw7****
&LaunchTemplateVersion=Default
&OnDemandBaseCapacity=30
&OnDemandPercentageAboveBaseCapacity=20
&SpotInstanceRemedy=true
&CompensateWithOnDemand=true
&SpotInstancePools=5
&DesiredCapacity=5
&GroupDeletionProtection=true
&MultiAZPolicy=PRIORITY
&VSwitchIds=["vsw-bp1oo2a7isyrb8igf****"]
&LaunchTemplateOverride=[{"InstanceType":"ecs.c5.xlarge","WeightedCapacity":4,"SpotPriceLimit":0.025}]
&AzBalance=false
&AllocationStrategy=priority
&SpotAllocationStrategy=lowestPrice
&CustomPolicyARN=acs:fc:cn-zhangjiakou:16145688****:services/ess_custom_terminate_policy.LATEST/functions/ess_custom_terminate_policy_name
&DisableDesiredCapacity=false
&ScalingPolicy=recycle
&HealthCheckTypes=["ECS"]
&StopInstanceTimeout=60
&CapacityOptions={"OnDemandBaseCapacity":30,"OnDemandPercentageAboveBaseCapacity":20,"CompensateWithOnDemand":true,"SpotAutoReplaceOnDemand":true}
&Common request parameters

Sample success responses

XML format

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

<ModifyScalingGroupResponse>
    <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3****</RequestId>
</ModifyScalingGroupResponse>

JSON format

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

{
  "RequestId" : "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****"
}

Error codes

For more information about error codes, see the Error Center.

HTTP status code

Error code

Error message

Description

404

InvalidScalingGroupId.NotFound

The specified scaling group does not exist.

The specified scaling group does not exist in your account.

400

InvalidScalingGroupName.Duplicate

The specified value of parameter parameter name is duplicated.

parameter name

is duplicated.

The scaling group name already exists.

404

InvalidScalingConfigurationId.NotFound

The specified scaling configuration does not exist.

The specified scaling configuration does not exist in the scaling group.

400

InvalidScalingConfigurationId.InstanceTypeMismatch

The specified scaling configuration and existing active scaling configuration have different instance type.

The instance type of the specified scaling configuration does not match the instance type of the active scaling configuration.

400

InvalidParameter.Conflict

The value of parameter parameter name and parameter parameter name are confilict.

parameter name

and parameter

parameter name

are in conflict.

The specified MinSize is greater than MaxSize.

400

LaunchTemplateVersionSet.NotFound

The specific version of launch template is not exist.

The specified version of the launch template does not exist.

400

LaunchTemplateSet.NotFound

The specified launch template set is not found.

The specified launch template does not exist.

400

TemplateMissingParameter.ImageId

The input parameter "ImageId" that is mandatory for processing this request is not supplied.

The specified version of the launch template is missing image information.

400

TemplateMissingParameter.InstanceTypes

The input parameter "InstanceTypes" that is mandatory for processing this request is not supplied.

The specified version of the launch template is missing instance type information.

400

TemplateMissingParameter.SecurityGroup

The input parameter "SecurityGroup" that is mandatory for processing this request is not supplied.

The specified version of the launch template is missing security group information.

400

TemplateVersion.NotNumber

The input parameter "LaunchTemplateVersion" is supposed to be a string representing the version number.

The specified fixed version number of the launch template must be a number.