Skip to content

register_targets async

register_targets(
    *,
    config_overrides: Optional[AsyncElasticLoadBalancingv2ClientConfig] = None,
    target_group_arn: Optional[TargetGroupArn] = None,
    targets: Optional[TargetDescriptions] = None,
) -> RegisterTargetsOutput

Registers the specified targets with the specified target group.

If the target is an EC2 instance, it must be in the running state when you register it.

By default, the load balancer routes requests to registered targets using the protocol and port for the target group. Alternatively, you can override the port for a target when you register it. You can register each EC2 instance or IP address with the same target group multiple times using different ports.

For more information, see the following:

Parameters:

Raises:

Examples:

To register targets with a target group This example registers the specified instances with the specified target group.

>>> await client.register_targets(target_group_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067', targets=[{'Id': 'i-80c8dd94'}, {'Id': 'i-ceddcd4d'}])
To register targets with a target group using port overrides
This example registers the specified instance with the specified target group using multiple ports. This enables you to register ECS containers on the same instance as targets in the target group.
>>> await client.register_targets(target_group_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-new-targets/3bb63f11dfb0faf9', targets=[{'Id': 'i-80c8dd94', 'Port': 80}, {'Id': 'i-80c8dd94', 'Port': 766}])
Source code in docs_src/capo_elastic_load_balancing_v2/_services/async_elastic_load_balancingv2.py
async def register_targets(
    self,
    *,
    config_overrides: Optional[AsyncElasticLoadBalancingv2ClientConfig] = None,
    target_group_arn: Optional[
        "capo_elastic_load_balancing_v2.types.target_group_arn.TargetGroupArn"
    ] = None,
    targets: Optional[
        "capo_elastic_load_balancing_v2.types.target_descriptions.TargetDescriptions"
    ] = None,
) -> "capo_elastic_load_balancing_v2.types.register_targets_output.RegisterTargetsOutput":
    """<p>Registers the specified targets with the specified target group.</p> <p>If the target is an EC2 instance, it must be in the <code>running</code> state when you register it.</p> <p>By default, the load balancer routes requests to registered targets using the protocol and port for the target group. Alternatively, you can override the port for a target when you register it. You can register each EC2 instance or IP address with the same target group multiple times using different ports.</p> <p>For more information, see the following:</p> <ul> <li> <p> <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-register-targets.html">Register targets for your Application Load Balancer</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/network/target-group-register-targets.html">Register targets for your Network Load Balancer</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/gateway/target-group-register-targets.html">Register targets for your Gateway Load Balancer</a> </p> </li> </ul>

    Args:
        target_group_arn: <p>The Amazon Resource Name (ARN) of the target group.</p>
        targets: <p>The targets.</p>

    Raises:
        capo_elastic_load_balancing_v2.errors.invalid_target_exception.InvalidTargetException: <p>The specified target does not exist, is not in the same VPC as the target group, or has an unsupported instance type.</p>
        capo_elastic_load_balancing_v2.errors.target_group_not_found_exception.TargetGroupNotFoundException: <p>The specified target group does not exist.</p>
        capo_elastic_load_balancing_v2.errors.too_many_registrations_for_target_id_exception.TooManyRegistrationsForTargetIdException: <p>You've reached the limit on the number of times a target can be registered with a load balancer.</p>
        capo_elastic_load_balancing_v2.errors.too_many_targets_exception.TooManyTargetsException: <p>You've reached the limit on the number of targets.</p>
        capo_elastic_load_balancing_v2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To register targets with a target group
        This example registers the specified instances with the specified target group.

        >>> await client.register_targets(target_group_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067', targets=[{'Id': 'i-80c8dd94'}, {'Id': 'i-ceddcd4d'}])
        To register targets with a target group using port overrides
        This example registers the specified instance with the specified target group using multiple ports. This enables you to register ECS containers on the same instance as targets in the target group.

        >>> await client.register_targets(target_group_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-new-targets/3bb63f11dfb0faf9', targets=[{'Id': 'i-80c8dd94', 'Port': 80}, {'Id': 'i-80c8dd94', 'Port': 766}])
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_elastic_load_balancing_v2.types.register_targets_input.RegisterTargetsInput]",
    ) -> AsyncOperationResponse[
        "capo_elastic_load_balancing_v2.types.register_targets_output.RegisterTargetsOutput"
    ]:
        import capo_elastic_load_balancing_v2._operations.elastic_load_balancing_v10.register_targets

        (
            output,
            http_response,
        ) = await capo_elastic_load_balancing_v2._operations.elastic_load_balancing_v10.register_targets.async_register_targets(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("RegisterTargets")
    )
    input_: capo_elastic_load_balancing_v2.types.register_targets_input.RegisterTargetsInput = {}
    if target_group_arn is not None:
        input_["target_group_arn"] = target_group_arn
    if targets is not None:
        input_["targets"] = targets

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output