Route 53 Subdomains

toddm92 edited this page Dec 21, 2014 · 35 revisions

Creating a R53 Subdomain

Used in the examples:

Parent domain: mydomain.com.
Subdomain:     sub.mydomain.com.

Summary Steps (From the AWS Console)

Create a new subdomain zone...

  1. In the Amazon Route 53 console, click Create Hosted Zone.
  2. In the right pane, enter the domain name; sub.mydomain.com and a comment (optional).
  3. Below the right pane, click Create.
  4. 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.

  1. In the AWS Route 53 console, click Go to Record Sets.
  2. Click Create Record Set.
  3. In the right pane, enter the zone name; sub.mydomain.com.
  4. The type should be NS.
  5. In the value field, enter the name servers from the last step above.
  6. Below the right pane, click Create.
  7. 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>

Populating a Zone With Basic Record Sets

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"
          }
        ]
      }
    },
    ...
  ]
}