Cloudfront dist on top level domain

amazon-s3, dns

Solution

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

- Cloud front distribution

- 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.

- 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.

Steps to do this.

- Create a hosted zone in Route 53.

- 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).

- 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. Make sure you leave the subdomain part empty (since we are only interested in creating record for second-level domain).

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)

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`).

Problem

Is it possible to point a top level domain like http://example.com to a amazon cloudfront distribution? I know it's possible with CNAMEs, but as far as I know, I need to set an A-name record for the top level domain in the DNS settings.

Original source