51

As Amazon Route 53 allows you to set an A record or a CNAME to a different sub-domain name using Alias, I am wondering what is the difference between A record and CNAME now.

To clarify my question, the difference between CNAME and A record in a traditional NameServer is that only CNAME can be used to point to a different subdomain and A record must point to a valid IP address. Since the AWS Route53 allows you to do use a subdomain with either A Rec or CNAME .. does it not blur the distinction between the two.

Scalable
  • 1,550
  • 4
  • 16
  • 29

2 Answers2

99

Your question is quite valid, but you are using the word "subdomain" in a not-quite-precise way.

What you are actually asking is about the fact that an Route 53, an A record can give the appearance of referencing either a fully-qualified hostname from another domain, or a hostname or subdomain from its own domain, while in proper DNS, the only way to reference another hostname is with a CNAME, yet those can't be provisioned at the apex of a domain ("example.com") pointing to a subdomain ("www.example.com").

An alias, you're saying, seems to be functionally equivalent but more flexible than a CNAME so is there a difference?

The difference between a CNAME and an alias is that a CNAME is still a proper, standard, ordinary DNS CNAME, which returns a DNS query response "hi, you need to know that the real ("canonical") name of the server you are looking for is 'x'" and, depending on circumstances, may also include the A record for the target host or may not, requiring the client to go for a second lookup.

Aliases, on the other hand, are a clever hack created by Amazon which does not break the protocol yet allows Route 53 to hand out the A record directly from resource "X" when the A record for resource "Y" is requested. Aliases can also reference other record types, but the record type they reference must be the same and for the purposes of this discussion, I am talking about A record aliases.

And, the important take-away here is that an alias actually returns an A record -- not a reference to the target, like a CNAME does.

The catch is that with an alias, you cannot put just any hostname in that box. It has to be a hostname within a domain where Route 53 has the magical hooks so that it can retrieve the apprpriate A record to serve up -- either another entry in your zone, or from S3, ELB, or Cloudfront. This is a very different implementation than how CNAME records work, even though the net effect appears to be the same.

Put anything else in there, and The record set could not be saved because:- Alias Target contains an invalid value. Try it. :)

Of course, CNAME records have no limitation like that... they're just limited by design in their use at the top of a zone.

So, in fact, Aliases and CNAME records do not have as much overlap as you may have initially thought. In some situations, only one is usable, and cases where either one would work, the difference is probably insignificant.

One advantage of Alias in the case where either one could be used is that an alias never requires 2 DNS queries, as I mentioned above. It is always answered directly by Route 53 with the appropriate A record, where a CNAME, at least in the case where it references a hostname in a different top level domain, can require two sequential DNS lookups, giving Alias a theoretical performance advantage in that case.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
  • 2
    wow - thanks for such detailed answer. My understanding improved many fold with this. – Scalable Jun 20 '13 at 20:52
  • 1
    Excellent. Please consider accepting my answer unless there are any other points you would like me to clarify. – Michael - sqlbot Jun 20 '13 at 21:19
  • 2
    Just to add a little bit of confusion, you can have 'alias cnames'. If you wanted cdn1.website.com, cdn2.website.com and cdn3.website.com all to point to the same 3rd party domain, you could alias cname them to cdn.website.com, which would be a cname to website.bestcdn.com. The advantage here is that rather than 2 cname lookups (few ms delay in content loading), there is only one, and there is only one record to update, if the cdn changes. If you are going to ask about why use multiple cdn urls to the same plce? This is a trick sometimes used to increase concurrent asset downloads. – KHobbits Feb 04 '17 at 03:44
  • @KHobbits Agreed. The CNAME entry is pretty much essential if you are using a third party, say for some reason lobs.domain.ext is on google cloud storage, these providers may prefer/require CNAME to be used. – mckenzm Mar 27 '17 at 01:25
  • 1
    @mckenzm true. This answer was really focused on `A` record aliases, the typical way in which Alias records are used, but you can create an `AAAA` or `CNAME` Alias, or -- apparently -- an Alias for [any type of record](http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resource-record-sets-values-alias.html#rrsets-values-alias-type) other than `NS` or `SOA` if referencing another record within your own hosted zone. – Michael - sqlbot Mar 27 '17 at 01:37
1

I think you have wrong information. Amazon Route53 doesn't allow A records with subdomains. When I'm trying to set it to a domain name I'm getting an error:

The record set could not be saved because:
- The Value field contains invalid characters or is in an invalid format.

A records are for IP addresses only.

yegor256
  • 102,010
  • 123
  • 446
  • 597
  • 1
    Thanks yegor256 for your response - however you should try this : Set Alias: Yes that will enable a text box below labelled "Alias Target" .. in which you can put a subdomain .. I generally put a loadbalancer fqdn there. So I think my question is pretty valid. – Scalable Jun 19 '13 at 22:19
  • Alias are still appropriately `A` or `CNAME` records under the covers. All they do is map DNS resolution to to other services. – datasage Jun 19 '13 at 23:52