Building Site-to-Site VPN Failover Between Branch and AWS
Build a dual-tunnel AWS Site-to-Site VPN with BGP failover across branch circuits, verify convergence time, and document rollback steps.

In this lesson
Advertising disclosure: this article includes partner links. KBY may earn a commission if you sign up or buy through one, at no extra cost to you. How we make money.
Table of Contents
Table of contents
Before you begin
- Working knowledge of IPsec and BGP fundamentals
- AWS IAM permissions for VPC and VPN resource creation
- Access to branch router or firewall CLI supporting BGP
Track this tutorial
Choose your current status and tick each safety check as you complete it. Sign in to sync progress between devices.
Current status
Tutorial stages
- Step 1 — Provision two Customer Gateways and a BGP-based VPN connection
- Step 2 — Configure branch routers with IPsec and BGP
- Step 3 — Force failover and time the convergence
0 of 3 stages complete
Before you apply the change
Confirm these production-safety controls during the tutorial.
#Operational requirement
The business driver behind this build is straightforward: a single-circuit VPN represents an unacceptable single point of failure for any branch that depends on AWS-hosted services during trading hours. Once a location relies on line-of-business applications, shared file storage or authentication services sitting in a VPC, an unplanned circuit outage translates directly into lost productivity and support escalations. The operational requirement is therefore not merely technical resilience for its own sake, but a measurable reduction in mean time to recovery when — not if — a primary circuit fails.
This requirement is typically raised by the network engineering lead or IT operations manager, and should be captured formally before implementation begins, referencing the specific branch site, its current single-tunnel configuration, and the acceptable convergence window agreed with the business. Without a documented requirement, engineers risk building resilience that nobody asked for in the wrong place, or missing a convergence target that operations actually need. The requirement should also specify which workloads must remain reachable during failover, since not every branch dependency carries equal priority.
#Pre-implementation access review
Before any Customer Gateway or VPN connection is created, review who currently holds write access to the target VPC’s route tables and VGW attachment. Site-to-site VPN builds routinely get delegated to whichever engineer is available, and it is common to discover that access was never formally revoked from a previous contractor or that a shared service account still has standing permissions against production routing objects. Resolving this beforehand avoids attributing a change to the wrong identity later, which complicates audit trails during incident review.
Confirm that the engineer performing the build holds only the permissions listed in the prerequisites, scoped to the specific VGW and route tables in question, rather than a broader policy inherited from an administrator group. Where access has expanded beyond what the task requires, raise a request to narrow it before proceeding. This review should be documented against the change ticket with a timestamp and the reviewer’s name, since it forms part of the evidence auditors expect when assessing whether segregation of duties was genuinely observed rather than assumed.
#Route table propagation verification
Before signing off, confirm route propagation is actually enabled on the target route table rather than assumed. A tunnel showing UP with BGP Established can still fail to insert routes if propagation was never switched on for that specific table, particularly when a VPC has several route tables and only one was updated during initial build.
First, run the read-only check and record the current routes:
1aws ec2 describe-route-tables --route-table-ids rtb-0a1b2c3d --query "RouteTables[].Routes"Only if propagation is missing, and only on route tables whose scope has been approved in the change ticket, enable it as a separate, deliberate step, then re-run the check above:
1aws ec2 enable-vgw-route-propagation --route-table-id rtb-0a1b2c3d --gateway-id vgw-0bbb2222Check every subnet-associated route table that branch traffic could traverse, not just the one used during the lab build — a workload sitting in a subnet associated with an unmodified table will silently lose reachability during failover while everything else appears healthy.
#Evidence to retain
Capture the output of describe-route-tables immediately after enabling propagation and again after the failover test, showing the destination CIDR pointing at the correct VGW attachment ID in both states. Auditors reviewing the change ticket later will want to see the route source shown as propagated rather than static, confirming BGP — not a manually entered route — is driving the path.
#Health check dependency on the branch router
CloudWatch’s TunnelState metric reflects the IPsec tunnel state as seen from the AWS side; it does not confirm the branch router’s BGP process is healthy. A router that has exhausted its BGP table memory or is mid-reload can show a tunnel as cryptographically up while still failing to advertise routes. Pair the CloudWatch alarm with an independent reachability probe from a host inside the branch LAN, scheduled outside the router itself, so a router-level fault doesn’t also disable the thing meant to detect it.
#Symptom: alarm silent, users still affected
If users report an outage but no CloudWatch alarm has fired, check whether the affected subnet’s route table was excluded from propagation, per the section above, before assuming the alarm threshold is misconfigured. This is a distinct fault class from tunnel failure and won’t appear in TunnelState at all.
#Change-control record additions
Alongside the evidence already listed, record the exact route table IDs modified, the propagation enable/disable timestamps, and the identity of the engineer who ran the command. Where a route table serves production and non-production subnets together, note explicitly which subnets were in scope for this change, since a shared table is a common source of unintended blast radius during rollback.
#Rollback addition
If route propagation must be reverted, follow one order: record the current routes with describe-route-tables, restore the prior route state (including any static routes that were in place before the build, which should be staged in advance), then disable propagation on the specific route table, and only then delete the VPN objects. Disabling propagation removes the routes to the branch, so without restored static routes the affected subnets are left with no path at all rather than reverting to the prior known-good state.
1aws ec2 disable-vgw-route-propagation --route-table-id rtb-0a1b2c3d --gateway-id vgw-0bbb2222Before touching production routing, confirm the engineer’s IAM role has been scoped rather than inherited from a broader administrator policy. A common oversight is running these commands under a role that also holds ec2:DeleteRoute or ec2:ReplaceRoute against unrelated route tables, which turns a VPN build into an accidental blast-radius incident. Request a time-bound elevation through your identity provider, log the request ticket number against the change record, and confirm the elevation expires automatically rather than relying on someone remembering to revoke it.
#Segregation of duties
Whoever approves the change record should not be the same person executing the router configuration. On a two-person operations team this can feel bureaucratic, but the point is a second set of eyes checking the ASN allocation and PSK handling before anything touches the live VGW. Record the approver’s name, the ticket reference and the approval timestamp in the same document that holds the BGP summaries — auditors will ask for all three together, not separately.
#Configuration detail often missed
#Dead peer detection alignment
AWS generates specific DPD timeout and retry values per tunnel in the downloaded configuration file. If the branch router’s IPsec profile uses a locally defined DPD interval instead of the AWS-generated one, the tunnel can appear UP in the console while the router considers the peer dead, producing a black-hole state that ping alone won’t reveal until the hold timer expires. Check the keepalive settings configured on the router with:
1show crypto isakmp profile
2show running-configCompare the DPD interval and retry count against the AWS-supplied configuration file line by line before accepting the tunnel as correctly built.
#MTU and fragmentation
IPsec overhead reduces the effective MTU across the tunnel. Where the branch router doesn’t clamp TCP MSS, large transfers can succeed on ping but stall on file copies once encapsulated packets exceed path MTU. Set the tunnel MTU and an explicit MSS clamp together on the tunnel interface. The values below (MTU 1436, MSS 1379) apply to the AWS-recommended AES-GCM settings; if you use a different cipher, check the values AWS documents for it and the downloaded configuration file:
1interface Tunnel1
2 ip mtu 1436
3 ip tcp adjust-mss 1379Confirm with a large-payload transfer test, not just ICMP, before declaring the tunnel production-ready.
#Monitoring and alerting
A tunnel that fails silently outside business hours is worse than one that fails loudly during a change window. Configure CloudWatch alarms against the TunnelState metric for both VPN connections, with a threshold that pages on-call after two consecutive missed data points rather than a single blip, which reduces noise from transient carrier-side maintenance.
#Threshold guidance
| Condition | Threshold | Action |
|---|---|---|
| Single tunnel down >5 minutes | Warning | Notify on-call, no page |
| Both tunnels down >2 minutes | Critical | Page on-call immediately |
| BGP session flapping >3 times/hour | Warning | Investigate DPD and circuit stability |
| Convergence time above the locally agreed target (for example 90 seconds) in test | Warning | Review timers and circuit behaviour before sign-off |
Route the critical alarm through the same paging channel used for other production routing incidents so the on-call engineer doesn’t need to know this is a VPN-specific alert to respond correctly.
#Realistic failure symptoms during operation
#Slow convergence under load
Convergence measured during a quiet test window can differ from convergence during a genuine failure at peak traffic. If the branch router’s CPU is already under load handling other BGP peers or NAT translations, BGP hold-timer expiry detection can be delayed, pushing real-world failover past the figure captured in testing. Re-run the shutdown test during a representative traffic period at least once before final sign-off, and note the discrepancy if one exists.
#Route flapping after partial circuit degradation
A circuit that is degraded rather than fully down — intermittent packet loss instead of a clean outage — can cause the BGP session to flap repeatedly rather than fail over cleanly. This produces a worse user experience than a single clean cutover because traffic oscillates between tunnels. Watch for repeated Established/Idle transitions in show ip bgp summary output and treat more than three flaps within an hour as a circuit-quality issue requiring ISP escalation rather than a VPN configuration fault.
#Change-control record keeping
The change ticket should carry more than a pass/fail note. Attach the pre-change route table export, the post-change route table export, both BGP summary captures, the timestamped ping log, and the CloudWatch alarm configuration screenshot. Where the build deviates from the standard — for example a non-default ASN or a manually adjusted local-preference — record the reason inline in the ticket rather than only in router comments, since router comments are lost on a config reload.
#Escalation path
If convergence exceeds the agreed target after two consecutive re-tests with correctly matched timers, escalate to the network engineering lead before attempting further timer tuning — repeatedly lowering hold timers without understanding the root cause risks session instability under normal conditions. If PSK mismatches recur after a Customer Gateway rebuild, escalate to whoever holds the secrets vault administration rights rather than regenerating credentials repeatedly, since repeated regeneration without process review tends to mask a deeper handover gap between infrastructure and network teams.
A branch office loses its primary circuit at 08:14 on a Monday morning. If the site-to-site VPN to AWS is pinned to a single tunnel on a single Customer Gateway, that branch is now cut off from every AWS-hosted workload — file shares, line-of-business apps, RADIUS. Tickets pile up, the on-call engineer gets paged, and someone asks why redundancy wasn’t built in from day one.
Your task as the newly hired engineer: build redundant VPN connectivity across two Customer Gateways on two separate ISP circuits, get BGP failover working, and produce proof it actually converges before change management will sign off. Each VPN connection provides two AWS tunnels, so this design gives two connections, one per ISP circuit. This is a routing change to production. Treat it as one.
#Prerequisites
| Requirement | Detail |
|---|---|
| IAM permissions | ec2:CreateVpnConnection, ec2:CreateCustomerGateway, ec2:CreateVpnGateway, ec2:DescribeVpnConnections, route table modify rights |
| VPC setup | Attached VGW or Transit Gateway, at least two modifiable route tables |
| Branch circuits | Two public IPs on different ISPs, terminating on IPsec/BGP-capable routers |
| ASN | Private ASN 64512–65534, unique against anything already peered to the VGW |
| Change approval | Logged before touching production routing |
| Identity | MFA-enforced access under Entra ID or IAM — no shared credentials |
#Step 1 — Provision two Customer Gateways and a BGP-based VPN connection
Create one Customer Gateway per circuit, then one VPN connection per Customer Gateway using dynamic routing, not static routes. Both branch routers use the same private ASN (65001) because they are the same branch site; the preference between circuits is set in Step 2.
1aws ec2 create-customer-gateway --type ipsec.1 --public-ip 203.0.113.10 --bgp-asn 65001 --device-name "Branch-ISP-A"
2
3aws ec2 create-customer-gateway --type ipsec.1 --public-ip 198.51.100.20 --bgp-asn 65001 --device-name "Branch-ISP-B"
4
5aws ec2 create-vpn-connection --type ipsec.1 --customer-gateway-id cgw-0aaa1111 --vpn-gateway-id vgw-0bbb2222 --options '{"StaticRoutesOnly":false}'
6
7aws ec2 create-vpn-connection --type ipsec.1 --customer-gateway-id cgw-0ccc3333 --vpn-gateway-id vgw-0bbb2222 --options '{"StaticRoutesOnly":false}'Capture the JSONThe KBY LexiconJSONJSON (JavaScript Object Notation) is a lightweight, text-based data-interchange format built from key-value pairs and ordered lists, defined by RFC 8259.
output: VpnConnectionId, tunnel outside IPs, pre-shared keys. PSKs go into a secrets vault, never into a ticket comment. Do not proceed until aws ec2 describe-customer-gateways shows both gateways as available and aws ec2 describe-vpn-connections shows both connections with State available. Tunnel status will normally show DOWN until the branch routers are configured in Step 2, and UP only once IPsec is established. Leave the existing single-tunnel production connection in place and untouched throughout this build.
#Step 2 — Configure branch routers with IPsec and BGP
Match the IKE version, DPD timers and encryption suite exactly as AWS generated them. Download the configuration file for each VPN connection and use the inside tunnel IPs and the Amazon-side ASN it specifies for each tunnel. Save the router’s current running configuration before changing it. Then bring up BGP per tunnel. The values below are placeholders only.

