Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Cloud

AWS CLI Route 53 Commands: Hosted Zones and DNS Records

We control names on the internet: hosted zones, A, CNAME and alias records, health checks, DNS tests and cleanup.

In this chapter

  • Create a hosted zone
  • Add and change records
  • Use alias records
  • Health checks
  • Test DNS and delete

1. The big picture: the phone contacts list

You save "Aai" in contacts and the phone finds the number. DNS saves "shop.example.com" and finds the server IP. Route 53 is the contacts list for your domain.

Commands are in aws route53: create-hosted-zone, change-resource-record-sets, list-resource-record-sets, create-health-check, test-dns-answer.

DNS workflowcreate-hosted-zoneset NS at the registrarchange-resource-record-sets UPSERTwait resource-record-sets-changeddig / test-dns-answer
Route 53 is global, so no region is needed.

2. Hosted zone

Your domain needs a place where its records live.

A public hosted zone holds records and gives 4 name servers. caller-reference must be unique each time.

  1. Create the zone.
Z=$(aws route53 create-hosted-zone --name example.com --caller-reference cli-$(date +%s) --query HostedZone.Id --output text)
echo $Z

Expected output:

/hostedzone/Z0123456789ABCDEFGHIJ
  1. See the name servers.
aws route53 get-hosted-zone --id $Z --query DelegationSet.NameServers --output text

Expected output:

ns-123.awsdns-15.com  ns-456.awsdns-57.net  ns-789.awsdns-34.org  ns-1011.awsdns-62.co.uk

3. Add and change records

DNS answers questions about names. For example, an A record associates a name with an IPv4 address. Creating a public hosted zone produces authoritative nameservers for that zone. The parent domain or registrar must point its delegation to those nameservers for ordinary clients to find it. Two hosted zones with the same name can hold different records, and clients only follow the configured delegation.

Use an approved disposable subdomain. Confirm an UPSERT changes the intended hosted zone and wait for Route 53 to report INSYNC. Ask its authoritative server for the lab record, then ask your normal resolver. The normal resolver can still report the previous answer while its cached record is valid. A surprising result at the authoritative server suggests the wrong zone or record, while a discrepancy at the resolver points you to delegation or caching.

You bought a server and want www to point at it.

change-resource-record-sets takes a change batch with CREATE, DELETE or UPSERT. UPSERT creates or updates.

  1. Write the change.
cat > a.json <<J
{"Changes":[{"Action":"UPSERT","ResourceRecordSet":{"Name":"www.example.com","Type":"A","TTL":300,"ResourceRecords":[{"Value":"15.252.55.24"}]}}]}
J

Expected output:

(no output means success)
  1. Apply and wait.
