将 AttachVpnGateway 与 CLI 配合使用 - AWS SDK 代码示例

AWS 文档 SDK 示例 GitHub 存储库中还有更多 AWS SDK 示例。

AttachVpnGateway 与 CLI 配合使用

以下代码示例演示如何使用 AttachVpnGateway

CLI
AWS CLI

将虚拟专用网关连接到 VPC

以下 attach-vpn-gateway 示例将指定的虚拟专用网关连接到指定的 VPC。

aws ec2 attach-vpn-gateway \ --vpn-gateway-id vgw-9a4cacf3 \ --vpc-id vpc-a01106c2

输出:

{ "VpcAttachment": { "State": "attaching", "VpcId": "vpc-a01106c2" } }
  • 有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 AttachVpnGateway

PowerShell
Tools for PowerShell V4

示例 1:此示例将指定的虚拟专用网关连接到指定的 VPC。

Add-EC2VpnGateway -VpnGatewayId vgw-1a2b3c4d -VpcId vpc-12345678

输出

State VpcId ----- ----- attaching vpc-12345678
  • 有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet Reference (V4)》中的 AttachVpnGateway

Tools for PowerShell V5

示例 1:此示例将指定的虚拟专用网关连接到指定的 VPC。

Add-EC2VpnGateway -VpnGatewayId vgw-1a2b3c4d -VpcId vpc-12345678

输出

State VpcId ----- ----- attaching vpc-12345678
  • 有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet Reference (V5)》中的 AttachVpnGateway