Amazon AWS Transit Gateway
Last updated Oct 15, 2026 This guide provides step-by-step instructions for connecting an Amazon Web Services (AWS) Transit Gateway to Cloudflare WAN with redundant, route-based IPsec tunnels and Border Gateway Protocol (BGP). The primary topology uses:
- One Cloudflare anycast IP
- One AWS customer gateway
- One AWS Site-to-Site VPN connection with two IPsec tunnels
- Two BGP sessions between AWS Transit Gateway and Cloudflare WAN
Cloudflare assigns an IPv4 anycast IP to each Cloudflare WAN account, and additional anycast IPs are available from your account team. Because the anycast IP is served from Cloudflare data centers globally, a tunnel is not tied to a single Cloudflare server or data center. This guide uses one anycast IP for the baseline and supports a second anycast IP for customers who have one. For more information, refer to Anycast and Configure tunnel endpoints.
AWS Transit Gateway uses equal-cost multipath (ECMP) to distribute traffic across equal BGP paths. BGP dynamically exchanges routes and withdraws a path when its session fails. This design avoids the active/standby limitation of an AWS static-routing Site-to-Site VPN connection.
AWS requires a /30 inside tunnel network for each tunnel and supports a maximum Phase 1 lifetime of 28800 seconds. This guide uses /30 tunnel addressing and a 28800-second Phase 1 lifetime for that reason.
Support scope
This configuration is a reference example demonstrating known compatibility with Cloudflare services. It is not an officially supported AWS configuration. The steps and settings were tested in the test environment listed below. Adjustments may be required for other Regions or environments.
Terraform is recommended
Terraform is the recommended deployment method for this integration because it consistently applies the interdependent AWS, tunnel, routing, and Cloudflare WAN settings described in this guide. The Terraform reference deployment has been tested against the reference environment, and testing has not identified any issues.
Architecture
The general design uses the following resources:
- One AWS Transit Gateway with VPN ECMP support enabled
- One dedicated Transit Gateway route table for the workload VPC and AWS VPN attachments for Cloudflare WAN
- One or more workload VPCs attached to the Transit Gateway
- One AWS customer gateway for each configured Cloudflare anycast IP
- One dynamic-routing AWS Site-to-Site VPN connection for each customer gateway
- Two AWS-managed IPsec tunnels and two corresponding Cloudflare WAN IPsec tunnels per VPN connection
- One BGP session per tunnel between AWS Transit Gateway and Cloudflare WAN
The Terraform proof of concept creates:
- One workload VPC with exactly one public workload subnet
- Two Transit Gateway attachment subnets in separate Availability Zones
- One Internet Gateway for direct egress from the public workload subnet
- Selective routes that send only
vpn_routed_prefixesdestinations to the Transit Gateway
It does not create:
- Virtual machines or test hosts
- Standalone Elastic Network Interfaces (ENIs); AWS creates ENIs for the Transit Gateway VPC attachment in the attachment subnets
- Security groups
- Elastic IP addresses
- NAT services
The workload subnet assigns public IPv4 addresses on launch. Its route table sends only the more-specific destinations configured in vpn_routed_prefixes to the Transit Gateway and Site-to-Site VPNs; remaining IPv4 egress follows the 0.0.0.0/0 route to the Internet Gateway.
Terraform proof of concept: AWS workload VPC 192.168.0.0/16
Public workload subnet 192.168.125.0/24
Workload route table
+-- vpn_routed_prefixes (more-specific) --> AWS Transit Gateway ASN 65020
| |
| VPN connection 1
| |
| +----+----+
| | |
| Tunnel 1 Tunnel 2
| | |
| Cloudflare WAN ASN 13335
| 162.159.135.1
|
+-- 0.0.0.0/0 (remaining IPv4) --> Internet Gateway --> Internet
TGW attachment subnets: 192.168.124.0/28 and 192.168.124.16/28
The AWS Site-to-Site VPN connection terminates on one AWS customer gateway. Because an AWS customer gateway has one public IP address, both tunnels use the same Cloudflare anycast IP.
AWS tunnel model
AWS requires every Site-to-Site VPN connection to contain two tunnel objects and does not provide an option to define a single-tunnel connection. Tunnels 01 and 02 therefore both terminate on 162.159.135.1. Configure both tunnels for AWS redundancy, even though a connection can temporarily operate while only one tunnel is established.
Secondary anycast IP customers
Each leased anycast IP uses one AWS customer gateway and one Site-to-Site VPN connection. The first anycast IP uses tunnels 01 and 02, and the second uses tunnels 03 and 04. The Terraform configuration supports one or two distinct anycast IPs, with exactly two tunnel CIDRs and two PSKs for each anycast IP.
Test environment
| Field | Value |
|---|---|
| Cloud provider | Amazon Web Services |
| Services | AWS Transit Gateway and AWS Site-to-Site VPN |
| AWS Region | US East (Ohio), us-east-2 |
| Routing mode | Dynamic routing with BGP |
| AWS Transit Gateway ASN | 65020 |
| Cloudflare ASN | 13335 |
| Number of anycast IPs | Two |
| Number of VPN connections | Two |
| Number of IPsec tunnels | Four |
| Terraform AWS provider | hashicorp/aws 6.67.0 |
| Terraform Cloudflare provider | cloudflare/cloudflare 5.27.0 |
| Date tested | October 2026 |
The test environment used:
- Two leased anycast IPs
- Four IPsec tunnels
- Four BGP sessions
AWS imported the expected Cloudflare WAN routes on every configured tunnel, and Cloudflare learned the complete AWS VPC prefix.
The baseline deployment in this guide uses one anycast IP, one VPN connection, and two tunnels. It uses the same settings as the first VPN connection in the test environment. The baseline was not deployed on its own; its Terraform plan is covered by the included terraform test suite, which uses mock providers.
IKE/IPsec and BGP settings
| Field | Value |
|---|---|
| Traffic selection criteria | Route-based VPN |
| Routing | BGP |
| Tunnel forwarding | Active/active with ECMP |
| IKE version | IKEv2 |
| Authentication | Pre-shared key |
| Phase 1 encryption | AES-256-CBC |
| Phase 1 integrity | SHA-256 |
| Phase 1 DH group | Group 20 |
| Phase 1 lifetime | 28,800 seconds |
| Phase 2 encryption | AES-256-CBC |
| Phase 2 integrity | SHA-256 |
| Phase 2 PFS group | Group 20 |
| Phase 2 lifetime | 3,600 seconds |
| AWS replay window | 2,048 packets |
| Cloudflare replay protection | Enabled |
| NAT traversal (NAT-T) | Automatic |
| Dead Peer Detection action | Restart |
| Tunnel startup action | Start |
| AWS Transit Gateway ASN | 65020 |
| CF Account ASN | 13335 (default) |
| BGP authentication | None |
AWS Site-to-Site VPN does not support disabling anti-replay protection. Enable replay protection on each corresponding Cloudflare WAN tunnel and use the maximum AWS replay window of 2048. Replay protection can pin traffic for a tunnel to one Cloudflare server to preserve packet sequence, reducing some anycast performance and resilience benefits.
Pre-shared key requirements
Configure a pre-shared key that meets the following AWS requirements:
- Contains 8 to 64 characters
- Contains only letters, numbers, periods (
.), and underscores (_) - Does not begin with
0
Configure the same PSK on the matching AWS and Cloudflare WAN tunnel objects. In Cloudflare, select Use my own pre-shared key and enter the PSK configured on the AWS tunnel.
For more information, refer to VpnTunnelOptionsSpecification ↗︎ in the AWS documentation.
For the AWS console workflow, configure a unique PSK for each tunnel or reuse the same PSK across all tunnels. The Terraform workflow requires a unique PSK for each tunnel.
Use unique PSKs with Terraform
The Terraform AWS provider identifies which AWS public IPv4 address belongs to tunnel 1 by matching the tunnel 1 PSK. If both tunnels in a VPN connection use the same PSK, the provider cannot make that match and can assign the wrong AWS public IPv4 address to a Cloudflare WAN tunnel. IKE can still establish because the PSKs match, but BGP and tunnel health checks fail because the inside addresses do not match. The Terraform configuration rejects duplicate PSKs.
Configuration settings
Cloudflare WAN accepts a /31 or /30 interface address for each tunnel and recommends /31. For more information, refer to Configure tunnel endpoints.
AWS Site-to-Site VPN requires a unique /30 inside tunnel network for each tunnel, so this guide uses /30. AWS assigns the first usable IP address in the /30 to its side of the tunnel. Therefore, configure the second usable IP address on the Cloudflare WAN side. Cloudflare supports AWS inside tunnel networks selected from 169.254.240.0/20.
AWS and Cloudflare WAN also require different input formats:
- AWS accepts the
/30network address as the Inside IPv4 CIDR - Cloudflare WAN requires its usable host address with the
/30prefix length as the IPv4 interface address
Do not enter the /30 network address as the Cloudflare interface address. In this example, AWS uses 169.254.240.45, and Cloudflare WAN uses 169.254.240.46. The baseline uses the following two /30 networks.
| Attribute | Tunnel 01 of 02 | Tunnel 02 of 02 |
|---|---|---|
| Cloudflare tunnel name | AWS_TUN_01 |
AWS_TUN_02 |
| AWS VPN connection | VPN 1 | VPN 1 |
| AWS public IPv4 address | <AWS_OUTSIDE_IP_01> |
<AWS_OUTSIDE_IP_02> |
| Cloudflare anycast IP | 162.159.135.1 |
162.159.135.1 |
| AWS inside IPv4 CIDR input | 169.254.240.44/30 |
169.254.240.48/30 |
| AWS inside IP | 169.254.240.45 |
169.254.240.49 |
| Cloudflare interface address | 169.254.240.46/30 |
169.254.240.50/30 |
| BGP initiator | AWS | AWS |
| AWS ASN | 65020 |
65020 |
| CF Account ASN | 13335 |
13335 |
| Pre-shared key | <TUNNEL_01_PSK> |
<TUNNEL_02_PSK> |
Secondary anycast IP customers
Use tunnels 03 and 04 with 169.254.240.52/30 and 169.254.240.56/30, respectively. Their Cloudflare interface addresses are 169.254.240.54/30 and 169.254.240.58/30.
The example AWS VPC prefix is 192.168.0.0/16. Replace it and all angle-bracketed values with values from your environment. AWS generates two public IPv4 addresses per VPN connection. These values are unavailable before AWS creates the connection.
Assumptions
This guide assumes the following:
- Your Cloudflare WAN account has Unified Routing and BGP over IPsec enabled
- The Cloudflare WAN account has
162.159.135.1available and, when using two anycast IPs, also has172.64.135.1available - For the AWS console path, an AWS Transit Gateway exists and the workload VPC is attached in at least two Availability Zones; the Terraform path creates these resources
- The AWS VPC prefix is
192.168.0.0/16for this example - The AWS VPC prefix and prefixes learned from Cloudflare WAN do not overlap
- Security groups, network access control lists, host firewalls, and Cloudflare WAN network firewall policies allow the required application and test traffic
- You can create and modify AWS customer gateways, Site-to-Site VPN connections, Transit Gateway route tables, VPC route tables, and Cloudflare WAN resources
- IPv4 is used for tunnel interfaces and routed prefixes
- AWS Transit Gateway ASN
65020is not used by another Cloudflare WAN-connected site whose routes AWS must learn; otherwise, BGP loop prevention can reject those routes
Configuration workflow
- Configure the AWS Transit Gateway for ASN
65020and VPN ECMP. - Create a dedicated Transit Gateway route table.
- Create one AWS customer gateway for the Cloudflare anycast IP.
- Create one dynamic-routing AWS Site-to-Site VPN connection.
- Configure the IKE version and Phase 1 and Phase 2 settings for each tunnel by using Modify VPN tunnel options.
- Create two matching Cloudflare WAN IPsec tunnels.
- Enable BGP on each Cloudflare tunnel.
- Propagate the VPC and VPN attachments into the Transit Gateway route table.
- Add VPC routes toward Cloudflare WAN.
- Verify every configured tunnel, BGP session, and end-to-end traffic.
Choose a deployment method
Use the Terraform workflow unless you have a specific requirement to configure existing resources manually. Review the generated plan for your account and network before applying it. Do not complete both workflows for the same deployment.
- To create the complete reference AWS and Cloudflare WAN environment, continue with Terraform reference deployment
- To configure an existing Transit Gateway and workload VPC manually, continue with Gather Cloudflare WAN information
Gather Cloudflare WAN information
Gather and verify the Cloudflare information before creating AWS resources. AWS customer gateways use the Cloudflare anycast IPs as their public IP addresses, so changing an anycast IP later requires replacing the corresponding AWS customer gateway and VPN connection.
For more information about Cloudflare anycast IPs and tunnel addressing, refer to Configure tunnel endpoints.
- Log in to the Cloudflare dashboard.
- Go to Address Space > Leased IPs.
- Confirm the account has the baseline IPv4 anycast IP
162.159.135.1. - Go to Networking > Routes > WAN configuration.
- Confirm Unified Routing and BGP over IPsec are available for the account.
- Record the CF Account ASN. The default is
13335. - Inventory the eligible routes in the Unified Routing dataplane that AWS should learn.
- Check existing tunnel names and interface addresses.
Secondary anycast IP customers
In step 3, also confirm that 172.64.135.1 is leased to the account.
Record the following values before continuing:
| Item | Reference value |
|---|---|
| Cloudflare anycast IP 1 | 162.159.135.1 |
| Cloudflare anycast IP 2 | 172.64.135.1 |
| CF Account ASN | 13335 (default) |
| AWS Transit Gateway ASN | 65020 |
| AWS VPC prefix | 192.168.0.0/16 |
| Expected RFC 1918 prefixes from Cloudflare WAN | <EXPECTED_RFC1918_PREFIX_LIST> |
By default, Cloudflare WAN routes RFC 1918 address space. Publicly routable address space can be enabled one prefix at a time. Contact Cloudflare for assistance with enabling public prefixes.
Create the AWS VPN connection first
Do not create the Cloudflare tunnel objects yet. AWS generates two public IPv4 addresses for each VPN connection. Each generated address identifies the Customer endpoint for one Cloudflare tunnel. Record the VPN connection ID, inside /30 CIDR, and public IPv4 address together so you can apply the generated address to the correct Cloudflare tunnel.
Check existing tunnel names and interface addresses
Cloudflare rejects a new tunnel whose name or interface address matches another tunnel in the same Cloudflare account. The AWS Site-to-Site VPN connections are created before the Cloudflare tunnels, so a conflict otherwise appears only after the AWS resources exist. Before you choose tunnel names and inside /30 CIDRs, list the names and interface addresses already in use.
In the Cloudflare dashboard, go to the Connectors page and review the IPsec/GRE tunnels tab. Alternatively, run the following commands with an API token that can read Cloudflare WAN configuration:
curl -s -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" "https://api.cloudflare.com/client/v4/accounts/<CLOUDFLARE_ACCOUNT_ID>/magic/ipsec_tunnels" | jq -r '.result.ipsec_tunnels[] | "\(.interface_address)\t\(.name)"' | sort
curl -s -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" "https://api.cloudflare.com/client/v4/accounts/<CLOUDFLARE_ACCOUNT_ID>/magic/gre_tunnels" | jq -r '.result.gre_tunnels[] | "\(.interface_address)\t\(.name)"' | sort
