All Products
Search
Document Center

Auto Scaling:AttachServerGroups

Last Updated:Dec 30, 2025

You can call this operation to add one or more server groups to a scaling group. This helps you dynamically adjust the number of instances to handle workload changes and ensure high availability for your application. You can add server groups of Application Load Balancer (ALB), Network Load Balancer (NLB), and Gateway Load Balancer (GWLB). Auto Scaling automatically adds instances to the server groups to distribute traffic based on the load. This improves the stability of your application.

Try it now

You can call this operation directly in OpenAPI Explorer. OpenAPI Explorer saves you the trouble of calculating signatures. After a successful call, OpenAPI Explorer automatically generates sample code for various SDKs.

Request parameters

Parameter

Type

Required

Example

Description

Action

String

Yes

AttachServerGroups

The operation that you want to perform. Set the value to AttachServerGroups.

RegionId

String

Yes

cn-hangzhou

The region ID of the scaling group.

ScalingGroupId

String

Yes

asg-bp18p2yfxow2dloq****

The ID of the scaling group.

ClientToken

String

No

123e4567-e89b-12d3-a456-42665544****

A client token to ensure the idempotence of the request.

Generate a unique token for each request. The token can contain only ASCII characters and must be no more than 64 characters in length. For more information, see How to ensure idempotence.

ForceAttach

Boolean

No

false

Specifies whether to add the existing ECS or ECI instances in the scaling group to the new server groups. Valid values:

  • true: Adds the instances.

  • false: Does not add the instances.

Default value: false.

ServerGroup.N.ServerGroupId

String

Yes

sgp-60ofsqhwer0b***

The ID of the server group.

ServerGroup.N.Type

String

Yes

ALB

The type of the server group. Valid values:

  • ALB: Application Load Balancer.

  • NLB: Network Load Balancer.

  • GWLB: Gateway Load Balancer.

ServerGroup.N.Weight

Integer

No

100

The weight of an ECS or ECI instance as a backend server. Valid values: 0 to 100.

A higher weight value indicates that more access requests are distributed to the instance. If the weight is 0, no access requests are distributed to the instance.

Note

This parameter is required for ALB and NLB server groups. You cannot set this parameter for GWLB server groups.

ServerGroup.N.Port

Integer

No

22

The port number used by the ECS or ECI instance as a backend server.

Valid values: 1 to 65535.

Note

This parameter is required for ALB and NLB server groups. You cannot set this parameter for GWLB server groups. For GWLB server groups, the default port is 6081.

Response parameters

Parameter

Type

Example

Description

ScalingActivityId

String

asa-bp1c9djwrgxjyk31****

The ID of the scaling activity that attaches the server groups and adds the instances in the scaling group to the server groups.

Note

This parameter is returned only if ForceAttach is set to true.

RequestId

String

74C4E313-8570-479F-8791-DC25360D****

The request ID.

Examples

Sample request

http(s)://ess.aliyuncs.com/?Action=AttachServerGroups
&RegionId=cn-hangzhou
&ScalingGroupId=asg-bp18p2yfxow2dloq****
&ClientToken=123e4567-e89b-12d3-a456-42665544****
&ForceAttach=false
&ServerGroup=[{"ServerGroupId":"sgp-60ofsqhwer0b***","Type":"ALB","Weight":100,"Port":22}]
&Common request parameters

Sample response

XML format

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

<AttachServerGroupsResponse>
    <ScalingActivityId>asa-bp1c9djwrgxjyk31****</ScalingActivityId>
    <RequestId>74C4E313-8570-479F-8791-DC25360D****</RequestId>
</AttachServerGroupsResponse>

JSON format

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

{
  "ScalingActivityId" : "asa-bp1c9djwrgxjyk31****",
  "RequestId" : "74C4E313-8570-479F-8791-DC25360D****"
}

Error codes

For a list of error codes, see Error Center.