-
Notifications
You must be signed in to change notification settings - Fork 61
Route 53 Subdomains
Used in the examples:
Parent domain: mydomain.com. Subdomain: sub.mydomain.com.
Summary Steps (From the AWS Console)
Create a new subdomain zone...
- In the Amazon Route 53 console, click Create Hosted Zone.
- In the right pane, enter the domain name; sub.mydomain.com and a comment (optional).
- Below the right pane, click Create.
- Take note of the name servers assigned to the new zone.
From the parent domain...
Note: The parent domain and subdomain can be located in the same account, or in different AWS accounts.
- In the AWS Route 53 console, click Go to Record Sets.
- Click Create Record Set.
- In the right pane, enter the zone name; sub.mydomain.com.
- The type should be NS.
- In the value field, enter the name servers from the last step above.
- Below the right pane, click Create.
- Done!
Using the AWS CLI
Create a new subdomain zone...
aws route53 create-hosted-zone \ --name sub.mydomain.com. \ --caller-reference mysubdomain
Take note of the name servers from the JSON output delegated to the new zone. You'll need them in the next step to create a NS record in the parent domain.
Create a new NS record in the parent domain...
aws route53 change-resource-record-sets \ --hosted-zone-id <parent-zone-id> \ --change-batch file://r53-ns-batch.json
r53 NS batch file template:
{ "Comment": "Create a subdomain NS record in the parent domain", "Changes": [ { "Action": "CREATE", "ResourceRecordSet": { "Name": "sub.mydomain.com", "Type": "NS", "TTL": 300, "ResourceRecords": [ { "Value": "ns-1864.awsdns-41.co.uk" }, { "Value": "ns-1254.awsdns-28.org" }, { "Value": "ns-467.awsdns-58.com" }, { "Value": "ns-638.awsdns-15.net" } ] } } ] }
Note: Substitute ResourceRecordSet {Name} and the ResourceRecords {Values} with your own.
Creating a new hosted zone and changing resource record sets take time to propagate to the Amazon Route 53 DNS servers.
Checking the status of your changes...
aws route53 get-change --id <change-id>
aws route53 change-resource-record-sets \ --hosted-zone-id <zone-id> \ --change-batch file://r53-a-batch.json
r53 A batch file template:
{ "Comment": "Create a batch of A record sets", "Changes": [ { "Action": "CREATE", "ResourceRecordSet": { "Name": "host1.sub.mydomain.com", "Type": "A", "TTL": 300, "ResourceRecords": [ { "Value": "10.79.3.1" } ] } }, { "Action": "CREATE", "ResourceRecordSet": { "Name": "host2.sub.mydomain.com", "Type": "A", "TTL": 300, "ResourceRecords": [ { "Value": "10.79.3.2" } ] } }, ... ] }