0
0
AwsComparisonBeginner · 4 min read

A Record vs CNAME vs Alias in Route 53: Key Differences and Usage

In AWS Route 53, a A record maps a domain directly to an IP address, a CNAME record maps a domain to another domain name, and an alias record is a Route 53-specific feature that maps a domain to AWS resources like CloudFront or ELB without extra DNS queries. Alias records are preferred for AWS resources because they are free and support root domains, unlike CNAMEs.
⚖️

Quick Comparison

Here is a quick comparison of A record, CNAME record, and alias record in Route 53 based on key factors.

FeatureA RecordCNAME RecordAlias Record
Points toIP addressAnother domain nameAWS resource or domain name
Supports root domain (example.com)YesNoYes
DNS query costStandardStandardFree within Route 53
Use with AWS servicesNoNoYes (CloudFront, ELB, S3, etc.)
Allows chainingNoYesNo
TTL controlYesYesNo (managed by AWS)
⚖️

Key Differences

A record directly links your domain to an IP address. This means when someone types your domain, DNS returns the IP to connect to. It works for root domains like example.com but requires you to manage IP addresses manually.

CNAME record points your domain to another domain name instead of an IP. This is useful for subdomains like www.example.com pointing to example.net. However, CNAMEs cannot be used at the root domain level because DNS rules forbid it.

Alias record is a special Route 53 feature that acts like a CNAME but can be used at the root domain and points directly to AWS resources such as CloudFront distributions, Elastic Load Balancers, or S3 buckets. Alias records do not incur extra DNS query charges and AWS manages their IP addresses automatically, making them easier and cheaper to use with AWS services.

⚖️

Code Comparison

Here is how you create an A record in Route 53 using AWS CLI to point example.com to an IP address.

json
{
  "Comment": "Create A record for example.com",
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "example.com.",
        "Type": "A",
        "TTL": 300,
        "ResourceRecords": [
          {"Value": "192.0.2.44"}
        ]
      }
    }
  ]
}
Output
Creates an A record pointing example.com to IP 192.0.2.44
↔️

Alias Record Equivalent

Here is how you create an alias record in Route 53 using AWS CLI to point example.com to an AWS Elastic Load Balancer.

json
{
  "Comment": "Create alias record for example.com to ELB",
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "example.com.",
        "Type": "A",
        "AliasTarget": {
          "HostedZoneId": "Z35SXDOTRQ7X7K",
          "DNSName": "my-load-balancer-1234567890.us-west-2.elb.amazonaws.com.",
          "EvaluateTargetHealth": false
        }
      }
    }
  ]
}
Output
Creates an alias A record pointing example.com to the specified ELB
🎯

When to Use Which

Choose A record when you have a fixed IP address to point your domain to, especially for root domains without AWS resources.

Choose CNAME record for subdomains that need to point to other domain names outside AWS or when you want to alias one domain to another but not at the root level.

Choose alias record when pointing your domain (including root) to AWS resources like CloudFront, ELB, or S3 buckets because it is cost-effective, supports root domains, and AWS manages the IP addresses automatically.

Key Takeaways

Use A records to map domains directly to IP addresses, suitable for root domains without AWS resources.
Use CNAME records to point subdomains to other domain names but never at the root domain.
Use alias records in Route 53 to point domains to AWS resources with no extra DNS cost and support for root domains.
Alias records simplify management by automatically handling IP changes of AWS resources.
Choose the record type based on your domain level and whether you use AWS services.