Amazon CloudFront
Developer Guide (API Version 2010-11-01)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Using CNAMEs

What Is a CNAME?

A CNAME record is an entry in a DNS table that lets you alias one fully qualified domain name to another. For example, if you owned www.beagles.com and beagles.dogs.com, you could create the following CNAME record that would specify www.beagles.com as an alias for beagles.dogs.com.

www.beagles.com CNAME beagles.dogs.com

A CNAME is useful because it lets you choose a domain name for your links instead of the domain name CloudFront provides you. Download and streaming distributions support CNAMEs.

[Important]Important

You must be the owner of any domain name that you specify as an alias of your distribution's domain name.

You create a distribution, and CloudFront returns d604721fxaaqy9.cloudfront.net as the distribution's domain name. The link you would create to your object called images/image.jpg would be http://d604721fxaaqy9.cloudfront.net/images/image.jpg.

However, you want your links to use example.com instead of the cloudfront.net domain name that CloudFront provided. So you want the link to images/image.jpg to be http://example.com/images/image.jpg instead of http://d604721fxaaqy9.cloudfront.net/images/image.jpg.

[Note]Note

CloudFront doesn't support CNAMEs with HTTPS. If content is requested over HTTPS using CNAMEs, your end users' browsers will display the warning: This page contains both secure and non-secure items. To prevent this message from appearing, don't use CNAMEs with CloudFront HTTPS distributions.

Setting Up a CNAME Alias

The following figure and table describe the process for setting up a CNAME alias so you can use your own domain name in your links instead of your distribution's CloudFront domain name.

Basic flow for updating a distribution

Process for Setting Up a CNAME Alias

1

Update your distribution's configuration to include the CNAME alias (using the CNAME element in the DistributionConfig (or StreamingDistributionConfig) object).

If you're adding another CNAME alias to a distribution that already has one, see Multiple CNAME Aliases.

For information about distribution configuration and updating a distribution, see Updating a Distribution's Configuration, and go to DistributionConfig Complex Type in the Amazon CloudFront API Reference. For more information about streaming distributions, go to StreamingDistributionConfig Complex Type in the Amazon CloudFront API Reference.

2

Confirm your update in task 1 is fully deployed.

The update is fully deployed after the distribution's status returns to Deployed. If you don't wait for the update to be deployed, the links you create in the following steps might not work. For information about getting a distribution's status, go to GET Distribution Config in the Amazon CloudFront API Reference. For more information about streaming distributions, go to GET Streaming Distribution Config in the Amazon CloudFront API Reference.

3

Create a CNAME record in the DNS system to establish the alias between your domain name and the CloudFront domain name for your distribution.

The exact procedure for configuring DNS depends on your DNS server or DNS provider and is beyond the scope of this document.

[Important]Important

If you already have an existing CNAME record for your domain name, make sure you update that record or replace it with a new one that points to your distribution's domain name.

Also, make sure your CNAME record points to your distribution's domain name, and not your origin server.

4

Confirm in the DNS system that the CNAME record points to your distribution's domain name.

Use a DNS tool like dig (for information about dig, go to http://www.kloth.net/services/dig.php). The following shows an example dig request on a domain name called images.yourdomain.com, and the relevant part of the response.

[prompt]> dig images.yourdomain.com
									
; <<> DiG 9.3.3rc2 <<> images.yourdomain.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15917
;; flags: qr rd ra; QUERY: 1, ANSWER: 9, AUTHORITY: 2, ADDITIONAL: 0

;; QUESTION SECTION:
;images.yourdomain.com.     IN    A
									
;; ANSWER SECTION:
images.yourdomain.com. 10800 IN  CNAME  d604721fxaaqy9.cloudfront.net.
...
...

The line in the Answer Section shows the CNAME alias between the domain name images.yourdomain.com and the CloudFront distribution domain name d604721fxaaqy9.cloudfront.net. The CNAME record for your domain name is set up correctly if the name on the right side of CNAME in that line is your CloudFront distribution's domain name. If it's your Amazon S3 origin server bucket or some other domain name, then the CNAME record is set up incorrectly. In that case, go back to task 3 and correct the CNAME record to point to your distribution's domain name.

5

Test the CNAME alias.

Create some test links that use your domain name in the URL instead of the distribution's CloudFront domain name. Test those links to confirm your content is being served correctly with the CNAME alias.

6

Go live with the CNAME alias.

Substitute your domain name for the distribution's CloudFront domain name in your live links to objects.


Multiple CNAME Aliases

You can use more than one CNAME alias with a distribution. For example, you could have alias1.example.com and alias2.example.com both associated with your distribution's domain name. You can have up to 10 CNAME aliases per distribution. You can associate a particular CNAME alias with only one distribution.

[Important]Important

When adding an additional CNAME alias to a distribution that already has one, make sure to include the original CNAME alias in the DistributionConfig object. Otherwise, your update erases the original CNAME alias and just adds the new one. This is because the process of updating a distribution's configuration replaces the entire configuration object; it doesn't add new items to it.

No CNAME vs. an Empty CNAME

In a distribution's configuration, the lack of a CNAME element is not equivalent to an empty CNAME element (<CNAME/>). If you don't want the distribution to have a CNAME, then don't include a CNAME element when you create the distribution or update its configuration. If you do, CloudFront returns a MalformedXML error (for more information about errors, go to Errors in the Amazon CloudFront API Reference). The following table shows a correct and incorrect configuration object for a distribution with no CNAMEs. For more information about the configuration object, go to DistributionConfig Complex Type in the Amazon CloudFront API Reference.

Correct

<?xml version="1.0" encoding="UTF-8"?>
<DistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/">
   <S3Origin>
      <DNSName>mybucket.s3.amazonaws.com</DNSName>
   </S3Origin>   
   <CallerReference>20091130090000</CallerReference>
   <Comment>My comments</Comment>
   <Enabled>true</Enabled>
</DistributionConfig>

Incorrect

<?xml version="1.0" encoding="UTF-8"?>
<DistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/">
   <S3Origin>
      <DNSName>mybucket.s3.amazonaws.com</DNSName>
   </S3Origin>   
   <CallerReference>20091130090000</CallerReference>
   <CNAME/>
   <Comment>My comments</Comment>
   <Enabled>true</Enabled>
</DistributionConfig>

To remove a CNAME from a distribution, remove the corresponding CNAME element and update the configuration. For information about updating a distribution's configuration, see Updating a Distribution's Configuration.