

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 搭配使用 `ReplaceRouteTableAssociation` 與 CLI
<a name="example_ec2_ReplaceRouteTableAssociation_section"></a>

下列程式碼範例示範如何使用 `ReplaceRouteTableAssociation`。

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

**AWS CLI**  
**取代與子網路相關聯的路由表**  
此範例會將指定的路由表，與指定之路由表關聯的子網路建立關聯。  
命令：  

```
aws ec2 replace-route-table-association --association-id rtbassoc-781d0d1a --route-table-id rtb-22574640
```
輸出：  

```
{
    "NewAssociationId": "rtbassoc-3a1f0f58"
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ReplaceRouteTableAssociation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/replace-route-table-association.html)。

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

**Tools for PowerShell V4**  
**範例 1：此範例會將指定的路由表，與指定之路由表關聯的子網路建立關聯。**  

```
Set-EC2RouteTableAssociation -RouteTableId rtb-1a2b3c4d -AssociationId rtbassoc-12345678
```
**輸出：**  

```
rtbassoc-87654321
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [ReplaceRouteTableAssociation](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例會將指定的路由表，與指定之路由表關聯的子網路建立關聯。**  

```
Set-EC2RouteTableAssociation -RouteTableId rtb-1a2b3c4d -AssociationId rtbassoc-12345678
```
**輸出：**  

```
rtbassoc-87654321
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ReplaceRouteTableAssociation](https://docs.aws.amazon.com/powershell/v5/reference)。

------

如需 AWS SDK 開發人員指南和程式碼範例的完整清單，請參閱 [使用 SDK 建立 Amazon EC2 資源 AWS](sdk-general-information-section.md)。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。