Today I Learned

AWS Route 53, prefer ALIAS over CNAME if you can

Let’s assume you have a zone defined:

resource "aws_route53_zone" "primary" {
  name = "example.com"
}

Now you want to add subdomain api and point it to your Application Load Balancer, normally you would think to add CNAME to point to your ALB:

resource "aws_route53_record" "api" {
  zone_id = aws_route53_zone.primary.zone_id
  name    = "api"
  type    = "CNAME"
  ttl     = "5"
  records = ["your-alb-dns-name"]
}

but you will be charged extra for CNAME queries: Route53 Pricing

You incur charges for every DNS query answered by the Amazon Route 53 service, except for queries to Alias A records that are mapped to Elastic Load Balancing instances, CloudFront distributions, AWS Elastic Beanstalk environments, API Gateways, VPC endpoints, or Amazon S3 website buckets, which are provided at no additional charge.

To help you decide please read documentation: Choosing alias and non-alias

Route 53 charges for CNAME queries. vs. Route 53 doesn’t charge for alias queries to AWS resources.

So it’s better to use aliases to AWS resources if you can:

resource "aws_route53_record" "api" {
  zone_id = aws_route53_zone.primary.zone_id
  name    = "api"
  type    = "A"

  alias {
    name                   = "your-api-alb-dns-name"
    zone_id                = "your-api-alb-zone-id"
    evaluate_target_health = true
  }
}