0
0
AWScloud~5 mins

Record types (A, AAAA, CNAME, Alias) in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you want to connect your website or app to the internet, you need to tell the internet where to find it. Record types like A, AAAA, CNAME, and Alias help map your domain name to the right place, like an IP address or another domain.
When you want your domain name to point to a server's IPv4 address using an A record.
When you want your domain name to point to a server's IPv6 address using an AAAA record.
When you want your domain name to point to another domain name using a CNAME record.
When you want to point your domain to AWS resources like CloudFront or an Elastic Load Balancer using an Alias record.
Config File - route53-records.json
route53-records.json
{
  "Comment": "Create records for example.com",
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "example.com.",
        "Type": "A",
        "TTL": 300,
        "ResourceRecords": [
          {"Value": "192.0.2.1"}
        ]
      }
    },
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "example.com.",
        "Type": "AAAA",
        "TTL": 300,
        "ResourceRecords": [
          {"Value": "2001:db8:85a3::8a2e:370:7334"}
        ]
      }
    },
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "www.example.com.",
        "Type": "CNAME",
        "TTL": 300,
        "ResourceRecords": [
          {"Value": "example.com."}
        ]
      }
    },
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "alias.example.com.",
        "Type": "A",
        "AliasTarget": {
          "HostedZoneId": "Z2FDTNDATAQYW2",
          "DNSName": "d123.cloudfront.net.",
          "EvaluateTargetHealth": false
        }
      }
    }
  ]
}

This JSON file is used with AWS Route 53 to create DNS records.

  • A record: Points example.com to an IPv4 address.
  • AAAA record: Points example.com to an IPv6 address.
  • CNAME record: Points www.example.com to example.com.
  • Alias record: Points alias.example.com to an AWS CloudFront distribution using its DNS name and hosted zone ID.
Commands
This command applies the DNS record changes defined in the JSON file to the specified hosted zone in Route 53.
Terminal
aws route53 change-resource-record-sets --hosted-zone-id Z3P5QSUBK4POTI --change-batch file://route53-records.json
Expected OutputExpected
{ "ChangeInfo": { "Id": "/change/C2682N5HXP0BZ4", "Status": "PENDING", "SubmittedAt": "2024-06-01T12:00:00Z", "Comment": "Create records for example.com" } }
--hosted-zone-id - Specifies the Route 53 hosted zone where the records will be created.
--change-batch - Specifies the JSON file with the record changes.
This command lists all DNS records in the hosted zone to verify that the new records were created successfully.
Terminal
aws route53 list-resource-record-sets --hosted-zone-id Z3P5QSUBK4POTI
Expected OutputExpected
{ "ResourceRecordSets": [ { "Name": "example.com.", "Type": "A", "TTL": 300, "ResourceRecords": [ {"Value": "192.0.2.1"} ] }, { "Name": "example.com.", "Type": "AAAA", "TTL": 300, "ResourceRecords": [ {"Value": "2001:db8:85a3::8a2e:370:7334"} ] }, { "Name": "www.example.com.", "Type": "CNAME", "TTL": 300, "ResourceRecords": [ {"Value": "example.com."} ] }, { "Name": "alias.example.com.", "Type": "A", "AliasTarget": { "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": "d123.cloudfront.net.", "EvaluateTargetHealth": false } } ] }
--hosted-zone-id - Specifies the hosted zone to list records from.
Key Concept

If you remember nothing else from this pattern, remember: DNS record types tell the internet how to find your domain, whether by IP address, another domain, or AWS resources.

Common Mistakes
Using a CNAME record for the root domain (example.com) instead of a CNAME for subdomains.
DNS standards do not allow CNAME records at the root domain, which can cause resolution failures.
Use A or Alias records for the root domain and CNAME records only for subdomains like www.
Setting TTL too low or too high without understanding impact.
Too low TTL causes excessive DNS queries; too high delays updates propagation.
Use a balanced TTL like 300 seconds for typical use.
Not using Alias records for AWS resources like CloudFront or ELB.
Alias records allow AWS to manage IP changes automatically; without them, your DNS may break if IPs change.
Use Alias records pointing to AWS resource DNS names with correct hosted zone IDs.
Summary
Create DNS records using a JSON file with A, AAAA, CNAME, and Alias types for different purposes.
Apply the DNS changes to Route 53 using the AWS CLI change-resource-record-sets command.
Verify the records were created correctly by listing them with the AWS CLI.