This API operation is superseded by AttachTrafficSources, which can attach multiple traffic sources types. We recommend using AttachTrafficSources to simplify how you manage traffic sources. However, we continue to support AttachLoadBalancers. You can use both the original AttachLoadBalancers API operation and AttachTrafficSources on the same Auto Scaling group.
Attaches one or more Classic Load Balancers to the specified Auto Scaling group. Amazon EC2 Auto Scaling registers the running instances with these Classic Load Balancers.
To describe the load balancers for an Auto Scaling group, call the DescribeLoadBalancers API. To detach a load balancer from the Auto Scaling group, call the DetachLoadBalancers API.
This operation is additive and does not detach existing Classic Load Balancers or target groups from the Auto Scaling group.
For more information, see Use Elastic Load Balancing to distribute traffic across the instances in your Auto Scaling group in the Amazon EC2 Auto Scaling User Guide.
Parameters:
Raises:
Examples:
To attach a load balancer to an Auto Scaling group
This example attaches the specified load balancer to the specified Auto Scaling group.
>>> client.attach_load_balancers(auto_scaling_group_name='my-auto-scaling-group', load_balancer_names=['my-load-balancer'])
Source code in docs_src/capo_auto_scaling/_services/auto_scaling.py
| def attach_load_balancers(
self,
*,
config_overrides: Optional[AutoScalingClientConfig] = None,
auto_scaling_group_name: Optional[
"capo_auto_scaling.types.xml_string_max_len255.XmlStringMaxLen255"
] = None,
load_balancer_names: Optional[
"capo_auto_scaling.types.load_balancer_names.LoadBalancerNames"
] = None,
) -> "capo_auto_scaling.types.attach_load_balancers_result_type.AttachLoadBalancersResultType":
"""<note> <p>This API operation is superseded by <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_AttachTrafficSources.html">AttachTrafficSources</a>, which can attach multiple traffic sources types. We recommend using <code>AttachTrafficSources</code> to simplify how you manage traffic sources. However, we continue to support <code>AttachLoadBalancers</code>. You can use both the original <code>AttachLoadBalancers</code> API operation and <code>AttachTrafficSources</code> on the same Auto Scaling group.</p> </note> <p>Attaches one or more Classic Load Balancers to the specified Auto Scaling group. Amazon EC2 Auto Scaling registers the running instances with these Classic Load Balancers.</p> <p>To describe the load balancers for an Auto Scaling group, call the <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeLoadBalancers.html">DescribeLoadBalancers</a> API. To detach a load balancer from the Auto Scaling group, call the <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DetachLoadBalancers.html">DetachLoadBalancers</a> API.</p> <p>This operation is additive and does not detach existing Classic Load Balancers or target groups from the Auto Scaling group.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-load-balancer.html">Use Elastic Load Balancing to distribute traffic across the instances in your Auto Scaling group</a> in the <i>Amazon EC2 Auto Scaling User Guide</i>.</p>
Args:
auto_scaling_group_name: <p>The name of the Auto Scaling group.</p>
load_balancer_names: <p>The names of the load balancers. You can specify up to 10 load balancers.</p>
Raises:
capo_auto_scaling.errors.instance_refresh_in_progress_fault.InstanceRefreshInProgressFault: <p>The request failed because an active instance refresh already exists for the specified Auto Scaling group.</p>
capo_auto_scaling.errors.resource_contention_fault.ResourceContentionFault: <p>You already have a pending update to an Amazon EC2 Auto Scaling resource (for example, an Auto Scaling group, instance, or load balancer).</p>
capo_auto_scaling.errors.service_linked_role_failure.ServiceLinkedRoleFailure: <p>The service-linked role is not yet ready for use.</p>
capo_auto_scaling.errors.UnknownServiceError: The service returned an error code this client does not model.
Examples:
To attach a load balancer to an Auto Scaling group
This example attaches the specified load balancer to the specified Auto Scaling group.
>>> client.attach_load_balancers(auto_scaling_group_name='my-auto-scaling-group', load_balancer_names=['my-load-balancer'])
"""
def _handler(
req: "OperationRequest[capo_auto_scaling.types.attach_load_balancers_type.AttachLoadBalancersType]",
) -> OperationResponse[
"capo_auto_scaling.types.attach_load_balancers_result_type.AttachLoadBalancersResultType"
]:
import capo_auto_scaling._operations.auto_scaling_2011_01_01.attach_load_balancers
output, http_response = (
capo_auto_scaling._operations.auto_scaling_2011_01_01.attach_load_balancers.attach_load_balancers(
req.options, req.input
)
)
return OperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("AttachLoadBalancers")
)
input_: capo_auto_scaling.types.attach_load_balancers_type.AttachLoadBalancersType = {}
if auto_scaling_group_name is not None:
input_["auto_scaling_group_name"] = auto_scaling_group_name
if load_balancer_names is not None:
input_["load_balancer_names"] = load_balancer_names
response = execute_pipeline(
OperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
response.response.close()
return response.output
|