All Products
Search
Document Center

Auto Scaling:AttachLoadBalancers

Last Updated:Dec 11, 2024

Attaches load balancers to a scaling group. Auto Scaling supports the attachment of load balancers to scaling groups. Load balancers help distribute the access traffic to the instances in scaling groups, which effectively improves the service performance of the scaling groups. You can call the AttachLoadBalancers operation to attach one or more load balancers to your scaling group.

Operation description

Before you call this operation, make sure that the following requirements are met:

  • The load balancer and the scaling group belong to the same Alibaba Cloud account and region.
  • The load balancer is in the Running state.
  • At least one listener is configured for the load balancer, and the health check feature is enabled for the load balancer.
  • If the network type of the load balancer and the scaling group is virtual private cloud (VPC), they use the same VPC.
  • If the network type of the scaling group is VPC, and that of the load balancer is classic network and a backend server of the load balancer uses a VPC, the scaling group and the backend server use the same VPC.
  • The attachment of load balancers ensures that the cumulative number of load balancers attached to the scaling group stays within the predefined maximum limit. For information about the load balancer quota, see Limits .

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:AttachLoadBalancersupdate
*ScalingGroup
acs:ess:{#regionId}:{#accountId}:scalinggroup/{#ScalingGroupId}
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
ScalingGroupIdstringYes

The ID of the scaling group.

asg-bp1avr6ensitts3w****
ForceAttachbooleanNo

Specifies whether to add the existing instances in the scaling group as backend servers of the load balancer. Valid values:

  • true: If you set this parameter to true, the attachment of the load balancer entails the addition of the existing instances in the scaling group to the backend server groups of the load balancer.

    **

    Note If a load balancer is currently attached to your scaling group, and you want to add the instances in your scaling group to the backend server groups of the load balancer, you can call this operation again and set the ForceAttach request parameter to true.

  • false: If you set this parameter to false, the attachment of the load balancer does not entail the addition of the existing instances in the scaling group to the backend server groups of the load balancer.

Default value: false.

false
ClientTokenstringNo

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****
AsyncbooleanNo

Specifies whether to attach the CLB instance to the scaling group in an asynchronous manner. If you attach the CLB instance from the scaling group in an asynchronous manner, the call is successful only after all operations are successful. If a specific operation fails, the call fails. We recommend that you set this parameter to true. Valid values:

  • true: attaches the CLB instance to the scaling group in an asynchronous manner. In this case, the ID of the scaling activity is returned.
  • false: does not attach the CLB instance to the scaling group in an asynchronous manner.

Default value: false.

false
LoadBalancersarrayNo

The IDs of the load balancers that you want to attach to the scaling group.

stringNo

The ID of the load balancer that you want to attach to the scaling group.

Note In each call, you can attach up to five load balancers to a scaling group.
lb-2zeur05gfs****
LoadBalancerConfigsarray<object>No

The configurations of the classic load balancer (CLB, formerly known as SLB) instance.

objectNo
LoadBalancerIdstringNo

The ID of the CLB instance.

147b46d767c-cn-qingdao-cm5****
WeightintegerNo

The weight of an Elastic Compute Service (ECS) instance or elastic container instance as a backend sever of the CLB instance. If an instance has a higher weight, more access traffic is routed to the instance. If an instance has zero weight, no access traffic is routed to the instance.

Valid values: 0 to 100.

10

Response parameters

ParameterTypeDescriptionExample
object
ScalingActivityIdstring

The ID of the scaling activity.

This parameter is returned only if you set Async to true. You can call the DescribeScalingActivities operation to query the scaling activity IDs and status.

asa-bp140qd7mak8k63f****
RequestIdstring

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

Examples

Sample success responses

JSONformat

{
  "ScalingActivityId": "asa-bp140qd7mak8k63f****",
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
}

Error codes

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

Change history

Change timeSummary of changesOperation
2023-03-30The request parameters of the API has changedView Change Details