Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloudfront dist on top level domain

Tags:

Is it possible to point a top level domain like http://example.com to a amazon cloudfront distribution?

I know it's possible with CNAME's but as far as i know i need to set a A-name record for the top level domain in the DNS settings.

like image 651
Martin Avatar asked Aug 28 '09 17:08

Martin


1 Answers

As explained by @dgeske, this can be done. In my case, I had not purchased the domain from Route 53, and hence had to do extra configuration.

Scenario: You have the following

  1. Cloud front distribution
  2. A second-level domain (example.com) not purchased from Amazon Route 53. It was Google domains in my case, but the idea will work for other providers also.
  3. You want to point the second-level domain (example.com) to the cloud front distribution (as opposed to a subdomain like www.example.com)

Your nomenclature is slightly inaccurate. example.com is not a TLD (top-level domain), it is what is called a second-level domain. See the following image. Parts of a URL

Steps to do this.

  1. Create a hosted zone in Route 53.Create a hosted zone in route 53
  2. Route 53 will now give you a list of name servers that you have to set in the domain settings panel of the provider from which you purchased the domain (Google domains in my case).Chaning name servers from google domains dashboard
  3. Go back to Route 53 dashboard, and create an A - Alias record for this hosted zone (use create record set option). Remember to select 'Yes' radio button.A-Alias record set Make sure you leave the subdomain part empty (since we are only interested in creating record for second-level domain).leave sub-domain part empty

Now you should be able to access your cloudfront distribution at http://example.com. Depending on your DNS server, it may take a while to get records updated.
You may configure your system to use a public DNS server such as 8.8.8.8 to verify if you are able to access the cloudfront distribution using the URL. I used firefox's DNS over https feature for this. This makes firefox use cloudflare's (not cloudfront) DNS servers. You can also use dig command line utility dig @8.8.8.8 example.com (My domain was fightcoronapune.com, hence, dig @8.8.8.8 fightcoronapune.com) (telling dig to use 8.8.8.8 DNS server to resolve names) firefox DNS over https

You may additionally get Access Denied error, in which case you will have to configure the default root object for your cloudfront distribution. So that when you visit http://example.com the file http://example.com/index.html is served to you (assuming you specified index.html as default root object). This error has nothing to do with the steps we did above, and you will still get this error even if you directly use your cloudfront distribution's URL given by Amazon (eg. when you go to http://abcd.cloudfront.net directly, instead of going to http://example.com).

like image 165
Sahil Singh Avatar answered Sep 20 '22 02:09

Sahil Singh