Bootstrap FreeKB - Amazon Web Services (AWS) - Route 53 Alias records
Amazon Web Services (AWS) - Route 53 Alias records


This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.

Route 53 is Amazon Web Services DNS.

  • An A record can be used to:
    • Route requests from a DNS name to an IPv4 address (for example, from www.example.com to 10.11.12.13)
  • An A Alias record (this article) can be used to:
    • Route requests from your Hosted Zone base DNS name to a subdomain, for example from example.com to www.example.com (This can't be done with a CNAME record)
    • Route requests from subdomain "a" to subdomain "b", for example, from foo.example.com to bar.example.com (This can also be done with a CNAME record)
    • Route requests to a AWS service, such as an Elastic Load Balancer or CloudFront Distribution or API Gateway
  • CNAME (canonical name) record is used to
    • Route requests from subdomain "a" to subdomain "b", for example, from foo.example.com to bar.example.com (This can also be done with an A Alias record)

For example, let's say you have a Route 53 Hosted Zone for example.com. The aws route53 list-hosted-zones command can be used to list your Hosted Zones.

~]$ aws route53 list-hosted-zones
{
    "HostedZones": [
        {
            "Id": "/hostedzone/Z056866DJM1OE9C45GH42",
            "Name": "sample.com.",
            "CallerReference": "RISWorkflow-RD:98abdc50-5adf-1234-abdc-471041234a6c",
            "Config": {
                "Comment": "HostedZone created by Route53 Registrar",
                "PrivateZone": false
            },
            "ResourceRecordSetCount": 3
        }
    ]
}

 

Here is an example of how you could create an A record that forwards requests from foo.example.com to 10.11.12.13.

aws route53 change-resource-record-sets \
--hosted-zone-id Z056866DJM1OE9C45GH42 \
--change-batch '{ "Changes": [ { "Action": "CREATE", "ResourceRecordSet": { "Name": "foo.example.com", "Type": "CNAME", "TTL": 300, "ResourceRecords": [ { "Value": "10.11.12.13" } ] } } ] }'

 

nslookup should now resolve foo.example.com to IP 10.11.12.13.

~]$ nslookup www.freekb.link
Server:         172.31.0.2
Address:        172.31.0.2#53

Non-authoritative answer:
Name:   foo.example.com
Address: 10.11.12.13

 

Then going to foo.example.com should bring up whatever is being served on IP address 10.11.12.13.

 

An Alias record can then be created to forward requests from bar.example.com to foo.example.com.

aws route53 change-resource-record-sets \
--hosted-zone-id Z056866DJM1OE9C45GH42 \
--change-batch '{ "Changes": [ { "Action": "CREATE", "ResourceRecordSet": { "AliasTarget": { "HostedZoneId": "Z056866DJM1OE9C45GH42", "EvaluateTargetHealth": true, "DNSName": "foo.example.com." }, "Type": "A", "Name": "bar.example.com." } } ] }'

 

nslookup should now resolve both foo.example.com and bar.example.com to IP 10.11.12.13.

~]$ nslookup bar.example.com
Server:         172.31.0.2
Address:        172.31.0.2#53

Non-authoritative answer:
Name:   bar.example.com
Address: 10.11.12.13

 

And going to foo.example.com or bar.example.com should bring up whatever is being served on IP address 10.11.12.13.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 1d3509 in the box below so that we can be sure you are a human.