Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Using S3 To Host a Static Site

This tutorial will show you how to get a very basic site hosted online using Amazon S3. This will only work with static sites that do not use any server-side language to create dynamic content, such as PHP. You are limited to pure HTML, Javascript, CSS and Images.

Steps

Create a Bucket

Create a bucket with your FQDN. E.g. www.mydomain.com. You must already own this domain for this tutorial to work.

Configure the Bucket

Configure the bucket you just created, by:

  1. Clicking the magnifying glass icon by the bucket name.
  2. Clicking on "Enable website hosting".
  3. Specifying the index document. We will create it later.
  4. Specifying the error document. We will create it later.
  5. Copying the endpoint url, which we will use later.
  6. Clicking save.

Configure DNS

For those not using AWS Route53, go to your domain registrar's DNS configuration service and create a new CNAME record that points to the endpoint you just copied from your bucket in the previous step.

Upload The Site

Now we need to upload our static site to the bucket so that others can view it. You will need at least an index.html and a 404.html file. Upload these by clicking on the bucket's name in s3 and then clicking the upload button in the top left corner (also shown in screenshot of next step).

Make The Site Public

Finally, we need to make those files publicly available so that anybody on the Internet can view our site. For each file:

  1. Click the radio button next to the filename in order to select it.
  2. Click the Permissions text in the pane on the right, in order to expand it.
  3. Click Add new permissions.
  4. Choose Everyone, and select Open/Download.
  5. Save your changes.

Your Site is Ready

You may need to wait a while for your DNS configuration from earlier to propagate over the internet, but within a couple hours or minutes, you should be able to see your static site if you type the domain into a browser.

Last updated: 21st June 2021
First published: 16th August 2018