Skip to content

attach_load_balancer_target_groups

attach_load_balancer_target_groups(
    *,
    config_overrides: Optional[AutoScalingClientConfig] = None,
    auto_scaling_group_name: Optional[XmlStringMaxLen255] = None,
    target_group_ar_ns: Optional[TargetGroupARNs] = None,
) -> AttachLoadBalancerTargetGroupsResultType

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 AttachLoadBalancerTargetGroups. You can use both the original AttachLoadBalancerTargetGroups API operation and AttachTrafficSources on the same Auto Scaling group.

Attaches one or more target groups to the specified Auto Scaling group.

This operation is used with the following load balancer types:

  • Application Load Balancer - Operates at the application layer (layer 7) and supports HTTP and HTTPS.

  • Network Load Balancer - Operates at the transport layer (layer 4) and supports TCP, TLS, and UDP.

  • Gateway Load Balancer - Operates at the network layer (layer 3).

To describe the target groups for an Auto Scaling group, call the DescribeLoadBalancerTargetGroups API. To detach the target group from the Auto Scaling group, call the DetachLoadBalancerTargetGroups API.

This operation is additive and does not detach existing target groups or Classic Load Balancers 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:

  • auto_scaling_group_name (Optional[XmlStringMaxLen255], default: None ) –

    The name of the Auto Scaling group.

  • target_group_ar_ns (Optional[TargetGroupARNs], default: None ) –

    The Amazon Resource Names (ARNs) of the target groups. You can specify up to 10 target groups. To get the ARN of a target group, use the Elastic Load Balancing DescribeTargetGroups API operation.

Raises:

Examples:

To attach a target group to an Auto Scaling group This example attaches the specified target group to the specified Auto Scaling group.

>>> client.attach_load_balancer_target_groups(auto_scaling_group_name='my-auto-scaling-group', target_group_ar_ns=['arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067'])
Source code in docs_src/capo_auto_scaling/_services/auto_scaling.py
def attach_load_balancer_target_groups(
    self,
    *,
    config_overrides: Optional[AutoScalingClientConfig] = None,
    auto_scaling_group_name: Optional[
        "capo_auto_scaling.types.xml_string_max_len255.XmlStringMaxLen255"
    ] = None,
    target_group_ar_ns: Optional[
        "capo_auto_scaling.types.target_group_ar_ns.TargetGroupARNs"
    ] = None,
) -> "capo_auto_scaling.types.attach_load_balancer_target_groups_result_type.AttachLoadBalancerTargetGroupsResultType":
    """<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>AttachLoadBalancerTargetGroups</code>. You can use both the original <code>AttachLoadBalancerTargetGroups</code> API operation and <code>AttachTrafficSources</code> on the same Auto Scaling group.</p> </note> <p>Attaches one or more target groups to the specified Auto Scaling group.</p> <p>This operation is used with the following load balancer types: </p> <ul> <li> <p>Application Load Balancer - Operates at the application layer (layer 7) and supports HTTP and HTTPS. </p> </li> <li> <p>Network Load Balancer - Operates at the transport layer (layer 4) and supports TCP, TLS, and UDP. </p> </li> <li> <p>Gateway Load Balancer - Operates at the network layer (layer 3).</p> </li> </ul> <p>To describe the target groups for an Auto Scaling group, call the <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeLoadBalancerTargetGroups.html">DescribeLoadBalancerTargetGroups</a> API. To detach the target group from the Auto Scaling group, call the <a href="https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DetachLoadBalancerTargetGroups.html">DetachLoadBalancerTargetGroups</a> API.</p> <p>This operation is additive and does not detach existing target groups or Classic Load Balancers 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>
        target_group_ar_ns: <p>The Amazon Resource Names (ARNs) of the target groups. You can specify up to 10 target groups. To get the ARN of a target group, use the Elastic Load Balancing <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeTargetGroups.html">DescribeTargetGroups</a> API operation.</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 target group to an Auto Scaling group
        This example attaches the specified target group to the specified Auto Scaling group.

        >>> client.attach_load_balancer_target_groups(auto_scaling_group_name='my-auto-scaling-group', target_group_ar_ns=['arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067'])
    """

    def _handler(
        req: "OperationRequest[capo_auto_scaling.types.attach_load_balancer_target_groups_type.AttachLoadBalancerTargetGroupsType]",
    ) -> OperationResponse[
        "capo_auto_scaling.types.attach_load_balancer_target_groups_result_type.AttachLoadBalancerTargetGroupsResultType"
    ]:
        import capo_auto_scaling._operations.auto_scaling_2011_01_01.attach_load_balancer_target_groups

        output, http_response = (
            capo_auto_scaling._operations.auto_scaling_2011_01_01.attach_load_balancer_target_groups.attach_load_balancer_target_groups(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AttachLoadBalancerTargetGroups")
    )
    input_: capo_auto_scaling.types.attach_load_balancer_target_groups_type.AttachLoadBalancerTargetGroupsType = {}
    if auto_scaling_group_name is not None:
        input_["auto_scaling_group_name"] = auto_scaling_group_name
    if target_group_ar_ns is not None:
        input_["target_group_ar_ns"] = target_group_ar_ns

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output