Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointing Amazon's CloudFront at an A record not a CNAME

I've found instructions to point my domain's CNAME to Amazon's CloudFront service but ideally I would like to point the root name (A record name). For example, foo.com instead of www.foo.com. Is this possible?

like image 333
git-noob Avatar asked Jun 01 '10 15:06

git-noob


People also ask

How do I point CNAME to CloudFront?

To add an alternate domain name (CNAME) to a CloudFront distribution, you must attach to your distribution a trusted, valid SSL/TLS certificate that covers the alternate domain name. This ensures that only people with access to your domain's certificate can associate with CloudFront a CNAME related to your domain.

Can I use CloudFront as an A record with Route 53?

Route 53 is a DNS service whereas Cloudfront is CDN service to serve static (and dynamic) content. You can use the cloudfront with Route 53 Geolocation Routing .

What is the difference between an A record and a CNAME?

An A Record maps a hostname to one or more IP addresses, while the CNAME record maps a hostname to another hostname.

How do I make a record with CloudFront?

Sign in to the AWS Management Console and open the Route 53 console at https://console.aws.amazon.com/route53/ . In the navigation pane, choose Hosted zones. Choose the linked name of the hosted zone for the domain that you want to use to route traffic to your CloudFront distribution. Choose Create record.


Video Answer


2 Answers

You can point the zone apex (i.e. example.com) to a CloudFront distribution on AWS using their Route 53 service. Just log into your CloudFront distribution and set the Alternate Domain Names (CNAMEs) to your domain (e.g. example.com and/or www.example.com). Then in Route 53, create a hosted zone for your domain, and then an alias record selecting the CloudFront distribution as the destination. You can also create a second alias record for any sub-domains, such as www.example.com. Note: you'll need to change the name servers with your domain registrar too.

From the Route 53 FAQs:

Q. Can I point my zone apex (example.com versus www.example.com) at my Amazon CloudFront distribution?

Yes. Amazon Route 53 offers a special type of record called an ‘Alias’ record that lets you map your zone apex (example.com) DNS name to your Amazon CloudFront distribution (for example, d123.cloudfront.net). IP addresses associated with Amazon CloudFront endpoints vary based on your end user’s location (in order to direct the end user to the nearest CloudFront edge location) and can change at any time due to scaling up, scaling down, or software updates. Route 53 responds to each request for an Alias record with the IP address(es) for the distribution. Route 53 doesn't charge for queries to Alias records that are mapped to a CloudFront distribution. These queries are listed as “Intra-AWS-DNS-Queries” on the Amazon Route 53 usage report.

For more information, see AWSs documentation:

  • Route 53: Routing Queries to an Amazon CloudFront Distribution
  • Route 53: Creating Alias Resource Record Sets
like image 145
TravisCannon Avatar answered Oct 21 '22 07:10

TravisCannon


Pointing www.example.com can still be done with an A-record, but you have to point it to an IP address then, it has nothing to do with the "www" or anything else in front or not.

The difference between CNAMEs and A-Records is only that a CNAME points to another name, which must in turn be looked up by the DNS, whereas an A-record only requires one lookup and is pointed directly to an IP address.

That said, you quickly understand why using A-records with this type of cloud hosting might be a bad idea or impossible. Amazon uses several IP addresses and you won't know up front what IP addresses these are. DNS changes are slow. So, unless you have a specific IP address that does not change, using an A-record simply will not work. Find a hosting offer with a fixed IP address and you can use A-records.

In terms of performance or reachability, there's only a marginal difference between CNAME and A-records.

EDIT:
As SLaks points out, it seems best to stick to "old rules" to use an A-Record for your root domain name. But you'll find that sometimes you will not have a choice, depending on what your hosting provider allows you to do. Luckily, nowadays, there's little if anything that should practically withhold you from doing so (using CNAME).

like image 45
Abel Avatar answered Oct 21 '22 09:10

Abel