All Products
Search
Document Center

Auto Scaling:AttachLoadBalancers

更新時間:May 10, 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.

Usage notes

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 types of the load balancer and the scaling group are 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 one 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

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter

Type

Required

Example

Description

Action

String

Yes

AttachLoadBalancers

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

ScalingGroupId

String

Yes

asg-bp1avr6ensitts3w****

The ID of the scaling group.

ForceAttach

Boolean

No

false

Specifies whether to add all instances in the current scaling group to the backend server groups of the Classic Load Balancer (CLB, formerly known as SLB) instance marked for attachment. Valid values:

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

    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 operation does not entail the addition of the existing instances in the scaling group to the backend server groups of the CLB instance.

Default value: false.

ClientToken

String

No

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

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.

Async

Boolean

No

false

Specifies whether to perform the attachment operation asynchronously. Asynchronous calls uphold the transactional integrity of operations, ensuring that execution outcomes are applied only when all operations complete successfully. We recommend that you set this parameter to true.

Valid values:

  • true: perform the attachment operation asynchronously. In this case, the ID of the scaling activity is returned.

  • false: does not perform the attachment operation asynchronously.

Default value: false.

LoadBalancer.N

String

No

lb-2zeur05gfs****

The ID of CLB instance N. Valid values of N: 1 to 5.

Note

You can attach up to five load balancers to a scaling group in one call.

LoadBalancerConfig.N.LoadBalancerId

String

No

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

The ID of the CLB instance.

LoadBalancerConfig.N.Weight

Integer

No

10

The weight of each instance as a backend server. A higher weight setting specifies that an instance will be allocated a larger proportion of incoming requests. If an instance is assigned a weight of 0, it will not receive any access requests.

Valid values: 0 to 100.

Response parameters

Parameter

Type

Example

Description

ScalingActivityId

String

asa-bp140qd7mak8k63f****

The ID of the scaling activity.

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

RequestId

String

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

The request ID.

Examples

Sample requests

http(s)://ess.aliyuncs.com/?Action=AttachLoadBalancers
&ScalingGroupId=asg-bp1avr6ensitts3w****
&ForceAttach=false
&ClientToken=123e4567-e89b-12d3-a456-42665544****
&Async=false
&LoadBalancer=["lb-2zeur05gfs****"]
&LoadBalancerConfig=[{"LoadBalancerId":"147b46d767c-cn-qingdao-cm5****","Weight":10}]
&<Common request parameters>

Sample success responses

XML format

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

<AttachLoadBalancersResponse>
    <ScalingActivityId>asa-bp140qd7mak8k63f****</ScalingActivityId>
    <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3****</RequestId>
</AttachLoadBalancersResponse>

JSON format

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

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

Error codes

For a list of error codes, see Service error codes.

HTTP status code

Error code

Error message

Description

403

Forbidden.Unauthorized

A required authorization for the specified action is not supplied.

Auto Scaling is not authorized to call the operation.

404

InvalidScalingGroupId.NotFound

The specified scaling group does not exist.

The specified scaling group does not exist within the Alibaba Cloud account.

400

QuotaExceeded.LoadBalancer

LoadBalancer quota exceeded in the scaling group "%s".

The number of CLB instances that you can attach to the scaling group exceeds the upper limit.

404

InvalidLoadBalancerId.NotFound

The load balancer "%s" does not exist.

The specified CLB instance does not exist within the Alibaba Cloud account.

400

InvalidLoadBalancerId.RegionMismatch

The load balancer "%s" and the specified scaling group are not in the same Region.

The CLB instance and the scaling group do not reside in the same region.

400

IncorrectLoadBalancerStatus

The current status of the load balancer "%s" does not support this action.

The operation is not supported when the CLB instance is in the current state.

400

IncorrectLoadBalancerHealthCheck

The current health check type of the load balancer "%s" does not support this action.

The health check feature is not enabled for the CLB instance.

400

InvalidLoadBalancerId.VPCMismatch

The specified virtual switch and the instance in the load balancer "%s" are not in the same VPC.

The CLB instance and the scaling group do not reside in the same VPC.

400

QuotaExceeded.BackendServer

Backend server quota exceeded in the load balancer "%s".

The number of backend servers of the CLB instance exceeds the upper limit.

404

InvalidScalingConfigurationId.NotFound

The specified scaling configuration does not exist.

The scaling group has no scaling configuration that is enabled.