How do I create alias records for services hosted in AWS?

Last updated: 2021-05-19

I am creating custom DNS records for services hosted on AWS. What type of alias record should I use?

Short description

Amazon Route 53 alias records are mapped internally to the DNS name of alias targets such as AWS resources. Route 53 monitors the IP address associated with an alias target's DNS name for scaling actions and software updates. The authoritative response from Route 53 name servers contains an A record (for IPv4 addresses) or AAAA record (for IPv6 addresses) with the IP address of the alias target.

Resolution

Create an alias record

Create your record using the Route 53 console and specify the necessary values for alias records.

Be sure to use the correct DNS record type for IP addresses in the service you're pointing to:

  • Amazon CloudFront distribution – A record (IPv4) or AAAA record (IPv6)
  • AWS Elastic Beanstalk environment – A record (IPv4)
  • Elastic Load Balancing (ELB) load balancer – A record (IPv4) or AAAA record (IPv6)
  • Amazon Simple Storage Service (Amazon S3) bucket – A record (IPv4)
  • Amazon API Gateway custom regional API and edge-optimized API – A record (IPv4)
  • Amazon VPC interface endpoint – A record (IPv4)
  • AWS Global Accelerator – A record (IPv4)
  • Another Route 53 record in the same hosted zone

Note: Some services require you to set up a custom DNS name before creating the record. These services include Amazon API Gateway and Amazon Cloudfront.

CNAME support

Route 53 follows the pointer in an alias record only if the record type matches. To create an alias record for a CNAME record, the alias target must resolve to a CNAME value.

Even if you create an invalid CNAME(ALIAS) record, Route 53 can't resolve the IP address of the endpoint. As a result, Route 53 returns an SERVFAIL/REFUSED RCODE error.

Valid CNAME(ALIAS) record:

Name Type Value
cname.example.com. CNAME(ALIAS) cname1.example.com.
cname1.example.com. CNAME abc.example.net.
abc.example.net. A 203.0.113.1

Invalid CNAME(ALIAS) record:

Name Type Value
cname.example.com.                                                CNAME(ALIAS)                                d12345xx.cloudfront.net.
cname.example.com. CNAME(ALIAS) dualstack.elb123.us-east 1.elb.amazonaws.com.
cname.example.com. CNAME(ALIAS) s3-website-us-west-2.amazonaws.com.
cname.example.com. CNAME(ALIAS) ebs1234.us-east-1.elasticbeanstalk.com.

Pointing from non-Route 53 DNS providers

If you use a DNS provider other than Route 53 for your domain name, then you might be able to point the domain to services hosted on AWS. Check if your DNS provider supports CNAME records on a root domain using techniques such as CNAME flattening, ANAME records, or WebHops redirection.

Considerations for creating CNAME records

1.    You can't create a CNAME record for the Parent, Naked, or Apex domain. With Route 53, you can use an alias record to point the parent domain to other supported alias targets.

For example, if you created a hosted zone for the domain "example.com", then you can't create the following CNAME record.

example.com CNAME dualstack.elb123.us-east 1.elb.amazonaws.com.

If you created a hosted zone for the domain "www.example.com", then you can't create the following CNAME record:

www.example.com CNAME dualstack.elb123.us-east 1.elb.amazonaws.com.

With Route 53, you can create an alias record instead. For example:

example.com Alias(A) dualstack.elb123.us-east 1.elb.amazonaws.com.

2.    CNAME records can't coexist with other record types for the same domain in the hosted zone file. For example, you can have only one record type for the domain "example.com" if the record type is CNAME. You can't create the following record:

abc.example.com CNAME www.example.com
abc.example.com A     54.239.28.85

3.    You can create a wildcard record that can coexist with the CNAME record. For example:

abc.example.com CNAME www.example.com
*.example.com   A     54.239.28.85