AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

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.

With a Network Load Balancer, you cannot register instances by instance ID if they have the following instance types: C1, CC1, CC2, CG1, CG2, CR1, CS1, G1, G2, HI1, HS1, M1, M2, M3, and T1. You can register instances of these types by IP address.

Note:

For .NET Core this operation is only available in asynchronous form. Please refer to RegisterTargetsAsync.

Namespace: Amazon.ElasticLoadBalancingV2
Assembly: AWSSDK.ElasticLoadBalancingV2.dll
Version: 3.x.y.z

Syntax

C#
public virtual RegisterTargetsResponse RegisterTargets(
         RegisterTargetsRequest request
)

Parameters

request
Type: Amazon.ElasticLoadBalancingV2.Model.RegisterTargetsRequest

Container for the necessary parameters to execute the RegisterTargets service method.

Return Value


The response from the RegisterTargets service method, as returned by ElasticLoadBalancingV2.

Exceptions

ExceptionCondition
InvalidTargetException The specified target does not exist, is not in the same VPC as the target group, or has an unsupported instance type.
TargetGroupNotFoundException The specified target group does not exist.
TooManyRegistrationsForTargetIdException You've reached the limit on the number of times a target can be registered with a load balancer.
TooManyTargetsException You've reached the limit on the number of targets.

Examples

This example registers the specified instances with the specified target group.

To register targets with a target group


var client = new AmazonElasticLoadBalancingV2Client();
var response = client.RegisterTargets(new RegisterTargetsRequest 
{
    TargetGroupArn = "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067",
    Targets = new List<TargetDescription> {
        new TargetDescription { Id = "i-80c8dd94" },
        new TargetDescription { Id = "i-ceddcd4d" }
    }
});


            

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.

To register targets with a target group using port overrides


var client = new AmazonElasticLoadBalancingV2Client();
var response = client.RegisterTargets(new RegisterTargetsRequest 
{
    TargetGroupArn = "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-new-targets/3bb63f11dfb0faf9",
    Targets = new List<TargetDescription> {
        new TargetDescription {
            Id = "i-80c8dd94",
            Port = 80
        },
        new TargetDescription {
            Id = "i-80c8dd94",
            Port = 766
        }
    }
});


            

Version Information

.NET Framework:
Supported in: 4.5, 4.0, 3.5

See Also