Sub topic 5
Common record types and choosing a TTL
This chapter assumes you have a public hosted zone for your domain and have delegated the domain to its Route 53 name servers. You should also know what a resolver cache is and what a TTL is in general terms. Here you will learn what each common record type does, which combinations are not allowed, and how to pick a TTL for each record.
What a record is
A hosted zone holds a set of records. Each record set has four parts that matter here:
- Name: the domain name the record answers for, such as
www.example.com. - Type: the kind of data stored, such as
AorMX. - TTL: the time to live, in seconds. It tells resolvers how long they may cache the answer.
- Value: one or more values of the right shape for the type.
Route 53 identifies a record set by name and type. If you also use a routing policy, the set identifier is part of the key. You will see this later with weighted and failover records.
The record types you will use most
| Type | Holds | Example value |
|---|---|---|
| A | An IPv4 address | `192.0.2.10` |
| AAAA | An IPv6 address | `2001:db8::10` |
| CNAME | An alias to another name | `app.example.net` |
| MX | A mail server, with a priority | `10 mail.example.com` |
| TXT | Free text, used for verification and email policy | `"v=spf1 include:_spf.example.com ~all"` |
| NS | The name servers for a zone or subdomain | `ns-123.awsdns-45.com` |
| SOA | Zone administration data | created by Route 53 |
A and AAAA
An A record maps a name to one or more IPv4 addresses. An AAAA record does the same for IPv6. A client that supports both asks for both and picks one. If a name has an A record and no AAAA record, IPv6-only clients cannot reach it. If you add AAAA records, make sure the IPv6 endpoint really works. A broken AAAA record can slow down or break connections for dual-stack clients.
You can put several values in one record set. Resolvers return all of them, and clients typically try them in the order given or in a rotated order. This is simple round-robin DNS. It does not check health. For that you need a health check, covered in a later chapter.
CNAME
A CNAME record says "this name is another name for that one." The resolver restarts the lookup for the target name. CNAME has three rules:
- A name with a CNAME record cannot have any other record type at the same name.
- A CNAME cannot be created at the zone apex (
example.comitself), because the apex must hold SOA and NS records. - Each lookup costs the resolver extra work, since it must follow the target.
For these reasons, an alias record is often the better choice for AWS targets, especially at the apex. The next chapter covers aliases. Use a CNAME when the target is outside AWS, or for a subdomain that points to a service run by a third party.
MX
An MX record names the mail servers for a domain. Each value has a priority number and a host name, separated by a space. Senders try the lowest number first and fall back to higher numbers. Two values with the same priority share the load.
The target must be a host name that has an A or AAAA record. Do not point it at an IP address, and avoid pointing it at a CNAME.
TXT
A TXT record holds text. Common uses are SPF, DKIM and DMARC email policies and domain ownership checks for services such as certificate authorities. A TXT value must be enclosed in double quotes. A single string in a TXT record is limited to 255 characters. For longer values, such as DKIM keys, you split the value into several quoted strings in one value, separated by a space. Resolvers join them back together.
NS and SOA
Route 53 creates an NS record and an SOA record at the apex when you create a hosted zone. The apex NS record lists the four name servers assigned to the zone. Leave it alone: it must match the delegation at your registrar.
You can also create an NS record for a subdomain, such as dev.example.com. This delegates that subdomain to a different set of name servers, for example a separate hosted zone. The SOA record is managed by Route 53, and you normally never edit it. Its last field affects how long resolvers cache "name does not exist" answers, which matters when you troubleshoot.
Creating records with a change batch
You change records by sending a change batch. Each change has an action and a record set. The action UPSERT creates the record if it is missing and replaces it if it exists, so it is safe to rerun. This batch sets an A record with a 300-second TTL:
{
"Comment": "Create or update the www A record",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "www.example.com",
"Type": "A",
"TTL": 300,
"ResourceRecords": [{ "Value": "192.0.2.10" }]
}
}
]
}Save it as www-a-record.json and submit it:
aws route53 change-resource-record-sets \
--hosted-zone-id ZONE_ID \
--change-batch file://www-a-record.jsonThe command returns a change ID with a status of PENDING. Route 53 reports INSYNC once the change reaches all of its authoritative servers, which usually takes under a minute. You can check with aws route53 get-change --id CHANGE_ID.
A batch can hold many changes, and Route 53 applies them as one unit: either all succeed or none do. This lets you create several records together. The next batch creates mail and verification records:
{
"Comment": "Mail and verification records",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "example.com",
"Type": "MX",
"TTL": 3600,
"ResourceRecords": [
{ "Value": "10 mail1.example.com" },
{ "Value": "20 mail2.example.com" }
]
}
},
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "example.com",
"Type": "TXT",
"TTL": 3600,
"ResourceRecords": [
{ "Value": "\"v=spf1 include:_spf.example.com ~all\"" }
]
}
},
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "docs.example.com",
"Type": "CNAME",
"TTL": 300,
"ResourceRecords": [{ "Value": "example.github.io" }]
}
}
]
}Inside JSON, the quotes around the TXT value are escaped with backslashes. Forgetting them is a common error, and Route 53 rejects the change with an invalid input message.
What TTL does
A TTL is a cache lifetime. A recursive resolver stores an answer and reuses it until the TTL expires, then asks the authoritative servers again. Two effects follow:
- A change takes time to spread. If you edit a record with a 3600-second TTL, some resolvers keep serving the old value for up to an hour. Route 53 itself has the new value within about a minute. Resolvers that cached the answer just before your edit hold it for the full TTL.
- Short TTLs mean more queries. Each expiry sends another query to Route 53. Route 53 bills standard queries, so a very short TTL on a busy name raises your bill and adds a little lookup latency for users. Queries for alias records that point to AWS resources are not billed.
Remember that the TTL clock runs at each resolver separately. There is no way to flush all caches. Some resolvers also apply their own minimum or maximum, so a TTL of 1 may be treated as longer.
Choosing a TTL
There is no single correct value. Use these starting points and adjust to your risk:
| Situation | Suggested TTL | Reason |
|---|---|---|
| Failover or weighted records | 60 seconds | Clients should react quickly to a change |
| Ordinary web records | 300 seconds | A reasonable balance of speed and query volume |
| MX, TXT, verification records | 3600 seconds | These rarely change |
| Subdomain NS delegations | 3600 to 172800 seconds | The delegation almost never changes |
| Record you plan to move soon | Lower it ahead of time | See the next section |
The Route 53 console defaults to 300 seconds. Apex NS records are created with 172800 seconds (two days), so a wrong delegation lingers for a long time.
Lowering the TTL before a migration
If you plan to move a site to a new IP address, the old TTL controls how long the old address can be served after the switch. Follow this order:
- Lower the TTL, for example from 3600 to 60.
- Wait at least as long as the old TTL, so every resolver has dropped the long-lived copy.
- Change the value to the new address.
- Confirm the new traffic arrives, then raise the TTL again.
Skipping step 2 is the common mistake. A resolver that cached the record with a 3600-second TTL a minute before you lowered it still holds the old value for almost an hour.
Negative caching
Resolvers also cache the answer "this name does not exist" (NXDOMAIN). The lifetime is the lower of the SOA record's own TTL and the minimum field in the SOA data. In a Route 53 zone this is 900 seconds by default. If you query a name before you create it, a resolver may keep returning "not found" for up to 15 minutes after you add the record. When you test a new name, query it only after you create it.
Common errors
- CNAME at the apex or beside other records. Route 53 rejects the change. Use an alias record or a different name.
- Unquoted TXT values. The value must be wrapped in escaped double quotes in JSON.
- MX pointing at a CNAME or an IP. Some mail servers refuse to deliver. Point to a host with an A or AAAA record.
- Editing the apex NS record. The zone stops matching its delegation and queries fail for some users.
- Upserting a partial value list. Values you leave out are removed.
- Trusting a quick test. A resolver you query repeatedly may be serving a cached answer, not the current one.
Exercise
You are moving www.example.com to a new IP address. The record currently has a TTL of 86400 seconds. Describe the steps and explain how long you must wait before changing the value.
Show answer
First upsert the record with the same value and a low TTL such as 60 seconds. Then wait at least 86400 seconds (24 hours), the old TTL, so that every resolver that cached the old copy has let it expire. After that, upsert the new IP address, check that traffic reaches the new server, and finally raise the TTL again. If you change the value before the wait is over, some resolvers keep serving the old address for up to 24 hours.
Exercise
A teammate submits a change batch that creates a CNAME for docs.example.com. The change fails, and docs.example.com already has a TXT record. What is the cause, and what are two ways to fix it?
Show answer
A CNAME cannot coexist with any other record type at the same name. To fix it, either remove the TXT record from docs.example.com, or move the TXT value to a different name and keep the CNAME. If the target is an AWS resource, an alias record is another option, but it must also be the only record type at that name for the same target type.