Opscraft
Route 53 routing policies · Lesson 5 of 10 · 3 min read

Failover routing

Active-passive

resource "aws_route53_record" "primary" {
  zone_id         = var.zone_id
  name            = "app.example.com"
  type            = "A"
  set_identifier  = "primary"
  failover_routing_policy { type = "PRIMARY" }
  health_check_id = aws_route53_health_check.app_primary.id   # or alias evaluate_target_health
  alias {
    name                   = aws_lb.primary.dns_name
    zone_id                = aws_lb.primary.zone_id
    evaluate_target_health = true
  }
}
resource "aws_route53_record" "secondary" {
  zone_id        = var.zone_id
  name           = "app.example.com"
  type           = "A"
  set_identifier = "secondary"
  failover_routing_policy { type = "SECONDARY" }
  alias {
    name                   = aws_cloudfront_distribution.maintenance.domain_name
    zone_id                = aws_cloudfront_distribution.maintenance.hosted_zone_id
    evaluate_target_health = false
  }
}
  • The primary must have a health check (or evaluate-target-health); otherwise Route 53 can't know when to fail over.
  • While the primary is healthy, all queries get the primary. When it's unhealthy, queries get the secondary.
  • The secondary can also have a health check (if both are unhealthy, Route 53 returns the primary).
  • Common secondaries: a DR region's ALB (pilot light / warm standby), or a static maintenance page on S3 + CloudFront ("we'll be right back").
Enlarge diagramapp.example.comPRIMARYALB in ap-south-1 · healthcheckSECONDARYDR region or maintenance pagehealthcheckpassing?healthyunhealthy
Figure 1. Active-passive failover: while the primary's health check passes, everyone gets the primary; when it fails, answers switch to the secondary.
Swipe sideways to see all of it, or tap to open it full screen.

For a static failover page, prepare in advance: the page, its CloudFront distribution and certificate for the same hostname (us-east-1 ACM), and a tested runbook — not something to build during an outage.

Failover timing

Total time ≈ health check detection (interval × failure threshold, e.g. 10 s × 3 = 30 s) + Route 53 propagation (seconds) + client cache TTL (60 s if configured well) + client retry behaviour. Plan for ~1–2 minutes with good settings, longer for clients that ignore TTL.

Enlarge diagramdetect: 10 s × 3client TTL 60 sretriesAbout 1-2 minutes in total; longer for clients that ignore TTL.
Figure 2. How long failover takes end to end with good settings.
Swipe sideways to see all of it, or tap to open it full screen.

"Failover isn't switching even though the primary is down"

Check: the health check is actually attached to the primary record (or evaluate-target-health is on); the health check targets the right endpoint/port/path and reports unhealthy; Route 53 health checkers can reach the endpoint (security groups allow their IP ranges — otherwise the check is always failing or always passing depending on setup); for alias targets, that the ALB really has no healthy targets (an ALB with one healthy target is still "healthy"); and client caches (TTL).