文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
将 CreateVpnConnection
与 CLI 配合使用
以下代码示例演示如何使用 CreateVpnConnection
。
- CLI
-
- AWS CLI
-
示例 1:创建使用动态路由的 VPN 连接
以下
create-vpn-connection
示例将在指定的虚拟私有网关和指定的客户网关之间创建 VPN 连接,并将标签应用于 VPN 连接。输出包括 XML 格式的客户网关设备的配置信息。aws ec2 create-vpn-connection \ --type
ipsec.1
\ --customer-gateway-idcgw-001122334455aabbc
\ --vpn-gateway-idvgw-1a1a1a1a1a1a2b2b2
\ --tag-specification 'ResourceType=vpn-connection,Tags=[{Key=Name,Value=BGP-VPN}]
'输出:
{ "VpnConnection": { "CustomerGatewayConfiguration": "...configuration information...", "CustomerGatewayId": "cgw-001122334455aabbc", "Category": "VPN", "State": "pending", "VpnConnectionId": "vpn-123123123123abcab", "VpnGatewayId": "vgw-1a1a1a1a1a1a2b2b2", "Options": { "EnableAcceleration": false, "StaticRoutesOnly": false, "LocalIpv4NetworkCidr": "0.0.0.0/0", "RemoteIpv4NetworkCidr": "0.0.0.0/0", "TunnelInsideIpVersion": "ipv4", "TunnelOptions": [ {}, {} ] }, "Routes": [], "Tags": [ { "Key": "Name", "Value": "BGP-VPN" } ] } }
有关更多信息,请参阅《 AWS Site-to-Site VPN 用户指南》中的AWS Site-to-Site VPN 工作原理。
示例 2:创建使用静态路由的 VPN 连接
以下
create-vpn-connection
示例将在指定的虚拟私有网关和指定的客户网关之间创建 VPN 连接。这些选项指定静态路由。输出包括 XML 格式的客户网关设备的配置信息。aws ec2 create-vpn-connection \ --type
ipsec.1
\ --customer-gateway-idcgw-001122334455aabbc
\ --vpn-gateway-idvgw-1a1a1a1a1a1a2b2b2
\ --options "{\"StaticRoutesOnly\":true}"输出:
{ "VpnConnection": { "CustomerGatewayConfiguration": "..configuration information...", "CustomerGatewayId": "cgw-001122334455aabbc", "Category": "VPN", "State": "pending", "VpnConnectionId": "vpn-123123123123abcab", "VpnGatewayId": "vgw-1a1a1a1a1a1a2b2b2", "Options": { "EnableAcceleration": false, "StaticRoutesOnly": true, "LocalIpv4NetworkCidr": "0.0.0.0/0", "RemoteIpv4NetworkCidr": "0.0.0.0/0", "TunnelInsideIpVersion": "ipv4", "TunnelOptions": [ {}, {} ] }, "Routes": [], "Tags": [] } }
有关更多信息,请参阅《 AWS Site-to-Site VPN 用户指南》中的AWS Site-to-Site VPN 工作原理。
示例 3:创建 VPN 连接并指定您自己的内部 CIDR 和预共享密钥
以下
create-vpn-connection
示例将创建 VPN 连接,并为每个隧道指定内部 IP 地址 CIDR 块和自定义预共享密钥。将在CustomerGatewayConfiguration
信息中返回指定值。aws ec2 create-vpn-connection \ --type
ipsec.1
\ --customer-gateway-idcgw-001122334455aabbc
\ --vpn-gateway-idvgw-1a1a1a1a1a1a2b2b2
\ --options TunnelOptions='[{TunnelInsideCidr=169.254.12.0/30,PreSharedKey=ExamplePreSharedKey1},{TunnelInsideCidr=169.254.13.0/30,PreSharedKey=ExamplePreSharedKey2}]'输出:
{ "VpnConnection": { "CustomerGatewayConfiguration": "..configuration information...", "CustomerGatewayId": "cgw-001122334455aabbc", "Category": "VPN", "State": "pending", "VpnConnectionId": "vpn-123123123123abcab", "VpnGatewayId": "vgw-1a1a1a1a1a1a2b2b2", "Options": { "EnableAcceleration": false, "StaticRoutesOnly": false, "LocalIpv4NetworkCidr": "0.0.0.0/0", "RemoteIpv4NetworkCidr": "0.0.0.0/0", "TunnelInsideIpVersion": "ipv4", "TunnelOptions": [ { "OutsideIpAddress": "203.0.113.3", "TunnelInsideCidr": "169.254.12.0/30", "PreSharedKey": "ExamplePreSharedKey1" }, { "OutsideIpAddress": "203.0.113.5", "TunnelInsideCidr": "169.254.13.0/30", "PreSharedKey": "ExamplePreSharedKey2" } ] }, "Routes": [], "Tags": [] } }
有关更多信息,请参阅《 AWS Site-to-Site VPN 用户指南》中的AWS Site-to-Site VPN 工作原理。
示例 4:创建支持 IPv6 流量的 VPN 连接
以下
create-vpn-connection
示例创建一个 VPN 连接,该连接支持指定传输网关和指定客户网关之间的 IPv6 流量。两条隧道的隧道选项都指定 AWS 必须启动 IKE 协商。aws ec2 create-vpn-connection \ --type
ipsec.1
\ --transit-gateway-idtgw-12312312312312312
\ --customer-gateway-idcgw-001122334455aabbc
\ --optionsTunnelInsideIpVersion=ipv6,TunnelOptions=[{StartupAction=start},{StartupAction=start}]
输出:
{ "VpnConnection": { "CustomerGatewayConfiguration": "..configuration information...", "CustomerGatewayId": "cgw-001122334455aabbc", "Category": "VPN", "State": "pending", "VpnConnectionId": "vpn-11111111122222222", "TransitGatewayId": "tgw-12312312312312312", "Options": { "EnableAcceleration": false, "StaticRoutesOnly": false, "LocalIpv6NetworkCidr": "::/0", "RemoteIpv6NetworkCidr": "::/0", "TunnelInsideIpVersion": "ipv6", "TunnelOptions": [ { "OutsideIpAddress": "203.0.113.3", "StartupAction": "start" }, { "OutsideIpAddress": "203.0.113.5", "StartupAction": "start" } ] }, "Routes": [], "Tags": [] } }
有关更多信息,请参阅《 AWS Site-to-Site VPN 用户指南》中的AWS Site-to-Site VPN 工作原理。
-
有关 API 的详细信息,请参阅AWS CLI 命令参考CreateVpnConnection
中的。
-
- PowerShell
-
- 用于 PowerShell
-
示例 1:此示例在指定的虚拟专用网关和指定的客户网关之间创建 VPN 连接。输出包括您的网络管理员所需的配置信息,采用 XML 格式。
New-EC2VpnConnection -Type ipsec.1 -CustomerGatewayId cgw-1a2b3c4d -VpnGatewayId vgw-1a2b3c4d
输出:
CustomerGatewayConfiguration : [XML document] CustomerGatewayId : cgw-1a2b3c4d Options : Routes : {} State : pending Tags : {} Type : VgwTelemetry : {} VpnConnectionId : vpn-12345678 VpnGatewayId : vgw-1a2b3c4d
示例 2:此示例创建 VPN 连接并将配置捕获到具有指定名称的文件中。
(New-EC2VpnConnection -CustomerGatewayId cgw-1a2b3c4d -VpnGatewayId vgw-1a2b3c4d).CustomerGatewayConfiguration | Out-File C:\path\vpn-configuration.xml
示例 3:此示例使用静态路由在指定的虚拟专用网关和指定的客户网关之间创建一个 VPN 连接。
New-EC2VpnConnection -Type ipsec.1 -CustomerGatewayId cgw-1a2b3c4d -VpnGatewayId vgw-1a2b3c4d -Options_StaticRoutesOnly $true
-
有关 API 的详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考CreateVpnConnection中的。
-