Alias cname record for zone apex

amazon-route53amazon-web-services

I am going to redirect example.com to www.example.com.
I have several records now.

example.com A 1.2.3.4
example.com NS "there are ns values"
example.com SOA "SOA value"
www.example.com CNAME mydom.example.com
mydom.example.com A 5.6.7.8

I try to change "example.com A 1.2.3.4" to cname alias record, that point to www.example.com.
I get message "[RRSet of type CNAME with DNS name example.com. is not permitted as it conflicts with other records with the same DNS name in zone example.com.]"

I try to delete "example.com A 1.2.3.4" and create the new "example.com CNAME(alias) www.example.com" but I again get message "[RRSet of type CNAME with DNS name example.com. is not permitted as it conflicts with other records with the same DNS name in zone example.com.]"

How can I create cname alias record with the name that the same as zone apex?

Best Answer

CNAME is never allowed at the apex of a zone, so that is the immediate cause of this failure, but that is somewhat unimportant, because for what you are doing, a CNAME isn't the correct record type.

If you have the record www.example.com A 203.0.113.1 and you want example.com to always return the same answer as www.example.com (currently 203.0.113.1 but you of course automatically updated if www changes in the future) then the example.com record would need to be type A with Alias = Yes and the alias target set to www.example.com.

This is exactly the same as just setting both hostnames to be normal A records and giving them the same value for IP address, except that changing one doesn't automatically change the other if you do them both manually, so having one of them as an alias for the other is usually preferrable.

The confuaion probably comes from a long-standing practice of doing something like this:

example com     A     203.0.113.1
www.example.com CNAME example.com.

This in less efficient since some lookups require twice the round trip time, so the alias approach is still preferred.

An Alias is a better solution, since it's an internal pointer to another record inside Route 53 whereas a CNAME is (in the sense relevant here) an external pointer to another record which could be anywhere. Aliases always point to the same type of record, A to A, AAAA to AAAA, CNAME to CNAME, so even if you had been allowed to create that invalid CNAME at the apex, the next problem would have been that the target of the alias wasn't a CNAME.