C=$(aws route53 change-resource-record-sets --hosted-zone-id $Z --change-batch file://a.json --query ChangeInfo.Id --output text)
aws route53 wait resource-record-sets-changed --id $C
aws route53 get-change --id $C --query ChangeInfo.Status --output text

Expected output:

INSYNC
  1. List records.
aws route53 list-resource-record-sets --hosted-zone-id $Z --query "ResourceRecordSets[].[Name,Type]" --output text

Expected output:

example.com.  NS
example.com.  SOA
www.example.com.  A

4. Alias records

Suppose your approved zone is example.com and the AWS load balancer has its own DNS name. A Route 53 alias lets a supported record direct clients to that AWS target. The lab needs the hosted zone ID of the zone you are editing and, in the alias target configuration, the hosted zone ID associated with the target AWS resource. The two values describe different objects.

Submit the change in the lab zone and wait using its change ID. Then inspect the DNS answer. For an alias A record a recursive query returns IPv4 answers when appropriate; it does not display the load balancer host as a normal CNAME response. Compare the intended alias target in the zone with authoritative and recursive results. Use the zone’s established test subdomain before changing real customer records.

The root domain example.com cannot be a CNAME, but you want it on a load balancer.

An alias A record points to AWS resources (ALB, CloudFront, S3 website) for free queries. It needs the target hosted zone id.

  1. Alias the apex to an ALB.
cat > al.json <<J
{"Changes":[{"Action":"UPSERT","ResourceRecordSet":{"Name":"example.com","Type":"A","AliasTarget":{"HostedZoneId":"ZP97RAFLXTNZK","DNSName":"cli-alb-123.ap-south-1.elb.amazonaws.com","EvaluateTargetHealth":true}}}]}
J
aws route53 change-resource-record-sets --hosted-zone-id $Z --change-batch file://al.json --query ChangeInfo.Status --output text

Expected output:

PENDING

5. Health checks and testing

If a server dies, DNS should stop sending people to it.

create-health-check probes a URL. Failover records use it. test-dns-answer asks Route 53 what it would reply.

  1. Create a health check.
H=$(aws route53 create-health-check --caller-reference hc-$(date +%s) --health-check-config Type=HTTPS,FullyQualifiedDomainName=www.example.com,Port=443,ResourcePath=/,RequestInterval=30,FailureThreshold=3 --query HealthCheck.Id --output text)
echo $H

Expected output:

a1b2c3d4-5678-90ab-cdef-111122223333
  1. Test the answer.
aws route53 test-dns-answer --hosted-zone-id $Z --record-name www.example.com --record-type A --query "[RecordData,ResponseCode]" --output text

Expected output:

15.252.55.24  NOERROR
  1. Check from your machine.
dig +short www.example.com @ns-123.awsdns-15.com

Expected output:

15.252.55.24

6. Same action in Python, Node.js, Java, Go, .NET and PHP

Scripts start in the CLI. Apps call the same API through an SDK. Knowing both helps you move a tested command into real code.

Low-level CLI commands expose service operations. A high-level command or an automatically paginated list can make multiple requests. For example, aws route53 change-resource-record-sets --hosted-zone-id $Z --change-batch file://a.json maps to the Upsert record API.

Same action (Upsert record) from code. Set the intended profile and Region for the SDK. Provider support and precedence can differ by SDK, and an explicit client setting can override defaults.

StackCode
Python (boto3)boto3.client("route53").change_resource_record_sets(HostedZoneId=z,ChangeBatch=batch)
Node.js (v3)await r53.send(new ChangeResourceRecordSetsCommand({HostedZoneId:z,ChangeBatch:batch}));
Java (v2)r53.changeResourceRecordSets(r -> r.hostedZoneId(z).changeBatch(batch));
Go (v2)c.ChangeResourceRecordSets(ctx, &route53.ChangeResourceRecordSetsInput{HostedZoneId: aws.String(z), ChangeBatch: batch})
.NETawait r53.ChangeResourceRecordSetsAsync(new ChangeResourceRecordSetsRequest{HostedZoneId=z,ChangeBatch=batch});
PHP$r53->changeResourceRecordSets(["HostedZoneId"=>$z,"ChangeBatch"=>$batch]);

7. Clean up so nothing keeps costing

Lab resources left running cost money and can be a security risk.

Delete in reverse order: children first, then parents.

  1. Delete records you added (zone must have only NS and SOA).
sed -i s/UPSERT/DELETE/ a.json al.json
aws route53 change-resource-record-sets --hosted-zone-id $Z --change-batch file://a.json
aws route53 change-resource-record-sets --hosted-zone-id $Z --change-batch file://al.json

Expected output:

(no output means success)
  1. Delete the health check and zone.
aws route53 delete-health-check --health-check-id $H
aws route53 delete-hosted-zone --id $Z --query ChangeInfo.Status --output text

Expected output:

PENDING
  1. Verify.
aws route53 list-hosted-zones-by-name --dns-name example.com --query "HostedZones[?Name=='example.com.']"

Expected output:

[]

Ravindra Bagale's Tip

A hosted zone costs about 0.50 USD per month even if unused. Delete test zones, and remember NS changes at the registrar can take up to 48 hours.

Common errors: cause and safe next check

Records are created in the wrong hosted zone

A hosted zone has the same name as its domain, but an account can have more than one zone over time. Confirm the hosted zone ID for the domain you intend before you call change-resource-record-sets.

A private zone is used when internet clients need the name

Public hosted zones serve internet routing. Private hosted zones serve Amazon VPC routing. Inspect whether callers are on the internet or only inside a VPC, then use the matching zone type.

Someone debates alias versus CNAME without checking the live record needs

Record choices depend on the target and on what Route 53 allows for that name. Prefer reading the current record-type guidance during rebase instead of forcing one type from memory. Start by listing existing records and the target you need to reach.

Practical questions and full answers

What is a hosted zone?

A hosted zone is a container for records. Those records hold information about how to route traffic for a domain and its subdomains. The hosted zone has the same name as the domain.

What is the difference between public and private hosted zones?

Public hosted zones contain records that specify how you want to route traffic on the internet. Private hosted zones contain records that specify how you want to route traffic in an Amazon VPC. Pick the type that matches who must resolve the name.

Where should I look before changing DNS with the CLI?

Confirm the hosted zone ID, the record name, the record type, and the values you intend to publish. Then apply a change batch carefully. Re-check TTL and record-type rules from the current Route 53 developer guide during rebase if a change is rejected.

8. Interview questions and answers

Q. A vs CNAME vs alias?

A maps to an IP. CNAME maps to another name (not at apex). Alias is Route 53 only, works at apex and points to AWS resources.

Q. What does UPSERT do?

Creates the record if missing, updates it if present.

Q. What is TTL?

Seconds resolvers cache the answer.

Q. Why caller-reference?

Idempotency: a unique string so a retry does not create two zones.

Q. Routing policies?

Simple, weighted, latency, failover, geolocation, multivalue.

Try at home

  1. Create a weighted pair of A records 70/30 and test with test-dns-answer.
  2. Add a TXT record for domain verification.

In short

  1. create-hosted-zone.
  2. Change batch JSON.
  3. UPSERT.
  4. Alias at apex.
  5. Delete records before zone.

Check authoritative DNS before waiting on caches

Use a disposable delegated zone or subdomain. After a change reaches INSYNC, query the authoritative server and check the parent delegation, then test normal recursive resolution. Remove your lab records and delegation before deleting the zone.

Interview check Does INSYNC mean every client cache saw the new record?

No. It confirms propagation to Route 53 authoritative servers; recursive caches may still hold the old record for the remaining TTL.

Reference documentation

Practise this chapter

Interview questions and answers

How would you troubleshoot a lab DNS change that works for some clients but not others?

I would confirm the intended hosted zone and parent delegation, then query the authoritative servers directly. I would compare those answers with affected recursive resolvers and inspect remaining TTL where available. The source of the mismatch determines whether to update the zone or wait for caches.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. What directs public recursive resolvers to the intended Route 53 zone?

Answer and explanation

C. The parent’s nameserver delegation

The parent delegation points DNS requests to the authoritative nameservers for the selected zone.

2. Route 53 is INSYNC but a normal resolver still returns an old address. What is a likely reason?

Answer and explanation

A. A previously cached record that has not expired

INSYNC concerns Route 53’s authoritative servers. Recursive caches can retain their original answer for the TTL.

3. What helps distinguish a wrong record from a resolver cache?

Answer and explanation

C. Compare the intended authoritative answer with the recursive answer

The authoritative answer shows the current zone data, while the recursive answer may reflect delegation or caching.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

About this scenario

Maple Leaf Books is a bookselling business in Toronto. Emily Tremblay looks after its IT and cloud work. They count money in CAD and run their AWS resources in the ca-central-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 12

Easy List hosted zones

You need the zone ID to change records.

List all hosted zones in the account.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Find the database endpoint

Your app connects using the endpoint name, not an IP.

Describe DB instance mapleleafbooks-db.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Biggest orders first

Querying the database is daily work after you set up RDS.

Show order id and amount, biggest amount first.

Tables: customers(id, name, city) and orders(id, customer_id, amount, odate).

  1. Find the table the task is about (see the table list above the box).
  2. Write the SQL statement step by step: what, from where, which rows.
  3. End the statement with ;
  4. Click Check answer. Your query runs on a practice copy of the table.

Easy Filter customers by city

Querying the database is daily work after you set up RDS.

List the names of customers in Pune.

Tables: customers(id, name, city) and orders(id, customer_id, amount, odate).

  1. Find the table the task is about (see the table list above the box).
  2. Write the SQL statement step by step: what, from where, which rows.
  3. End the statement with ;
  4. Click Check answer. Your query runs on a practice copy of the table.

Medium Create a hosted zone

A hosted zone holds all DNS records for your domain.

Create a public hosted zone for mapleleafbooks.ca, with caller reference mapleleafbooks-2026-01.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium List records in a zone

Check what A, CNAME and MX records exist before you change them.

List the record sets in hosted zone Z0123456789ABCDEFGHIJ.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Remove small orders

Querying the database is daily work after you set up RDS.

Delete orders with amount below 200.

Tables: customers(id, name, city) and orders(id, customer_id, amount, odate).

  1. Find the table the task is about (see the table list above the box).
  2. Write the SQL statement step by step: what, from where, which rows.
  3. End the statement with ;
  4. Click Check answer. Your query runs on a practice copy of the table.

Medium Orders with customer names

Querying the database is daily work after you set up RDS.

Show each customer name with each order amount.

Tables: customers(id, name, city) and orders(id, customer_id, amount, odate).

  1. Find the table the task is about (see the table list above the box).
  2. Write the SQL statement step by step: what, from where, which rows.
  3. End the statement with ;
  4. Click Check answer. Your query runs on a practice copy of the table.

Medium Total sales

Querying the database is daily work after you set up RDS.

Show the total of all order amounts as one number.

Tables: customers(id, name, city) and orders(id, customer_id, amount, odate).

  1. Find the table the task is about (see the table list above the box).
  2. Write the SQL statement step by step: what, from where, which rows.
  3. End the statement with ;
  4. Click Check answer. Your query runs on a practice copy of the table.

Hard Create or update a DNS record

UPSERT creates the record or updates it if it already exists.

Apply the record changes in change.json to hosted zone Z0123456789ABCDEFGHIJ.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Hard Sales per customer

Querying the database is daily work after you set up RDS.

Show customer_id and total amount per customer, only where total is above 1000.

Tables: customers(id, name, city) and orders(id, customer_id, amount, odate).

  1. Find the table the task is about (see the table list above the box).
  2. Write the SQL statement step by step: what, from where, which rows.
  3. End the statement with ;
  4. Click Check answer. Your query runs on a practice copy of the table.

Hard Customers with no orders

Querying the database is daily work after you set up RDS.

List names of customers who have never ordered.

Tables: customers(id, name, city) and orders(id, customer_id, amount, odate).

  1. Find the table the task is about (see the table list above the box).
  2. Write the SQL statement step by step: what, from where, which rows.
  3. End the statement with ;
  4. Click Check answer. Your query runs on a practice copy of the table.

Revision, comparison and interview cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Route 53 UPSERT. Point www at your server IP. Write a change batch JSON. change-resource-record-sets then wait. Verify with test-dns-answer or dig.
Revision card: Route 53 UPSERT · Download PNG · Open card page
Route 53 alias. Apex cannot be a CNAME. Alias A points to ALB, CloudFront, S3. Needs the target HostedZoneId. Alias queries to AWS targets are free.
Revision card: Route 53 alias · Download PNG · Open card page
CNAME vs Alias A. Not allowed at example.com. / Works at example.com.
Comparison: CNAME vs Alias A · Download PNG · Open card page
CNAME vs alias?. CNAME maps a name to a name, not at apex. Alias is Route 53 only and works at apex. Alias to AWS resources is free to query.
Interview card: CNAME vs alias? · Download PNG · Open card page

More cards: Ravi Sir's Cards.