While thinking about a cheap and easy way to host a huge amount of static websites I got the idea to host them on Amazon S3. The following guide demonstrates how to do just that. The official Amazon Guide states to use Route 53 as a DNS Service. But in my opinion this has a few disadvantages:

  • You will have trouble setting up your E-mail
  • It is pretty expensive (see the pricing)

Therefore we will use the domain registrar of your choice to register the domain and manage our emails. Using DNS we will route the web request to Amazon S3. I recommend to use Namecheap*.

Step-1: Create your S3 website bucket

First you need to create a bucket for your website. The name of the bucket must use the same name as your domain. If you want to use the domain example.xyz your bucket should be named example.xyz as well. The same rules apply for subdomains, so www.example.xyz would use www.example.xyz as its bucket name. The website end-point will then be something like example.xyz.s3-website-us-east-1.amazonaws.com. Naming the buckets differently will cause warnings and errors (404 not found, nosuchbucket).

Step-2: Change the buckets permissions

The website should be accessible to everyone, because of that we have to change the objects permissions to publicly accessible. Just attach the following policy to the bucket.

{
  "Version":"2012-10-17",
  "Statement":[{
	"Sid":"PublicReadGetObject",
        "Effect":"Allow",
	  "Principal": "*",
      "Action":["s3:GetObject"],
      "Resource":["arn:aws:s3:::example.com/*"
      ]
    }
  ]
}

See this guide for more details.

Step-3: Configure Buckets for Website Hosting

Now you need to configure your bucket for webhosting. Do this by opening the bucket properties and check the value static webhosting. Then fill the dialog with the appropriate values.

PS: Don’t forget to put an index.html file, but I guess you already know how to do this if you are reading this guide.

Step-4: Remove any existing „A“ record of your domain

Open the DNS administration tools of your domain registrar and remove any „A“ records the domain already has. The DNS „A“ record defines on which IP-Address the domain is hosted. We will not use IP-Addresses to point to s3, as it shouldn’t be accessed like that by design. If you leave any „A“ record the domain will route to its IP instead of S3.

Step-5: Forward your root domain to www

In the registrars domain setting you should forward the root domain example.xyz to the www subdomain. We will serve our domain from there.

Step-6: Add a „CNAME“ pointing to your S3 site

Add a CNAME for the www subdomain, pointing to your S3 website (www.mydomain.com.s3-website-eu-west-1.amazonaws.com). Your registrar should have a guide on its site explaining how to do this.

Add a CNAME

The only thing you have to do now is wait. It can take up to 24 hours for your settings to become effective.

 

* – This link is an affiliate link pointing to Namecheap. If you visit Namecheap using this link I will get a 15% comission on your order. The fact of me getting money doesn’t influence me in my decision to recommend this service in any way.