Sub topic 3
Creating a public hosted zone
This chapter covers what a public hosted zone is, how to create one with the console and the AWS CLI, and what Route 53 puts in it automatically. It also covers the mistakes that most often leave a new zone unused. It assumes you know what recursive resolvers and authoritative servers are (from the DNS basics chapter) and that you have the AWS CLI configured with permissions for Route 53. You should also know whether your domain is registered with Route 53 or elsewhere (see the previous chapter).
What a hosted zone is
A hosted zone is a container for the DNS records of one domain name and its subdomains. In Route 53, a public hosted zone answers queries from anywhere on the internet. A zone for example.com can hold records for example.com, www.example.com, api.eu.example.com, and so on. It cannot hold records for a different domain such as example.org.
Route 53 runs the zone on a set of authoritative name servers. Each zone gets its own set of four name servers, spread across different top-level domains (such as .com, .net, .org and .co.uk) for resilience. Those names look like ns-1234.awsdns-56.org. The zone does nothing for real users until the parent of your domain points at those four servers. That step is delegation, covered in the next chapter.
A hosted zone is not the same as a domain registration:
| Item | Registration | Hosted zone |
|---|---|---|
| What it records | Your right to use the name, held at a registry | The DNS records that answer queries for the name |
| Where it lives | The registrar and the TLD registry | Route 53 authoritative servers |
| Billing | Annual fee, varies by TLD | Monthly fee per zone, plus a charge per million queries |
| Can exist without the other | Yes | Yes |
What Route 53 creates for you
A new public zone starts with two records, and Route 53 creates both:
- An NS record at the zone apex (the name equal to the zone name, such as
example.com). It lists the four name servers assigned to this zone. - An SOA record (start of authority) at the apex. It carries administrative values such as the primary server name, a serial number, and the negative caching TTL, which is how long resolvers cache an "this name does not exist" answer.
Leave both in place. Deleting the NS or SOA record at the apex is not allowed, and editing them is rarely useful. The default NS record has a TTL of 172800 seconds (two days), and the SOA record has a TTL of 900 seconds.
Creating a zone in the console
- Open the Route 53 console and choose Hosted zones, then Create hosted zone.
- Enter the domain name, for example
example.com. Use lowercase and no trailing dot. - Set Type to Public hosted zone.
- Optionally add tags, then choose Create hosted zone.
The console generates the caller reference for you. When creation finishes, open the zone and copy the four values of the apex NS record.
Creating a zone with the CLI
The CLI needs two values: the zone name and a caller reference. The caller reference is a unique string that makes the request idempotent. If a network error makes you retry the same request with the same reference, Route 53 recognizes the retry and does not create a second zone. A timestamp is a common choice.
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']"Replace ZONE_ID with the ID from the first command's output. The second command prints the NS record, whose ResourceRecords list holds the four name servers to configure at your registrar.
Copying the ID by hand is error-prone in scripts. This version captures it and prints the name servers directly:
ZONE_ID=$(aws route53 create-hosted-zone \
--name example.com \
--caller-reference "$(date +%s)" \
--query "HostedZone.Id" \
--output text)
echo "Created zone: $ZONE_ID"
aws route53 get-hosted-zone \
--id "$ZONE_ID" \
--query "DelegationSet.NameServers" \
--output textThe response of create-hosted-zone also includes a ChangeInfo block with a status of PENDING. The status becomes INSYNC once the change has reached all Route 53 servers, usually within a minute. You can poll it with aws route53 get-change --id CHANGE_ID.
Finding a zone later
You will often need the ID of an existing zone. Search by name:
aws route53 list-hosted-zones-by-name \
--dns-name example.com \
--max-items 1 \
--query "HostedZones[0].[Id,Name,Config.PrivateZone]"Two details to remember. The returned Name ends with a dot (example.com.), which is the fully qualified form. Also, list-hosted-zones-by-name returns zones sorted starting from the name you give, so it can return a different zone if yours does not exist. Check that the returned name matches before you use the ID. The PrivateZone value shows false for public zones.
Duplicate zones and name server sets
Route 53 lets you create several hosted zones with the same name. Each gets a different set of four name servers. This is deliberate. It allows you to prepare a replacement zone before switching, for example during a migration. It is also the most common source of confusion.
Consider this sequence:
- You register
example.comwith Route 53. Route 53 automatically creates a hosted zone and sets the registered domain's name servers to match it. - Later, you create another zone for
example.comand add all your records there. - Queries still go to the first zone, because the registration points to its name servers. Your new records never appear.
The fix is to either add the records to the zone that the registration uses, or update the registration's name servers to those of the new zone. Compare the NS record of each zone with what the public DNS returns (the troubleshooting chapter shows how with dig).
A reusable delegation set is a group of four name servers that you create once and assign to several zones. All zones using it share identical name server names, which makes bulk migrations and vanity name servers easier. You create it with aws route53 create-reusable-delegation-set and pass its ID with --delegation-set-id when creating a zone. Most teams do not need it. Without it, every zone has its own set.
Hosted zones for subdomains
You can create a zone for a subdomain such as dev.example.com, separate from the zone for example.com. Teams do this to give a different account or team control over a branch of the name tree. The subdomain zone has its own NS record and its own four name servers. For it to work, the parent zone must contain an NS record named dev.example.com that lists those four servers. This is delegation within DNS itself.
aws route53 create-hosted-zone \
--name dev.example.com \
--caller-reference "$(date +%s)"Then add the subdomain's name servers to the parent zone with a change batch. The values below are examples. Use the four servers from your new subdomain zone.
{
"Comment": "Delegate dev.example.com to its own hosted zone",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "dev.example.com",
"Type": "NS",
"TTL": 300,
"ResourceRecords": [
{ "Value": "ns-111.awsdns-11.com" },
{ "Value": "ns-222.awsdns-22.net" },
{ "Value": "ns-333.awsdns-33.org" },
{ "Value": "ns-444.awsdns-44.co.uk" }
]
}
}
]
}Save it as dev-ns.json and apply it to the parent zone:
aws route53 change-resource-record-sets \
--hosted-zone-id PARENT_ZONE_ID \
--change-batch file://dev-ns.jsonCommon errors
- Trailing dots and case.
Example.COM.andexample.comname the same zone, but pick one form and use it consistently in scripts. - A zone for a name you do not control. Route 53 does not check ownership when you create a zone, so creation succeeding proves nothing. The zone has no effect until the parent delegates to it.
- Wrong zone ID in a change batch. Applying a change to a zone that is not live gives a successful API response and no visible effect. Always confirm which zone your registrar points to.
- Deleting a zone with records.
aws route53 delete-hosted-zonefails withHostedZoneNotEmptywhile any record other than the apex NS and SOA exists. Delete those records first. If you delete a zone that is still delegated, the domain stops resolving, and you are billed for the zone for the month if you delete it after the first twelve hours of the month... check the current pricing page for the exact billing rule. - Missing permissions. Creating and changing zones requires actions such as
route53:CreateHostedZone,route53:ChangeResourceRecordSetsandroute53:GetChange.
Summary
A public hosted zone holds the records for one domain on four Route 53 name servers, and it starts with an NS record and an SOA record that you should leave alone. Creating a zone is one command, but it takes effect only when the parent (the registrar for a top-level domain, or the parent zone for a subdomain) lists its name servers. Duplicate zones with the same name are allowed, so always check which one is delegated.
Exercise
You registered example.com with Route 53, and a hosted zone was created automatically. A colleague later created a second hosted zone for example.com in the same account and added a record for shop.example.com there. The record never resolves. What is the most likely cause, and how would you fix it?
Show answer
The registration's name servers still point to the first hosted zone, so resolvers never query the second zone, which has a different set of four name servers. Either add the shop.example.com record to the first zone, or update the domain's name servers to match the NS record of the second zone (and then delete the unused zone). Compare the NS record of each zone with the output of dig NS example.com +short to see which one is live.
Exercise
You create a hosted zone for dev.example.com and add an A record for app.dev.example.com. Queries for it return no answer. What step is missing?
Show answer
The parent zone example.com needs an NS record named dev.example.com that lists the four name servers of the dev.example.com zone. Without it, resolvers are never sent to the subdomain zone.