文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
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" } ] } }
如需詳細資訊,請參閱 VPNWord AWS Site-to-Site 使用者指南中的 HowWord 運作。 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": [] } }
如需詳細資訊,請參閱 VPNWord AWS Site-to-Site 使用者指南中的 HowWord 運作。 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": [] } }
如需詳細資訊,請參閱 VPNWord AWS Site-to-Site 使用者指南中的 HowWord 運作。 AWS Site-to-Site VPN
範例 4:建立支援 VPN 流量的 IPv6 連線
下列
create-vpn-connection
範例會建立支援指定傳輸閘道與指定客戶閘道之間 IPv6 流量的 VPN 連線。兩個通道的通道選項會指定 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": [] } }
如需詳細資訊,請參閱 VPNWord AWS Site-to-Site 使用者指南中的 HowWord 運作。 AWS Site-to-Site VPN
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateVpnConnection
。
-
- PowerShell
-
- for 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。
-