Route 53 — Configuring Type and CNAME Records in AWS CLI

Prasad
3 min readJun 2, 2023

--

DNS (Domain Name System) records are like the phone book of the internet. They serve as a crucial component of the internet infrastructure, translating human-readable domain names (e.g., www.example.com) into machine-readable IP addresses (e.g., 000.000.0.1) that computers and servers understand.

DNS records are instructions that tell the internet how to find and connect to specific resources associated with a domain name. These records are stored on DNS servers and help route incoming requests to the appropriate destination.

Amazon Web Services (AWS) offers a convenient command-line interface (CLI) that allows users to configure DNS records, including Type and CNAME records.

DNS records and their basic functionalities:

A (Address) Record: Associates a domain name with an IPv4 address. It enables users to reach a specific web server or website.

AAAA (IPv6 Address) Record: Similar to an A record, but associates a domain name with an IPv6 address. It allows for the use of the newer IPv6 protocol.IPv6 provides a larger address space to accommodate the growing number of internet-connected devices and offers improvements in security and network configuration compared to IPv4. IPv6 e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334 IPv4 : 192.168.0.1

CNAME (Canonical Name) Record: Creates an alias for a domain or subdomain. It points the domain to another domain or subdomain, enabling you to redirect traffic to a different location easily.

MX (Mail Exchanger) Record: Specifies the mail server responsible for handling email delivery for a domain. It directs incoming emails to the appropriate mail server.

TXT (Text) Record: Stores text-based information related to a domain. It is commonly used for domain verification, SPF (Sender Policy Framework) records for email authentication, and other purposes.

NS (Name Server) Record: Indicates the authoritative DNS servers responsible for a domain. It specifies the DNS servers that hold the official records for a particular domain.

In this article, we will explore how to set up and manage Arecord and CNAME using the AWS CLI. Additionally, we will discuss the benefits of leveraging these record types in your AWS environment.

To create a Type record, use the change-resource-record-sets command of the route53 AWS CLI command group. Here's an example command:

aws route53 change-resource-record-sets \
--hosted-zone-id <your-hosted-zone-id> \
--change-batch '{"Changes":[{"Action":"CREATE","ResourceRecordSet":{"Name":"example.com.","Type":"A","TTL":300,"ResourceRecords":[{"Value":"<IPv4 address>"}]}}]}'
aws route53 change-resource-record-sets \
--hosted-zone-id <your-hosted-zone-id> \
--change-batch '{"Changes":[{"Action":"UPSERT","ResourceRecordSet":{"Name":"example.com.","Type":"A","TTL":300,"ResourceRecords":[{"Value":"<new-IPv4-address>"}]}}]}'

Similar to Type records, CNAME records can be managed using the change-resource-record-sets command. Here's an example command:

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

To update a CNAME record using the AWS CLI, you can utilize the change-resource-record-sets command from the route53 AWS CLI command group. Here's an example command:

aws route53 change-resource-record-sets \
--hosted-zone-id <your-hosted-zone-id> \
--change-batch '{"Changes":[{"Action":"UPSERT","ResourceRecordSet":{"Name":"www.example.com.","Type":"CNAME","TTL":300,"ResourceRecords":[{"Value":"new.example.com."}]}}]}'

Replace <your-hosted-zone-id> with your actual hosted zone ID, and specify the new CNAME value in place of new.example.com.. The UPSERT action will either create a new CNAME record if it doesn't exist or update the existing record if it does.

Execute the command, and upon successful execution, the CNAME record will be updated in your DNS configuration, pointing the specified domain to the new target.

Please note that DNS record propagation can take some time, typically ranging from a few minutes to several hours, depending on various factors such as TTL settings and DNS caching. It’s recommended to allow sufficient time for the changes to propagate across the DNS network.

Benefits :

  1. Easy Maintenance: With CNAME records, you can create aliases for your domains, making it simpler to manage changes or updates. Instead of modifying multiple records, you can update the target of the CNAME record, and the changes will propagate automatically.
  2. High Availability: By leveraging Type records, you can distribute traffic across multiple resources using various routing policies, including weighted, failover, geolocation, and latency-based routing. This ensures high availability and improves the performance of your applications.
  3. Scalability: With AWS CLI, you can automate the creation and management of Type and CNAME records, allowing for easy scalability as your infrastructure grows. This helps streamline the DNS management process and reduces the chances of human error.
Quick Comparision

--

--

Prasad
Prasad

Written by Prasad

I am a OpenSource Enthusiast|Python Lover who attempts to find simple explanations for questions and share them with others

No responses yet