Routing traffic to an Amazon CloudFront distribution by using your domain name
You can use Amazon CloudFront, the AWS content delivery network (CDN), as one way to speed up delivery of your web content. CloudFront can deliver your entire website—including dynamic, static, streaming, and interactive content—by using a global network of edge locations. Users who request your content are automatically routed to the edge location that gives them the lowest latency.
Note
You can route traffic to a CloudFront distribution only for public hosted zones.
To use CloudFront to distribute your website content, create a distribution and specify settings for it. For example, specify the Amazon S3 bucket or HTTP server that you want CloudFront to get your content from, whether you want only selected users to have access to your content, and whether you want users to use HTTPS.
When you create a distribution, CloudFront assigns a domain name to the distribution, such as d111111abcdef8.cloudfront.net. You can use this domain name in the URLs for your content, for example:
http://d111111abcdef8.cloudfront.net/logo.jpg
Alternatively, you can use your own domain name in URLs, for example:
http://example.com/logo.jpg
Follow the steps in the Amazon CloudFront Developer Guide to use your own domain name in your files' URLs in a CloudFront distribution, instead of the domain name that CloudFront assigns to your distribution. For more information, about using your own domain name with a CloudFront distribution, see Using custom URLs by adding alternate domain names (CNAMEs).
When you use a Route 53 domain name with a CloudFront distribution, use Amazon Route 53 to create an alias record that points to your CloudFront distribution. An alias record is a Route 53 extension to DNS. It's similar to a CNAME record, but you can create an alias record both for the root domain, such as example.com, and for subdomains, such as www.example.com. (You can create CNAME records only for subdomains.) When Route 53 receives a DNS query that matches the name and type of an alias record, Route 53 responds with the domain name that is associated with your distribution.
Note
Route 53 doesn't charge for alias queries to CloudFront distributions or other AWS resources.
Prerequisites
To get started, you need the following:
A registered domain name. You can use Amazon Route 53 as your domain registrar or you can use a different registrar.
Route 53 as the DNS service for the domain. If you register your domain name by using Route 53, we automatically configure Route 53 as the DNS service for the domain.
For information about using Route 53 as the DNS service provider for your domain, see Making Amazon Route 53 the DNS service for an existing domain.
Request a public certificate so that Amazon CloudFront distributions require HTTPS. For more information, see Step 2: Request a public certificate and DNS validation in the AWS Certificate Manager in the AWS Certificate Manager User Guide.
-
A CloudFront distribution. The distribution must include an alternate domain name that matches the domain name that you want to use for your URLs instead of the domain name that CloudFront assigned to your distribution.
For example, if you want the URLs for your content to contain the domain name example.com, the Alternate Domain Name field for the distribution must include example.com.
For more information, see the following documentation in the Amazon CloudFront Developer Guide:
Configuring Amazon Route 53 to route traffic to a CloudFront distribution
To configure Amazon Route 53 to route traffic to a CloudFront distribution, follow these steps. For more information about using your own domain name with a CloudFront distribution, see Using custom URLs by adding alternate domain names (CNAMEs) in the Amazon CloudFront Developer Guide.
Note
Changes generally propagate to all Route 53 servers within 60 seconds. When the changes propagate, you'll be able to route traffic to your CloudFront distribution by using the name of the alias record that you create in this procedure.
To route traffic to a CloudFront distribution
-
Get the domain name that CloudFront assigned to your distribution and determine whether IPv6 is enabled:
Sign in to the AWS Management Console and open the CloudFront console at https://console.aws.amazon.com/cloudfront/v4/home
. -
in the ID column, select the linked name of the distribution that you want to route traffic to (not the check box).
-
On the General tab, get the value of the Distribution domain name field.
-
On the General tab, in the Settings section, choose edit and scroll to check the IPv6 field to see whether IPv6 is enabled for the distribution. If IPv6 is enabled, you'll need to create two alias records for the distribution, one to route IPv4 traffic to the distribution, and one to route IPv6 traffic. Choose Cancel.
For more information, see Enable IPv6 in the topic Values that you specify when you create or update a distribution in the Amazon CloudFront Developer Guide.
Sign in to the AWS Management Console and open the Route 53 console at https://console.aws.amazon.com/route53/
. -
In the navigation pane, choose Hosted zones.
-
Choose the linked name of the hosted zone for the domain that you want to use to route traffic to your CloudFront distribution.
-
Choose Create record.
You can use the wizard to create the records or choose Switch to quick create.
-
Specify the following values:
- Routing policy
-
Choose the applicable routing policy. For more information, see Choosing a routing policy.
- Record name
-
Enter the domain name that you want to use to route traffic to your CloudFront distribution. The default value is the name of the hosted zone.
For example, if the name of the hosted zone is example.com and you want to use acme.example.com to route traffic to your distribution, enter acme.
- Alias
-
If you are using the Quick create record creation method, turn on Alias.
Important
You must create an Alias record for the CloudFront distribution to work.
- Value/Route traffic to
-
Choose Alias to CloudFront distributions. The us-east-1 Region is selected by default. Choose the domain name that CloudFront assigned to the distribution when you created it. This is the value that you got in step 1.
- Record type
-
Choose A – IPv4 address.
If IPv6 is enabled for the distribution and you're creating a second record, choose AAAA – IPv6 address.
- Evaluate target health
-
Accept the default value of No.
-
Choose Create records.
-
If IPv6 is enabled for the distribution, repeat steps 5 through 7. Specify the same settings except for the Record type field, as explained in step 6.