Subchapter 94.5
references/creating-a-site-to-site-vpn-connection.mdMarkdown17 KBView on GitHub
Domain expertise for building an AWS Site-to-Site VPN connection: an encrypted IP Security (IPsec) tunnel between an on-premises network and a VPC. Covers the target gateway decision (virtual private gateway, transit gateway, or AWS Cloud WAN), the fixed order of the dependent resources, the customer gateway as metadata only, the distinct-ASN rule for a virtual private gateway, and choosing tunnel options at create time.
Does not cover the routing-type decision (the choosing-static-or-dynamic-routing reference), tunnel bandwidth sizing (the choosing-tunnel-bandwidth reference), the VPN Concentrator (its own reference), or applying the device configuration (the applying-the-customer-gateway-device-configuration reference). Settle routing type before running this procedure.
Execute commands using the AWS MCP server when connected (sandboxed execution, audit logging,
observability). Fall back to the AWS CLI otherwise. Site-to-Site VPN is regional; pass
--region {region} matching the VPC or transit gateway the connection terminates on.
To build the connection end to end, follow the procedure exactly. See the Procedure section below.
The procedure covers:
| Choice | Use when |
|---|---|
| Virtual private gateway (VGW) | The VPN terminates at a single VPC and the customer needs no more than 1.25 Gbps per tunnel |
| Transit gateway | The VPN fronts many VPCs, needs Large (5 Gbps) tunnels, needs ECMP bandwidth aggregation, or will use a VPN Concentrator |
| AWS Cloud WAN core network | The VPN attaches to a Cloud WAN core network |
Constraints:
The connection only works after several resources are in place in the right order. Creating the VPN connection first and stopping there leaves traffic with nowhere to flow, and no single error points at the missing piece.
Constraints:
The customer gateway resource in AWS is only metadata: it gives AWS the device’s public IP address and routing details. Customers read “gateway” and assume creating it configures their device. It does not; the device configuration is a separate step the customer owns.
Constraints:
When the target gateway is a virtual private gateway, the Autonomous System Number (ASN) on the AWS side must differ from the customer gateway ASN, and the gateway must be attached to the VPC before anything routes.
Constraints:
Customers accept the default tunnel options at creation, then later need stronger algorithms and discover that modifying tunnel or connection options replaces the tunnel endpoints and interrupts connectivity.
Constraints:
Route propagation or the security group rule is missing. Confirm both (Creation order).
The AWS-side and customer gateway ASNs match, or the gateway is not attached. Set distinct ASNs and attach (Distinct ASNs).
The customer gateway resource is metadata only. The device configuration is the customer’s separate step (The customer gateway is metadata only).
Large tunnels need a transit gateway. Rebuild the target gateway on a transit gateway (Decision).
This procedure creates the customer gateway, the target gateway, the routing and security group configuration, and the VPN connection in the required order, then surfaces the console link to verify status and download the device configuration.
vpn-gateway, transit-gateway, core-network, or vpn-concentrator. If the customer says vpn-concentrator, redirect to the connecting-many-sites-with-a-vpn-concentrator reference.create-transit-gateway response in Step 3.static or dynamic, settled in the choosing-static-or-dynamic-routing reference.create-customer-gateway always requires --bgp-asn. For dynamic routing, use the real ASN of the on-premises device. For static routing, supply a placeholder (for example, 65000).customer_gateway_asn. If the customer does not specify one, use the AWS default 64512.Constraints for parameter acquisition:
Constraints:
aws sts get-caller-identityConstraints:
You MUST create the customer gateway describing the on-premises device:
aws ec2 create-customer-gateway --type ipsec.1 --public-ip {customer_gateway_ip} \
--bgp-asn {customer_gateway_asn} --region {region}If the customer’s BGP ASN is larger than 2,147,483,647 (a 32-bit ASN), you MUST use --bgp-asn-extended instead of --bgp-asn:
aws ec2 create-customer-gateway --type ipsec.1 --public-ip {customer_gateway_ip} \
--bgp-asn-extended {customer_gateway_asn} --region {region}--bgp-asn accepts values 1 to 2,147,483,647; --bgp-asn-extended accepts 2,147,483,648 to 4,294,967,295.
You MUST capture the CustomerGatewayId from the response
Constraints:
You MUST create the chosen target gateway. For a virtual private gateway, create it and attach it to the VPC:
aws ec2 create-vpn-gateway --type ipsec.1 --amazon-side-asn {aws_side_asn} --region {region}
aws ec2 attach-vpn-gateway --vpn-gateway-id {vpn_gateway_id} --vpc-id {vpc_id} --region {region}For a transit gateway, create it (or select an existing one) and attach it to the VPC. The VPN connection is associated with the transit gateway in Step 5; the VPC attachment carries VPN traffic into the VPC:
aws ec2 create-transit-gateway --options AmazonSideAsn={aws_side_asn} --region {region}
aws ec2 create-transit-gateway-vpc-attachment --transit-gateway-id {transit_gateway_id} \
--vpc-id {vpc_id} --subnet-ids {subnet_ids} --region {region}You MUST set an AWS-side ASN distinct from the customer gateway ASN for a virtual private gateway
Constraints:
Constraints:
You MUST create the connection against the target gateway and customer gateway, with the chosen routing type and tunnel options. For a virtual private gateway target, pass --vpn-gateway-id; for a transit gateway target, pass --transit-gateway-id instead:
# Virtual private gateway target
aws ec2 create-vpn-connection --type ipsec.1 --customer-gateway-id {customer_gateway_id} \
--vpn-gateway-id {vpn_gateway_id} \
--pre-shared-key-storage SecretsManager \
--options "StaticRoutesOnly={true_if_static},TunnelOptions=[{Phase1EncryptionAlgorithms=[{Value=AES256}],Phase2EncryptionAlgorithms=[{Value=AES256}],Phase1IntegrityAlgorithms=[{Value=SHA2-256}],Phase2IntegrityAlgorithms=[{Value=SHA2-256}],Phase1DHGroupNumbers=[{Value=14}],Phase2DHGroupNumbers=[{Value=14}]},{Phase1EncryptionAlgorithms=[{Value=AES256}],Phase2EncryptionAlgorithms=[{Value=AES256}],Phase1IntegrityAlgorithms=[{Value=SHA2-256}],Phase2IntegrityAlgorithms=[{Value=SHA2-256}],Phase1DHGroupNumbers=[{Value=14}],Phase2DHGroupNumbers=[{Value=14}]}]" \
--region {region}
# Transit gateway target
aws ec2 create-vpn-connection --type ipsec.1 --customer-gateway-id {customer_gateway_id} \
--transit-gateway-id {transit_gateway_id} \
--pre-shared-key-storage SecretsManager \
--options "StaticRoutesOnly={true_if_static},TunnelOptions=[{Phase1EncryptionAlgorithms=[{Value=AES256}],Phase2EncryptionAlgorithms=[{Value=AES256}],Phase1IntegrityAlgorithms=[{Value=SHA2-256}],Phase2IntegrityAlgorithms=[{Value=SHA2-256}],Phase1DHGroupNumbers=[{Value=14}],Phase2DHGroupNumbers=[{Value=14}]},{Phase1EncryptionAlgorithms=[{Value=AES256}],Phase2EncryptionAlgorithms=[{Value=AES256}],Phase1IntegrityAlgorithms=[{Value=SHA2-256}],Phase2IntegrityAlgorithms=[{Value=SHA2-256}],Phase1DHGroupNumbers=[{Value=14}],Phase2DHGroupNumbers=[{Value=14}]}]" \
--region {region}You MUST use --pre-shared-key-storage SecretsManager to store PSKs in AWS Secrets Manager so they are not returned as plain text in APIs like describe-vpn-connections; this incurs a small additional Secrets Manager cost per secret
You MUST set strong tunnel options (AES-256, SHA-256 or higher, Diffie-Hellman group 14 or higher) rather than the AES-128 / SHA-1 / DH group 2 minimums
You MUST supply two TunnelOptions objects, one per tunnel, since every connection has two tunnels; a single-element array leaves Tunnel 2 on the weak AES-128 / SHA-1 / DH group 2 defaults
You SHOULD enable Site-to-Site VPN logs at create time so tunnel establishment and BGP events are captured from the start; see the monitoring-and-troubleshooting-tunnels reference for setup
Constraints:
You MUST confirm the connection and its tunnels reach the expected state:
aws ec2 describe-vpn-connections --vpn-connection-ids {vpn_connection_id} --region {region}You MUST present the VPN connection console link, filling {region} and {vpnConnectionId} from
the API response, and tell the customer to open it, confirm the connection, and download the
device configuration:
https://console.aws.amazon.com/vpc/home?region={region}#VpnConnectionDetails:VpnConnectionId={vpnConnectionId}{
"region": "us-east-1",
"target_gateway_type": "transit-gateway",
"vpc_id": "vpc-0abc1234def567890",
"subnet_ids": ["subnet-0abc1234def567890", "subnet-0fed9876cba543210"],
"aws_side_asn": 64512,
"customer_gateway_ip": "203.0.113.10",
"routing_type": "dynamic",
"customer_gateway_asn": 65010
}Created customer gateway (203.0.113.10, ASN 65010) and the VPN connection on the transit gateway,
dynamic routing. Route propagation enabled and the security group updated.
Open the VPN connection in the console, confirm both tunnels, and download the device configuration:
https://console.aws.amazon.com/vpc/home?region=us-east-1#VpnConnectionDetails:VpnConnectionId=vpn-0abc1234def567890Route propagation or the security group rule is missing. Confirm both (Step 4).
ASNs match or the gateway is not attached. Set distinct ASNs and attach (Step 3).
The customer gateway is metadata. Hand off to the applying-the-customer-gateway-device-configuration reference.
Creating the connection sets the authentication and encryption posture the tunnels run with, so the security choices belong at create time, when changing them is free.
Constraints:
0.0.0.0/0