Sub topic 14
Connecting to on-premises with Site-to-Site VPN and Direct Connect
This chapter assumes you know CIDR notation, how route tables send traffic to targets, and how a VPC attaches to gateways. It covers the two main ways to link a VPC to an on-premises network: AWS Site-to-Site VPN and AWS Direct Connect.
The working model
Both options need a gateway on the AWS side and a device on your side. Traffic between your data center and the VPC then follows routes in the VPC route table, like any other target.
- A virtual private gateway (VGW) attaches to one VPC. It is the AWS endpoint for a VPN or a Direct Connect private virtual interface.
- A Transit Gateway can terminate the same connections for many VPCs, as the previous chapter described.
- A customer gateway is the AWS resource that records the public IP address and BGP ASN of your on-premises router or firewall.
Site-to-Site VPN
Site-to-Site VPN builds IPsec tunnels over the public internet. Each VPN connection has two tunnels that end in different AWS Availability Zones, so one tunnel can fail without dropping the link. Each tunnel supports up to about 1.25 Gbps. Latency and jitter vary because the traffic shares the internet.
Create the pieces with the CLI:
CGW_ID=$(aws ec2 create-customer-gateway --type ipsec.1 --bgp-asn 65000 --public-ip 203.0.113.10 --query CustomerGateway.CustomerGatewayId --output text)
VGW_ID=$(aws ec2 create-vpn-gateway --type ipsec.1 --query VpnGateway.VpnGatewayId --output text)
aws ec2 attach-vpn-gateway --vpn-gateway-id "$VGW_ID" --vpc-id "$VPC_ID"
aws ec2 create-vpn-connection --type ipsec.1 --customer-gateway-id "$CGW_ID" --vpn-gateway-id "$VGW_ID"
aws ec2 enable-vgw-route-propagation --route-table-id "$PRIVATE_RT_ID" --gateway-id "$VGW_ID"Route propagation copies the routes learned from your router into the route table. Without it, or without static routes, the VPC has no path to your network.
Direct Connect
Direct Connect is a dedicated physical link from your network to AWS at a Direct Connect location. It does not cross the public internet. You get predictable latency and steady throughput, with port speeds from 1 Gbps to 100 Gbps, and hosted connections at lower speeds through partners. Setup takes weeks because it involves a cross-connect and a provider.
You run logical virtual interfaces (VIFs) over the link:
| VIF type | Reaches |
|---|---|
| Private | One VPC through a VGW, or many through a Direct Connect gateway |
| Transit | Transit Gateways through a Direct Connect gateway |
| Public | AWS public endpoints such as S3 |
Direct Connect does not encrypt traffic by default. If you need encryption, run a VPN over it or use MACsec on supported ports.
Choosing between them
| Need | Better fit |
|---|---|
| Up in minutes, low cost, moderate bandwidth | Site-to-Site VPN |
| Consistent latency, high bandwidth | Direct Connect |
| Encrypted by default | Site-to-Site VPN |
| Highest availability | Direct Connect with a VPN as backup |
Common errors
- Overlapping CIDR blocks. If your on-premises range overlaps the VPC range, routing cannot tell which side owns an address. Plan ranges before you connect.
- Tunnel down. Check that your device allows UDP 500 and 4500 and that the customer gateway IP is correct.
- No route propagation. The tunnel is up but traffic fails because the route table has no entry for your on-premises range.
- Blocked by firewalls. Security groups and network ACLs still apply. Allow the on-premises CIDR explicitly.
- Single path. One VPN tunnel or one Direct Connect link is a single point of failure. Use both tunnels, and add a second connection for critical workloads.
Exercise
Your on-premises router's VPN tunnels show as up, but instances in the private subnet cannot reach on-premises hosts. What do you check first?
Show answer
Check that the private subnet's route table has a route to the on-premises CIDR, either through route propagation from the virtual private gateway or a static route. Then confirm security groups and network ACLs allow that CIDR.
Exercise
A team needs a link with steady latency and 10 Gbps of bandwidth, and it must be running in two days. Which option fits, and why might it not?
Show answer
Direct Connect fits the performance need, but its cross-connect and provider work usually takes weeks. A Site-to-Site VPN can serve as a stopgap, though each tunnel is limited to about 1.25 Gbps.