Sub topic 5
Common record types and choosing a TTL
This chapter assumes you know how a recursive resolver queries authoritative servers, and that you have a public hosted zone for your domain. It covers the record types you will create most often and how to pick a TTL (time to live) for each.
What a record contains
Every record in a hosted zone has four parts:
- A name, such as
www.example.com. - A type, such as
AorMX. - A TTL, in seconds. Resolvers may cache the answer for this long.
- One or more values.
Records that share a name and type form a record set. Route 53 treats the set as one unit, so you change all of its values together.
The record types you will use most
| Type | Holds | Typical use |
|---|---|---|
| A | IPv4 address | `www.example.com` points to `192.0.2.10` |
| AAAA | IPv6 address | The same name, reachable over IPv6 |
| CNAME | Another name | `blog.example.com` points to `example.hosting.net` |
| MX | Priority and mail server name | Where email for the domain is delivered |
| TXT | Free text | SPF, domain verification, DKIM keys |
| NS | Name servers | The servers that are authoritative for the zone |
Some details are easy to miss:
- A CNAME maps one name to another name, and the resolver then looks up that second name. A name that has a CNAME cannot have any other record type. For that reason you cannot put a CNAME at the zone apex (
example.com), which already holds NS and SOA records. The next chapter shows how alias records solve this. - An MX value has a priority and a host name, for example
10 mail1.example.com. The lowest number is tried first. The host name must have an A or AAAA record. It cannot point to a CNAME. - A TXT value is quoted. Long values, such as DKIM keys, are split into quoted strings of up to 255 characters each, all inside one record value.
- Route 53 creates the NS and SOA records when you create the zone. Leave the apex NS record alone unless you are deliberately changing delegation.
Creating a record with a change batch
You change records by submitting a change batch, a JSON file that lists actions. This example creates www.example.com as an A record with a TTL of 300 seconds.
{
"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" }]
}
}
]
}UPSERT creates the record if it is missing and replaces it if it exists. Submit the file with the CLI:
aws route53 change-resource-record-sets \
--hosted-zone-id ZONE_ID \
--change-batch file://www-a-record.jsonThe command returns a change ID. You can check it with aws route53 get-change. The status moves from PENDING to INSYNC once the change has reached all Route 53 name servers.
How TTL works
The TTL is a cache lifetime. After a resolver fetches your record, it reuses the answer until the TTL runs out and only then asks Route 53 again.
The trade-off is direct:
- A long TTL, such as 86400 (one day), lowers the number of queries and speeds up lookups, but changes take up to a day to reach every user.
- A short TTL, such as 60, makes changes and failover fast, but produces more queries. Route 53 bills per query, and each cache miss adds a lookup delay for the user.
Choosing a TTL
- Stable records (MX, TXT, NS): 3600 to 86400 seconds.
- Typical web records: 300 seconds is a sensible default.
- Records you plan to change soon: lower the TTL to 60 well before the change, wait at least as long as the old TTL, make the change, then raise it again.
- Failover and weighted records: 60 seconds, so shifts in traffic take effect quickly.
Common errors
- Adding a CNAME at the apex, or next to another record of the same name. Route 53 rejects the change.
- Pointing an MX record at a CNAME.
- Forgetting the trailing quotes in a TXT value.
- Testing right after a change and seeing the old answer. This is a cache, not a failed update.
Exercise
You plan to move www.example.com to a new IP address tomorrow. The record currently has a TTL of 86400. What should you do today, and why?
Show answer
Lower the TTL to 60 today, then wait at least 24 hours (the old TTL) so every resolver cache has expired the old long-lived answer. Tomorrow, change the IP address. Resolvers will pick up the new address within about a minute. Raise the TTL again afterward to cut query volume.