Drew's Blog - Home - Archive

Hosting a static website from S3

I'm trying to move my web hosting off of DreamHost, because they've had some problems recently. I decided that since most of my content is static, I would try to host my sites from S3. Yesterday, I did a trial run with a website of mine that doesn't actually get any traffic. Here's an overview of what you need to do to set up your own static site:

  1. Create an account on AWS, and then create a bucket for your website on the AWS Management Console. (Other blogs suggest that if your website is www.example.com, your bucket needs to be named www.example.com, but I suspect that isn't actually the case.)
  2. Upload your website's files to your bucket.
  3. Create a bucket policy that lets everything be viewable. To do this, select your bucket, then click "Properties" (in the upper right) and then click on the "Permissions" tab (if that isn't selected). Click "Edit Bucket Policy", and then click on the "AWS Policy Generator". This should open a new tab.
  4. Fill out the form with the following values (but without the quotes): Policy type => "S3 Bucket Policy", Effect => "Allow", Principle => "*", Action => "GetObject", ARN => "arn:aws:s3:::yourbucketname/*" (but replace yourbucketname with the name of your bucket, probably something like "www.example.com"). Click "Add Statement", and then scroll down and click "Generate Policy".
  5. Copy the JSON from the popup, and then paste it in to the textarea on the "Edit Bucket Policy" tab in the AWS Management Console. Click save.
  6. Now, we need to configure S3 to serve items as a website. In the AWS Management Console, click "Website" on the menu next to "Permissions".
  7. Click "Enable", fill in the names of the files you want to be served by default (probably "index.html") and on an error (perhaps "error.html"?).
  8. Now, we need to configure your domain name to point to your S3 bucket. Probably in a new tab (since you'll need to copy and paste your "endpoint" from this page later), go to your domain name registrar, and set up your @ and www records to be CNAMEs that point to your endpoint, but with the "http://" removed from the front, and the trailing slash replaced with a period. It should look like this: "www.example.com.s3-website-us-east-1.amazonaws.com."
  9. Wait for DNS to propagate...
  10. You're done! Wasn't that easy?

If you've read this far, you should probably follow me on Twitter.

See more posts

Drew writes code for fun and (sometimes) profit. He's currently studying Computer Science at Carnegie Mellon University. He has previously worked at Facebook, Amazon, and a startup called Intersect.