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.
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
public virtual RegisterTargetsResponse RegisterTargets( RegisterTargetsRequest request )
Container for the necessary parameters to execute the RegisterTargets service method.
Exception | Condition |
---|---|
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. |
This example registers the specified instances with the specified 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.
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 } } });
.NET Framework:
Supported in: 4.5, 4.0, 3.5