Opscraft
Route 53 hosted zones · Lesson 2 of 8 · 3 min read

Public hosted zones

Creating and connecting

aws route53 create-hosted-zone --name example.com --caller-reference $(date +%s)
aws route53 get-hosted-zone --id Z0123456789ABCDEFGHIJ   # shows the 4 name servers
resource "aws_route53_zone" "public" {
  name = "example.com"
}
output "name_servers" { value = aws_route53_zone.public.name_servers }

Then point the domain at it: if the domain is registered in Route 53 Domains, set its name servers there (automatic for new registrations); if registered elsewhere, update the name servers at that registrar. Until then, the zone exists but nobody asks it.

Watch out: destroying and recreating a hosted zone (an accidental Terraform replace) assigns four new name servers. The registrar still points to the old ones → the domain goes dark. Protect zones with lifecycle { prevent_destroy = true }, or use a reusable delegation set.

Enlarge diagramZone replacede.g. a forcedreplacement inTerraformNew name serversfour new awsdnshostsRegistrarunchangedstill delegates to theold fourDomain stopsresolvingold servers no longerserve it1234Protect public zones with prevent_destroy, or use a reusable delegation set.
Figure 1. The quiet outage: Terraform replaces a hosted zone, Route 53 assigns new name servers, and the registrar still points at the old ones.
Swipe sideways to see all of it, or tap to open it full screen.

Records you'll create

resource "aws_route53_record" "app" {          # alias to an ALB
  zone_id = aws_route53_zone.public.zone_id
  name    = "app.example.com"
  type    = "A"
  alias {
    name                   = aws_lb.app.dns_name
    zone_id                = aws_lb.app.zone_id
    evaluate_target_health = true
  }
}
resource "aws_route53_record" "spf" {          # TXT
  zone_id = aws_route53_zone.public.zone_id
  name    = "example.com"
  type    = "TXT"
  ttl     = 3600
  records = ["v=spf1 include:amazonses.com -all"]
}

Public zone features

  • DNSSEC signing for public zones (key-signing key in KMS, us-east-1), with the DS record added at the registrar.
  • Query logging for public zones goes to CloudWatch Logs (the log group must be in us-east-1) — useful for auditing and debugging which resolvers ask what.
  • Subdomain delegation to other hosted zones/accounts by adding NS records.