0
0
AWScloud~5 mins

Hosted zones concept in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you want to connect your website or app to a domain name, you need a way to tell the internet where to find it. Hosted zones help you manage the settings that link your domain name to your servers or services.
When you buy a domain name and want to point it to your website hosted on AWS.
When you need to manage DNS records like A, CNAME, or MX for your domain.
When you want to create subdomains like blog.example.com or shop.example.com.
When you want to route traffic to different AWS resources like load balancers or S3 buckets.
When you want to keep your domain's DNS settings organized and secure within AWS.
Commands
This command creates a new hosted zone for the domain example.com. The caller reference is a unique string to identify this request.
Terminal
aws route53 create-hosted-zone --name example.com --caller-reference 20240601120000
Expected OutputExpected
{ "HostedZone": { "Id": "/hostedzone/Z1D633PJN98FT9", "Name": "example.com.", "CallerReference": "20240601120000", "Config": { "PrivateZone": false }, "ResourceRecordSetCount": 2 }, "ChangeInfo": { "Id": "/change/C2682N5HXP0BZ4", "Status": "PENDING", "SubmittedAt": "2024-06-01T12:00:00Z" } }
--name - Specifies the domain name for the hosted zone.
--caller-reference - A unique string to identify the request and avoid duplicates.
This command lists all hosted zones in your AWS account to verify the new hosted zone was created.
Terminal
aws route53 list-hosted-zones
Expected OutputExpected
{ "HostedZones": [ { "Id": "/hostedzone/Z1D633PJN98FT9", "Name": "example.com.", "CallerReference": "20240601120000", "Config": { "PrivateZone": false }, "ResourceRecordSetCount": 2 } ] }
This command adds an A record to the hosted zone, pointing www.example.com to the IP address 192.0.2.44.
Terminal
aws route53 change-resource-record-sets --hosted-zone-id Z1D633PJN98FT9 --change-batch '{"Changes":[{"Action":"CREATE","ResourceRecordSet":{"Name":"www.example.com.","Type":"A","TTL":300,"ResourceRecords":[{"Value":"192.0.2.44"}]}}]}'
Expected OutputExpected
{ "ChangeInfo": { "Id": "/change/C2RDJXEXAMPLE", "Status": "PENDING", "SubmittedAt": "2024-06-01T12:05:00Z" } }
--hosted-zone-id - Specifies which hosted zone to update.
--change-batch - Defines the DNS record changes to apply.
This command lists all DNS records in the hosted zone to confirm the new record was added.
Terminal
aws route53 list-resource-record-sets --hosted-zone-id Z1D633PJN98FT9
Expected OutputExpected
{ "ResourceRecordSets": [ { "Name": "example.com.", "Type": "NS", "TTL": 172800, "ResourceRecords": [ {"Value": "ns-2048.awsdns-64.com."}, {"Value": "ns-2049.awsdns-65.net."}, {"Value": "ns-2050.awsdns-66.org."}, {"Value": "ns-2051.awsdns-67.co.uk."} ] }, { "Name": "example.com.", "Type": "SOA", "TTL": 900, "ResourceRecords": [ {"Value": "ns-2048.awsdns-64.com. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"} ] }, { "Name": "www.example.com.", "Type": "A", "TTL": 300, "ResourceRecords": [ {"Value": "192.0.2.44"} ] } ] }
--hosted-zone-id - Specifies which hosted zone's records to list.
Key Concept

If you remember nothing else from this pattern, remember: a hosted zone is where you manage all the DNS settings for your domain in AWS.

Common Mistakes
Using the wrong hosted zone ID when adding or listing DNS records.
The commands will fail or update the wrong domain's settings, causing your website to be unreachable.
Always copy the hosted zone ID exactly from the create or list command output before making changes.
Not waiting for DNS changes to propagate after updating records.
Your changes may not be visible immediately, leading to confusion or downtime.
Allow some time (usually a few minutes) for DNS changes to take effect and verify with the list command.
Summary
Create a hosted zone to manage your domain's DNS settings in AWS.
Add DNS records like A records to point subdomains to IP addresses.
List hosted zones and records to verify your DNS configuration.