Sub topic 6
Alias records and the zone apex
This chapter explains what an alias record is, why the zone apex needs one, and how to choose between an alias and a CNAME. It assumes you can read a record set in JSON, you know what a hosted zone is, and you have used change-resource-record-sets with a change batch. You should also know the record types and TTL behavior from the previous chapter.
The problem: a CNAME cannot sit at the apex
The zone apex (also called the root domain or naked domain) is the name of the zone itself, such as example.com. Every zone has an SOA record and NS records at the apex. The DNS standard says a CNAME record must be the only record at its name. A CNAME at example.com would conflict with the SOA and NS records, so Route 53 rejects it.
This is a real constraint for AWS users. CloudFront distributions, load balancers and API Gateway endpoints are all reached through DNS names, not fixed IP addresses. You cannot copy an address into an A record, because the address can change at any time. Subdomains like www.example.com can use a CNAME, but the bare example.com cannot.
An alias record solves this. It is a Route 53 extension to DNS that looks like an A or AAAA record to the outside world but is resolved inside Route 53.
How an alias record works
An alias record points at an AWS resource, or at another record in the same hosted zone. When a resolver asks for the name, Route 53 looks up the current addresses of the target and answers with them as an ordinary A or AAAA response. The resolver and the client never see a CNAME or an alias. They see IP addresses.
The diagram below shows the path of one query.
Several properties follow from this design:
- No TTL field. You cannot set a TTL on an alias record. Route 53 uses the TTL of the target, which is usually short. Specifying
TTLin an alias change batch causes an error. - Type must match the target. An alias to a CloudFront distribution or load balancer is created as type
Afor IPv4 orAAAAfor IPv6. You often need both, one of each, if the target supports IPv6. - Same zone, different name. An alias can also point at another record in the same hosted zone, for example
wwwpointing at the apex. The alias type must match the type of the target record. - Free queries for AWS targets. Route 53 does not charge for queries to alias records that point at AWS resources. Queries for a CNAME are charged at the standard rate.
- Health awareness. An alias record has an
EvaluateTargetHealthsetting. When it istrue, Route 53 treats the record as unhealthy if the target's own health status is unhealthy. This matters for routing policies, covered later in this tutorial.
Valid alias targets
An alias record can point at these kinds of targets:
| Target | Notes |
|---|---|
| CloudFront distribution | Fixed hosted zone ID `Z2FDTNDATAQYW2` |
| Application, Network or Classic Load Balancer | Hosted zone ID depends on the Region and load balancer type |
| API Gateway custom domain name | Regional or edge-optimized, each with its own zone ID |
| S3 website endpoint | Bucket name must match the record name; zone ID depends on the Region |
| Elastic Beanstalk environment | Zone ID depends on the Region |
| Global Accelerator | Accelerator DNS name |
| VPC interface endpoint | Useful in private hosted zones |
| Another record in the same hosted zone | Use the hosted zone's own ID |
Some AWS resources cannot be alias targets. An EC2 instance's public DNS name and an RDS endpoint are common examples. For those, use a CNAME on a subdomain, or an A record with a fixed address such as an Elastic IP.
The HostedZoneId in an alias target is not your zone's ID. It is the ID of the hosted zone that AWS owns for that service and Region. Using the wrong value is a common cause of failed change batches.
Example: an apex alias to CloudFront
This change batch creates an A alias at example.com. Z2FDTNDATAQYW2 is the fixed zone ID for all CloudFront distributions.
{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "example.com",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2",
"DNSName": "d111111abcdef8.cloudfront.net",
"EvaluateTargetHealth": false
}
}
}
]
}Save it as apex-alias.json and apply it with the CLI.
aws route53 change-resource-record-sets \
--hosted-zone-id ZONE_ID \
--change-batch file://apex-alias.jsonTwo details are worth noting. First, EvaluateTargetHealth is false here because a CloudFront distribution has no per-endpoint health to report. Second, the distribution must list example.com as an alternate domain name (CNAME) in its own configuration, with a matching TLS certificate. If it does not, the DNS lookup works but CloudFront rejects the request.
If the distribution has IPv6 enabled, add a second record with "Type": "AAAA" and the same alias target. Otherwise IPv6-only clients get no answer.
Example: an alias to a load balancer
For an Application Load Balancer, the zone ID depends on the Region. You can read both values from the API instead of looking them up in a table.
aws elbv2 describe-load-balancers \
--names my-alb \
--query "LoadBalancers[0].[DNSName,CanonicalHostedZoneId]" \
--output textUse the two returned values in the alias target. For an ALB in us-east-1 the result looks like this:
{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "app.example.com",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z35SXDOTRQ7X7K",
"DNSName": "my-alb-1234567890.us-east-1.elb.amazonaws.com",
"EvaluateTargetHealth": true
}
}
}
]
}Here EvaluateTargetHealth is true. Route 53 considers the record healthy only if the load balancer has at least one healthy target. When this record is part of a failover or weighted set, that status decides whether Route 53 still returns it.
Alias or CNAME?
Use this decision flow when you create a record that points at a DNS name.
The following table compares the two record kinds in more detail.
| Property | Alias record | CNAME record |
|---|---|---|
| Allowed at the zone apex | Yes | No |
| Targets | AWS resources and same-zone records | Any DNS name |
| Record type shown to clients | A or AAAA | CNAME, then the target's A or AAAA |
| TTL | Set by the target, not configurable | You choose it |
| Query charge for AWS targets | None | Standard rate |
| Works outside Route 53 | No | Yes, part of standard DNS |
| Resolver round trips | One answer from Route 53 | Resolver follows the chain, which may need extra lookups |
Because an alias is a Route 53 feature, you cannot export it to another DNS provider as an alias. If you migrate away, you must replace each alias with records the new provider supports.
Common mistakes
- Trying to create a CNAME at the apex. Route 53 returns an error that the record conflicts with the SOA and NS records. Use an alias.
- Using your own zone ID as
HostedZoneId. The value must be the zone ID of the target service. The exception is an alias to another record in your own zone, where you use your zone's ID. - Setting a TTL on an alias. Remove the
TTLfield from the record set. - Mismatched types. An alias A record that points at a name with only AAAA records gets no answer. Create both types when you want dual-stack access.
- Forgetting the target's own configuration. The alias gets traffic to CloudFront, an S3 website or API Gateway, but that service must also know about the custom domain name. A browser error after DNS resolves usually points to the target, not Route 53.
- Deleting the target first. Removing a CloudFront distribution or load balancer while the alias still exists leaves a dangling record. Delete the alias first, or someone else may be able to claim a reused name.
Checking the result
Query the apex with dig. You will see A records, not an alias, because the answer is built inside Route 53.
dig example.com A +short
dig example.com AAAA +shortTo confirm the record exists as an alias, read it from the zone.
aws route53 list-resource-record-sets \
--hosted-zone-id ZONE_ID \
--query "ResourceRecordSets[?Name=='example.com.' && Type=='A']"The output contains an AliasTarget object and no TTL or ResourceRecords. A record that shows ResourceRecords is a plain A record, not an alias.
Exercise
You own example.com in Route 53 and serve it through a CloudFront distribution that has IPv4 and IPv6 enabled. Which records do you create at the apex, which hosted zone ID do you put in the alias target, and why can't you use a CNAME?
Show answer
Create two alias records named example.com: one of type A and one of type AAAA, each with the CloudFront domain name as DNSName. Use the fixed CloudFront hosted zone ID Z2FDTNDATAQYW2 as HostedZoneId, not your own zone's ID. A CNAME is not allowed because the apex already holds SOA and NS records, and a CNAME must be the only record at its name.
Exercise
A teammate's change batch for an alias record fails. It contains "Type": "A", an AliasTarget that points at an ALB, and "TTL": 300. What is wrong, and what changes after you fix it?
Show answer
An alias record cannot have a TTL, so remove the TTL field. After the fix, Route 53 returns answers with the TTL of the target, which you cannot set. Also check that HostedZoneId is the load balancer's canonical zone ID (from CanonicalHostedZoneId) and not your own zone's ID.