logo
Published on

Route 53 Record Types

Authors
  • avatar
    Name
    Bowen Y
    Twitter

QUESTION

Use A records or CNAME records for my CloudFront distribution?

ANSWER

You can create both A records and CNAME records for your CloudFront distribution, but there are specific conditions and contexts in which you would choose one over the other.

CNAME Records: A CNAME record is used to map an alias name to a true or canonical domain name. When you use a CNAME record, the DNS query is redirected to the canonical name. CNAME records are typically used for subdomains like www.example.com or store.example.com. You would create a CNAME record if you want your custom subdomain to point to your CloudFront distribution's domain name (e.g., d1234.cloudfront.net).

A Records: An A record maps a domain name to its corresponding IPv4 IP address. Traditionally, A records are used for root domains (e.g., example.com without the 'www') because you cannot have a CNAME record at the zone apex (the root level of the domain). However, services like AWS Route 53 have a feature called "Alias" records, which are a type of A record that can point to AWS resources such as CloudFront distributions or S3 buckets. Alias records provide the functionality of a CNAME record for the zone apex.

There are some key reasons to use an Alias record in AWS, especially for CloudFront:

Zone Apex: As mentioned, you can't use a CNAME for your root domain. If you need to point your root domain (e.g., example.com) to your CloudFront distribution, you must use an A record with Alias functionality.

DNS Query Charges: AWS does not charge for DNS queries to Alias records that point to AWS resources, while there might be charges for CNAME record queries.

Performance: Alias records can provide better performance because they resolve to the most geographically appropriate IP addresses for your AWS resources, like your CloudFront distribution.

Management: Alias records are AWS-native, meaning they can be easily managed within the AWS ecosystem and are aware of changes in your AWS resources.

QUESTION

Why is it possible to use an 'A' record, which is traditionally used to point a domain to an IPv4 address, to redirect a domain to a CloudFront URL?

ANSWER

The ability to use an 'A' record to point a domain to a CloudFront URL is made possible by a special type of DNS record offered by AWS Route 53 called an Alias record. An Alias record is a variant of the traditional 'A' record that allows you to point your domain to AWS resources, such as an Elastic Load Balancer, an S3 bucket, or a CloudFront distribution, which do not have a static IP address.

Here’s why this works:

Alias Records: When you create an 'A' record as an Alias in AWS Route 53, it functions like a 'CNAME' record in that it can point to a DNS name (like a CloudFront distribution’s domain name), not just an IP address. However, it still retains some properties of an 'A' record, such as working at the zone apex (the root domain).

Dynamic Resolution: Alias records are resolved dynamically by Route 53. When a user queries your domain, Route 53 automatically recognizes the CloudFront distribution and routes the query to the appropriate CloudFront edge location. Thus, even though CloudFront uses a network of edge locations and does not have a single IP address, the Alias 'A' record can point to the service seamlessly.

AWS Integration: Alias records are a feature specific to AWS Route 53 and are designed to integrate smoothly with other AWS services. This integration allows for the dynamic resolution capability and is not something that traditional DNS services can provide with standard 'A' records.

This feature is particularly useful because it allows domain owners to use their root domain (e.g., example.com) with CloudFront, which would not be possible with a standard 'CNAME' record, as 'CNAME' records are not valid for root domains according to DNS standards.