

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

# 将 `AttachNetworkInterface` 与 CLI 配合使用
<a name="example_ec2_AttachNetworkInterface_section"></a>

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

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

**AWS CLI**  
**示例 1：将网络接口连接到实例**  
以下 `attach-network-interface` 示例将指定的网络接口连接到指定的实例。  

```
aws ec2 attach-network-interface \
    --network-interface-id eni-0dc56a8d4640ad10a \
    --instance-id i-1234567890abcdef0 \
    --device-index 1
```
输出：  

```
{
    "AttachmentId": "eni-attach-01a8fc87363f07cf9"
}
```
有关更多信息，请参阅《*Amazon EC2 用户指南*》中的[弹性网络接口](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html)。  
**示例 2：将网络接口连接到具有多个网卡的实例**  
以下 `attach-network-interface` 示例将指定的网络接口连接到指定的实例和网卡。  

```
aws ec2 attach-network-interface \
    --network-interface-id eni-07483b1897541ad83 \
    --instance-id i-01234567890abcdef \
    --network-card-index 1 \
    --device-index 1
```
输出：  

```
{
    "AttachmentId": "eni-attach-0fbd7ee87a88cd06c"
}
```
有关更多信息，请参阅《*Amazon EC2 用户指南*》中的[弹性网络接口](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[AttachNetworkInterface](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/attach-network-interface.html)*中的。

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

**适用于 PowerShell V4 的工具**  
**示例 1：此示例将指定的网络接口连接到指定的实例。**  

```
Add-EC2NetworkInterface -NetworkInterfaceId eni-12345678 -InstanceId i-1a2b3c4d -DeviceIndex 1
```
**输出**：  

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

**适用于 PowerShell V5 的工具**  
**示例 1：此示例将指定的网络接口连接到指定的实例。**  

```
Add-EC2NetworkInterface -NetworkInterfaceId eni-12345678 -InstanceId i-1a2b3c4d -DeviceIndex 1
```
**输出**：  

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

------

有关 S AWS DK 开发者指南和代码示例的完整列表，请参阅[使用 AWS SDK 创建 Amazon EC2 资源](sdk-general-information-section.md)。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。