Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon CloudFront Alternate Domain Names

I'm totally new to Amazon and all of its services. I have set up Amazon S3 and created a CloudFront distribution but what I want is to give a custom domain name to this CloudFront distribution.

I have created a sub-domain on my server and changed the CNAME to the CloudFront distribution link but I can not access to my content on S3. Can anyone tell me full go through how I can set up with alternate domain names?

like image 757
Junaid Tariq Avatar asked Sep 13 '15 12:09

Junaid Tariq


3 Answers

To give a custom domain name to an Amazon CloudFront distribution:

  • Provide an Alternate Domain Name when creating your CloudFront distribution
  • Create a CNAME record in Route 53 (or your own DNS provider) that points to the URL of your CloudFront distribution (eg d3i29vunzqzxrt.cloudfront.net), or create an A record in Route 53 that uses Alias = Yes and select the CloudFront distribution.

From the help tip in the CloudFront console:

If you want to use your own domain name (for example, www.example.com) instead of the CloudFront domain name (for example, d1234.cloudfront.net) for the URLs for your files, specify up to 100 CNAMEs. Separate CNAMEs with commas or put each on a new line. You also need to create a CNAME record with your DNS service to route queries for www.example.com to d1234.cloudfront.net.

like image 173
John Rotenstein Avatar answered Oct 29 '22 18:10

John Rotenstein


I think the guide is designed to have you spend more than you should. Instead, you should:

  1. Add Alternate Domain Name as the guide says.
  2. Create "A" record in Route 53, not CNAME. AWS will charge you for each CNAME request.
like image 31
Jiulin Teng Avatar answered Oct 29 '22 19:10

Jiulin Teng


Update:
Since this release (Apr 8, 2019) when you add an alternate domain name to a distribution, you must also attach a SSL/TLS certificate to that distribution that covers the alternate domain name.

So, first of all make sure that after you registered the domain name with your domain provider (GoDadday, CloudFlare, Route 53 etc') and created a CNAME record you should do the following:

Add an SSL/TLS certificate from an authorized certificate authority (for example - Let's Encrypt) to CloudFront that covers the domain name you plan to use with the distribution - to validate that you are authorized to use the domain. (Read more in here).

And only then update your distribution to add an alternate domain name:
Open Amazon CloudFront console -> General view -> Edit -> Alternate Domain Names (CNAMEs) -> enter the CNAME that you want to associate with the CloudFront distribution (for example www or home).

like image 28
RtmY Avatar answered Oct 29 '22 20:10

RtmY