

文档 AWS SDK 示例 GitHub 存储库中还有更多 [S AWS DK 示例](https://github.com/awsdocs/aws-doc-sdk-examples)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 将 `RegisterInstancesWithLoadBalancer` 与 CLI 配合使用
<a name="elastic-load-balancing_example_elastic-load-balancing_RegisterInstancesWithLoadBalancer_section"></a>

以下代码示例演示如何使用 `RegisterInstancesWithLoadBalancer`。

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

**AWS CLI**  
**将实例注册到负载均衡器**  
此示例将指定的实例注册到指定的负载均衡器。  
命令:  

```
aws elb register-instances-with-load-balancer --load-balancer-name {{my-load-balancer}} --instances {{i-d6f6fae3}}
```
输出：  

```
{
   "Instances": [
       {
           "InstanceId": "i-d6f6fae3"
       },
       {
           "InstanceId": "i-207d9717"
       },
       {
           "InstanceId": "i-afefb49b"
       }
   ]
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[RegisterInstancesWithLoadBalancer](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/elb/register-instances-with-load-balancer.html)*中的。

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例将指定的 EC2 实例注册到指定的负载均衡器。**  

```
Register-ELBInstanceWithLoadBalancer -LoadBalancerName my-load-balancer -Instance i-12345678
```
**输出**：  

```
InstanceId
----------
i-12345678
i-87654321
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [RegisterInstancesWithLoadBalancer](https://docs.aws.amazon.com/powershell/v4/reference)中的。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的 EC2 实例注册到指定的负载均衡器。**  

```
Register-ELBInstanceWithLoadBalancer -LoadBalancerName my-load-balancer -Instance i-12345678
```
**输出**：  

```
InstanceId
----------
i-12345678
i-87654321
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [RegisterInstancesWithLoadBalancer](https://docs.aws.amazon.com/powershell/v5/reference)中的。

------