Primary router (ISP-A) — prefer this path by raising local-preference on routes learned from AWS:
1route-map FROM-AWS-PRIMARY permit 10
2 set local-preference 200
3
4router bgp 65001
5 neighbor <aws-inside-ip-tunnel1> remote-as <amazon-side-asn>
6 neighbor <aws-inside-ip-tunnel1> timers 10 30
7 neighbor <aws-inside-ip-tunnel2> remote-as <amazon-side-asn>
8 neighbor <aws-inside-ip-tunnel2> timers 10 30
9 address-family ipv4
10 neighbor <aws-inside-ip-tunnel1> activate
11 neighbor <aws-inside-ip-tunnel1> route-map FROM-AWS-PRIMARY in
12 neighbor <aws-inside-ip-tunnel2> activate
13 neighbor <aws-inside-ip-tunnel2> route-map FROM-AWS-PRIMARY in
14 network 10.50.0.0 mask 255.255.255.0BackupThe KBY LexiconBackupA causally disconnected, point-in-time copy of system state, tagged with a consistency marker, that lets you recover from logical corruption or data loss independent of the source system's health. router (ISP-B) — make the branch prefix less attractive to AWS by prepending the AS path outbound:
1route-map TO-AWS-BACKUP permit 10
2 set as-path prepend 65001 65001 65001
3
4router bgp 65001
5 neighbor <aws-inside-ip-tunnel1> remote-as <amazon-side-asn>
6 neighbor <aws-inside-ip-tunnel1> timers 10 30
7 neighbor <aws-inside-ip-tunnel2> remote-as <amazon-side-asn>
8 neighbor <aws-inside-ip-tunnel2> timers 10 30
9 address-family ipv4
10 neighbor <aws-inside-ip-tunnel1> activate
11 neighbor <aws-inside-ip-tunnel1> route-map TO-AWS-BACKUP out
12 neighbor <aws-inside-ip-tunnel2> activate
13 neighbor <aws-inside-ip-tunnel2> route-map TO-AWS-BACKUP out
14 network 10.50.0.0 mask 255.255.255.0Repeat for each tunnel in the downloaded configuration of each router, using that router’s own inside IPs. Local-preference on the primary router steers branch-to-AWS traffic; the prepend on the backup router steers AWS-to-branch traffic. AWS’s documented BGP hold timer is 30 seconds; keep the router hold time at 30 seconds or below, and confirm the negotiated value in show ip bgp neighbors. Both BGP sessions must show Established, and the VPC route table should propagate 10.50.0.0/24 with the expected preference. Capture show ip bgp summary from both routers and a screenshot of the route table before moving on. Confirm the tunnels show UP in the AWS console first — do not simulate failure against a half-built tunnel.
#Step 3 — Force failover and time the convergence
Agree a pilot window and record the current route state and router configuration first so you can undo the test. Shut the tunnel interface, not the physical WAN link, so the test stays reversible.
1interface Tunnel1
2 shutdownRun continuous probes from a host in the branch LAN (source in 10.50.0.0/24) to a workload in a VPC CIDR that is reachable via the VGW; replace the placeholder with a real instance address in that VPC:
1ping -t <vpc-workload-ip>Expect traffic to shift to the remaining tunnel within the BGP hold-timer window. Because AWS’s hold timer is 30 seconds, treat a figure such as 90 seconds as a local convergence target, not a vendor guarantee. Capture the ping output showing exact dropped packets and recovery timestamp, plus show ip bgp summary confirming the backup tunnel as active with correct AS path length. This is the evidence change management will ask for.
#Verification
Bring Tunnel1 back up (no shutdown) and confirm traffic reverts to the primary path once BGP re-establishes and preference is restored. Re-check both connections’ tunnel states in the AWS console, confirm route table propagation matches expectations, and archive all captured evidence — JSON output, BGP summaries, ping logs — against the change ticket.

