

There are more AWS SDK examples available in the [AWS Doc SDK Examples](https://github.com/awsdocs/aws-doc-sdk-examples) GitHub repo.

# Use `RegisterTargets` with a CLI
<a name="elastic-load-balancing-v2_example_elastic-load-balancing-v2_RegisterTargets_section"></a>

The following code examples show how to use `RegisterTargets`.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example: 
+  [Getting started with Elastic Load Balancing](elastic-load-balancing-v2_example_elastic_load_balancing_v2_GettingStarted_058_section.md) 

------
#### [ CLI ]

**AWS CLI**  
**Example 1: To register targets with a target group by instance ID**  
The following `register-targets` example registers the specified instances with a target group. The target group must have a target type of `instance`.  

```
aws elbv2 register-targets \
    --target-group-arn {{arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067}} \
    --targets {{Id=i-1234567890abcdef0}} {{Id=i-0abcdef1234567890}}
```
**Example 2: To register targets with a target group using port overrides**  
The following `register-targets` example registers the specified instance with a target group using multiple ports. This enables you to register containers on the same instance as targets in the target group.  

```
aws elbv2 register-targets \
    --target-group-arn {{arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-internal-targets/3bb63f11dfb0faf9}} \
    --targets {{Id=i-0598c7d356eba48d7,Port=80}} {{Id=i-0598c7d356eba48d7,Port=766}}
```
**Example 3: To register targets with a target group by IP address**  
The following `register-targets` example registers the specified IP addresses with a target group. The target group must have a target type of `ip`.  

```
aws elbv2 register-targets \
    --target-group-arn {{arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-tcp-ip-targets/8518e899d173178f}} \
    --targets {{Id=10.0.1.15}} {{Id=10.0.1.23}}
```
**Example 4: To register a Lambda function as a target**  
The following `register-targets` example registers the specified IP addresses with a target group. The target group must have a target type of `lambda`. You must grant Elastic Load Balancing permission to invoke the Lambda function.  

```
aws elbv2 register-targets \
    --target-group-arn {{arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-tcp-ip-targets/8518e899d173178f}} \
    --targets {{Id=arn:aws:lambda:us-west-2:123456789012:function:my-function}}
```
+  For API details, see [RegisterTargets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/elbv2/register-targets.html) in *AWS CLI Command Reference*. 

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**Example 1: This example registers 'i-0672a4c4cdeae3111' instance with the specified target group.**  

```
Register-ELB2Target -TargetGroupArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test-tg/a4e04b3688be1970' -Target @{Port = 80; Id = 'i-0672a4c4cdeae3111'}
```
+  For API details, see [RegisterTargets](https://docs.aws.amazon.com/powershell/v4/reference) in *AWS Tools for PowerShell Cmdlet Reference (V4)*. 

**Tools for PowerShell V5**  
**Example 1: This example registers 'i-0672a4c4cdeae3111' instance with the specified target group.**  

```
Register-ELB2Target -TargetGroupArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test-tg/a4e04b3688be1970' -Target @{Port = 80; Id = 'i-0672a4c4cdeae3111'}
```
+  For API details, see [RegisterTargets](https://docs.aws.amazon.com/powershell/v5/reference) in *AWS Tools for PowerShell Cmdlet Reference (V5)*. 

------