Sub topic 3
Creating a public hosted zone
This chapter assumes you have an AWS account with the AWS CLI configured, and that you know what a record and an authoritative name server are from the earlier chapters. It covers what a hosted zone is, how to create one, and what Route 53 puts in it.
What a hosted zone is
A hosted zone is a container for the DNS records of one domain name and its subdomains. A public hosted zone answers queries from anywhere on the internet. The zone for example.com holds records such as www.example.com and mail.example.com.
Creating a zone does not make your domain work. Resolvers only ask Route 53 about your domain after the parent zone points to the zone's name servers. That step is covered in the next chapter.
What Route 53 creates for you
When you create a zone, Route 53 does three things:
- It assigns four name servers, drawn from different top-level domains (for example
.com,.net,.organd.co.uk), so that one TLD problem does not take them all out. - It adds an NS record at the zone apex listing those four servers.
- It adds an SOA (start of authority) record with zone metadata.
You should not delete these two records. Route 53 manages them, and the NS record is what you copy to your registrar.
Create the zone with the CLI
aws route53 create-hosted-zone \
--name example.com \
--caller-reference "$(date +%s)"
aws route53 list-resource-record-sets \
--hosted-zone-id ZONE_ID \
--query "ResourceRecordSets[?Type=='NS']"The --name option is the domain, with no trailing label such as www. The --caller-reference option is a string that must be unique for each create request. If a network error makes you retry with the same string, Route 53 recognizes the retry and does not create a second zone. Using date +%s gives a fresh value each time you run a new request.
The response includes the zone ID in the form /hostedzone/Z0123456789ABC. Use only the part after the last slash as ZONE_ID in later commands. The second command lists the NS record, and its four values are the name servers you will configure at your registrar.
To find the ID of an existing zone later, run aws route53 list-hosted-zones-by-name --dns-name example.com.
Common errors
| Symptom | Likely cause |
|---|---|
| `HostedZoneAlreadyExists` | The caller reference was reused with different settings. Use a new one. |
| Zone exists but the domain does not resolve | The domain is not delegated to this zone's name servers yet. |
| Name servers at the registrar do not match the zone | You created a second zone with the same name, or deleted and recreated the zone. |
| `HostedZoneNotEmpty` when deleting | The zone still has records other than the default NS and SOA. Delete those first. |
Registered domains and cost
If you register a domain with Route 53, it creates a public hosted zone for you and sets the registered domain's name servers to match. If your domain is registered elsewhere, you create the zone yourself and then update the registrar.
A hosted zone is billed monthly, and you also pay per query. Delete test zones you no longer need.
Exercise
You created a hosted zone for example.com, added records, and changed nothing at the registrar. A colleague says the site still does not resolve through Route 53. What is missing, and what value do you copy from the zone?
Show answer
The domain is not delegated. Copy the four values of the zone's apex NS record (shown by list-resource-record-sets) into the name server settings at the registrar. Until then, resolvers are not sent to this zone.
Exercise
Why does create-hosted-zone require a caller reference, and what does it prevent?
Show answer
The caller reference is a unique string for each create request. If a request is retried with the same reference, Route 53 treats it as the same request instead of creating a duplicate zone.