A zone apex record is a DNS record at the root of a DNS zone, such as 'example.com. ' RFC 1034 states that the zone apex must be an A Record, and not a CNAME record. This means that the zone apex record must point to one or more IP addresses.
A CNAME cannot be placed at the root domain level, because the root domain is the DNS Start of Authority (SOA) which must point to an IP address. CNAME records must point to another domain name, never to an IP address.
A Canonical Name or CNAME record is a type of DNS record that maps an alias name to a true or canonical domain name. CNAME records are typically used to map a subdomain such as www or mail to the domain hosting that subdomain's content.
The apex (sometimes known as the zone apex or domain apex) refers to records where the record name is the same as the zone's domain name. In the zone for example.com, a record for example.com is said to be at the zone apex.
As per RFC1912 section 2.4:
A CNAME record is not allowed to coexist with any other data. In
other words, if suzy.podunk.xx is an alias for sue.podunk.xx, you
can't also have an MX record for suzy.podunk.edu, or an A record, or
even a TXT record. Especially do not try to combine CNAMEs and NS
records like this!:
podunk.xx. IN NS ns1
IN NS ns2
IN CNAME mary
mary IN A
The RFC makes perfect sense as the nameserver wouldn't know whether it needs to follow the CNAME or answer with the actual record the CNAME overlaps with. bar.com
is a zone therefore it implicitly has an SOA record for the bar.com
name. You can't have both a SOA record and a CNAME with the same name.
However, given that SOA records are generally used only for zone maintenance, these situations where you want to provide a CNAME at the zone's apex are quite common. Even though the RFC prohibits it, many engineers would like a behaviour such as: "follow the CNAME unless the query explicitly asks for the SOA record". That's why Route 53 provides alias records
. These are a Route 53 specific feature which offer the exact functionality you require. Have a look at http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/CreatingAliasRRSets.html
bar.com
. (The name must be the same as the domain you want to redirect from in order for this to work!)bar.com
S3 Bucket go to Properties
> Static Website Hosting
, select Redirect all requests to another host name
and enter foo.com
in the text box.Hosted Zone
for bar.com
, click Create Record Set
. Select A - IPv4 address
for type. Click Yes
for Alias
. Click the text box for Alias Target
. bar.com
should be listed under -- S3 Website Endpoints --
. Save the record. Wait a few minutes and you should have a redirect setup to redirect requests from bar.com to foo.com.You can use this same method to redirect a naked domain to a subdomain (like www). I use this in cases where www.foo.com has to be a CNAME so I redirect from foo.com to www.foo.com with this same method. If foo.com is an A record, you can use this technique to redirect from www.foo.com to foo.com.
NOTE: this method will forward with the full path. i.e. http://bar.com/test will forward to http://foo.com/test.
On Route53, You need to create an A record NOT a CNAME record, and create an alias under that.
From @ewalshe's comment on Alexandru Cucu's answer, if you came here trying to setup API Gateway with a custom domain name and have a Cloudfront distribution url.
Jonathan answer is correct. If you still confuse with his answer please take a look of this example.
tldr; You have to pass in an FQDN as the ResourceRecordSet name.
I had this same problem using this statement c# snip:
private static void RegisterHostWithDns(IAmazonRoute53 ec2,SynoviaImage image)
{
var changeBatch = new ChangeBatch();
var rRs = new ResourceRecordSet(image.Name, RRType.CNAME) {TTL=60,ResourceRecords = new List<ResourceRecord>() { new ResourceRecord(image.PublicDns)} };
var change = new Change(ChangeAction.UPSERT, rRs);
changeBatch.Changes.Add(change);
var request = new ChangeResourceRecordSetsRequest(ConfigurationManager.AppSettings["DnsZoneId"], changeBatch);
var response = ec2.ChangeResourceRecordSets(request);
Console.WriteLine("Updated CNAME For {0} setting {1}",image.Name,image.PublicDns);
}
In this case image.Name == "Listener"
Once I changed it to:
private static void RegisterHostWithDns(IAmazonRoute53 ec2,SynoviaImage image)
{
var changeBatch = new ChangeBatch();
var rRs = new ResourceRecordSet(string.Format("{0}.{1}",image.Name, "testing.foo.bar.com"), RRType.CNAME) {TTL=60,ResourceRecords = new List<ResourceRecord>() { new ResourceRecord(image.PublicDns)} };
var change = new Change(ChangeAction.UPSERT, rRs);
changeBatch.Changes.Add(change);
var request = new ChangeResourceRecordSetsRequest(ConfigurationManager.AppSettings["DnsZoneId"], changeBatch);
var response = ec2.ChangeResourceRecordSets(request);
Console.WriteLine("Updated CNAME For {0} setting {1}",image.Name,image.PublicDns);
}
now the value being passed in is: "Listener.fully.qualified.com"
It works now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With