1show ip bgp summary
2aws ec2 describe-vpn-connections --vpn-connection-ids vpn-0123456789abcdef0Repeat the describe-vpn-connections check for the second connection and confirm State available and tunnel status UP on both.
#Failure Modes
- BGP sessions establish but routes never propagate — usually a missing
networkstatement or route table not associated with the VGW. - Failover takes far longer than expected — check that the router’s BGP timers are actually applied; the effective hold time is the lower of the router’s and AWS’s 30-second value.
- Both tunnels show UP but traffic still drops during the test — asymmetric routing because the branch LAN default route wasn’t updated to prefer the VPN path.
- PSK mismatch after a rebuild — someone regenerated the Customer Gateway without updating the router config, and the tunnel silently fails to rekey.
#Rollback
If failover testing causes unexpected outages, immediately bring Tunnel1 back up, verify BGP re-establishes, and revert any manual local-preference changes on the router. If the entire build is unstable, work in this order: record the current routes, restore the prior route state (static routes and the previous single-tunnel configuration from backup), and confirm the original single-tunnel connection is restored and carrying traffic. Then disable route propagation on the affected route tables, and only then delete the VPN objects. Before deleting, download the vendor configuration for each connection from the console (or the configuration download for each VPN connection) and confirm the backup is stored, because deleting a connection discards its tunnel configuration and PSKs. Check each ID against the change ticket so that only the two connections created in this build are deleted, never the pre-existing production connection. Delete the connections before the Customer Gateways, since a Customer Gateway cannot be deleted while a connection uses it. Document why in the change ticket before reattempting.
1aws ec2 describe-vpn-connections --vpn-connection-ids vpn-0123456789abcdef0 <second-vpn-connection-id>
2aws ec2 delete-vpn-connection --vpn-connection-id vpn-0123456789abcdef0
3aws ec2 delete-vpn-connection --vpn-connection-id <second-vpn-connection-id>
4aws ec2 describe-vpn-connections --vpn-connection-ids vpn-0123456789abcdef0 <second-vpn-connection-id>
5aws ec2 delete-customer-gateway --customer-gateway-id cgw-0aaa1111
6aws ec2 delete-customer-gateway --customer-gateway-id cgw-0ccc3333Confirm both connections show State deleted before deleting the Customer Gateways.
#Operational Summary
The diagram below shows the intended failover path.
Rendering diagram...
A redundant, BGP-backed VPN turns a single-circuit outage from a full branch disconnection into a brief, self-healing reroute. The value isn’t the configuration itself — it’s the evidence trail: BGP summaries, route table screenshots and timed packet-loss logs that prove convergence works before production sign-off, and that give the next engineer on call something concrete to check when a circuit fails at 08:14 on a Monday.
#Related reading
AWS Site-to-Site VPN Tunnel Down After BGP Flap to Azure: Fix
AWS Identity Controls Leave Workloads Exposed Until Verified
Fixing AWS S3 AccessDenied When an EC2 Instance Role Reads a Bucket
Fixing AWS EC2 SSH Connection Timed Out After Launching an Instance
About this page
Credited to
Dates
Published
Sources
Corrections
- : Corrected during a review of published articles. Details
Read-only scripts
- Windows devices with no BitLocker recovery key in Entra IDMicrosoft Entra ID, Windows
- Intune devices that haven't synced in N daysMicrosoft Intune
- Mailboxes forwarding to external addressesExchange Online
- BitLocker status of every volume on this PCWindows
Upcoming deadlines
- Intune moves to macOS 15 and laterQ4 2026
- SAP SuccessFactors provisioning: move from basic auth to workload identityNovember 2026
- Intune November release: JIT registration reminder at APNs renewal and automatic JIT for eligible tenantsNovember 2026
Explore KBY
The KBY Brief
A short email about twice a week with new runbooks, configuration traps and fixes from KBY Technologies.
SubscribeRelated articles
Enterprise Networking Fundamentals
Deploying Entra ID Conditional Access Without Locking Everyone Out
A staged, reversible method for enforcing MFA via Entra ID Conditional Access, covering break-glass accounts, Report-only validation, and rollback steps.
Enterprise IT Management
Restricting Microsoft 365 Group Creation to an Approved Security Group
How to limit Microsoft 365 Group creation to one approved security group with the Group.Unified directory setting, including state capture, validation from both sides, failure modes and a tested rollback.
DevOps & Automation
GitHub Actions Docker Build: Fixing Permission Denied on docker.sock
Diagnose docker.sock permission denied in GitHub Actions by runner type, then apply a least-privilege fix with validation and rollback.
Discover more
Graduate Learning
Ops Playbook
Lexicon Definitions
Learn More About KBY
About KBY
Learn about our mission, how our content is produced, and how we handle corrections.
Why Trust KBY
How KBY content is produced, what is checked automatically, and how errors are corrected.
The KBY Brief
A short email about twice a week with new runbooks, configuration traps and fixes from KBY Technologies.
Was this useful?
Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.
Build practical engineering skills.
Receive new lessons, learning paths, practical exercises and early-career guidance.
Comments
Add a thoughtful note on Building Site-to-Site VPN Failover Between Branch and AWS. Comments are checked for spam and held for moderation before appearing.