文件範例儲存庫中有更多 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" } ] } }
如需詳細資訊,請參閱 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
範例會建立支援指定傳輸閘道與指定客戶閘道之間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": [] } }
如需詳細資訊,請參閱 AWS Site-to-Site VPN 使用者指南 中的如何 AWS Site-to-Site VPN運作。
-
如需API詳細資訊,請參閱 命令參考 CreateVpnConnection
中的 。 AWS CLI
-
- 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中的 。
-