How to host a static website on S3

Updated: January 19, 2012

UPDATE: I was horribly wrong about how to do the domain forwarding for naked domains - however there's a simple answer. The good folks at wwizer have got a free naked domain rewriting service.

In order to use it simple change your A (Host) to point to the ip address and you'll be sorted.

In February this year Amazon announced that you can now host static websites on S3. This is a great cost effective way of hosting small, simple websites (like an iPhone app site for example).

Here's how you can do it:

  • Buy the domain name for the site you want to host. It's best to do this first, because the S3 bucket name has to be the same as the domain.

  • Get an S3 account (it's cheaper than you think, I only get billed 3c a month).

  • Log into the aws management console and create a bucket with the same name as your domain (complete with www). So for my website I called the bucket

  • So that people have permission to view your website you'll need to upload a bucket policy. Select on the newly created bucket, and click Actions > Properties.
    On the permissions tab click Add bucket policy and copy the following in (swapping for your own domain):

	  "Principal": {
            "AWS": "*"
  • While you've got the bucket panel open, click the Website tab and check Enabled. Also put the filename of your index file in the Index Document field.

You can also optional include the name of your Error Document. This is the will be the document that is shown for any 4XX class of errors.

  • Click the Upload button and upload your website into that bucket. (In my case it was 3 files, index.html, error.html and styles.css)

  • To test it worked, click on the Endpoint link on the Websites tab of the bucket properties. Hopefully you should see your website up and running! (It might take a few minutes to kick in).

Domain names

Almost there, now just have to get the domain name running correctly. For this you'll need to set up a CNAME redirect for www.
I know it's horrible, but I use Godaddy, and here's how I got this to work.

  • Log into the Godaddy domain management console and edit your zone file.

  • Amazon S3 static website doesn't support naked domain rewriting, but thankfully wwizer provide it as a free service. In order to use it simply change the A (Host) to the ip address

  • Edit the www subdomain to point to the endpoint that S3 gave you

  • Save the Zone File

  • Click save, and now you should be able to browse to your site, all up and running!


Here's a script I created that let's you upload your files to S3 with ease.
It doesn't handle subdirectories, and it uploads all the files all the time (which isn't very cost efficient) - but for small websites it's pretty useful.

To use it:

  • Install the S3 gem with gem install aws-s3

  • Copy the script into your website directory

  • Change the access key, secret and bucket name to your amazon credentials.

  • Run it with: ruby upload.rb

require 'rubygems'
require 'aws/s3'
# Change the access key and secret to your amazon credentials
    :access_key_id     => 'ACCESS_KEY_ID',
    :secret_access_key => 'SECRET'
# Change this to your S3 bucket name

# Will raise an error if bucket doesn't exist

Dir["*"].each do |file|
  # Don't upload this file!
  if file != __FILE__
    print "Uploading #{file}..", open(file), WEBSITE_BUCKET_NAME)
    puts "done!"

Subscribe via RSS

Back to all blog posts