How to Set Up Amazon S3 for Website Hosting

Amazon Web Services S3 is a great way to host static websites. Here’s how to set up Amazon AWS S3 for Website Hosting. 

If you want to run WordPress on Amazon S3, see Serverless WordPress.

This tutorial assumes you’ve already got an Amazon Web Services account.

  1. Go to Services and search for or select S3.

    Select the S3 service
    Select the S3 service
  2. Click Create Bucket.

    Select create bucket
    Select create bucket
  3. Enter a name for your bucket, this must be unique. For instance bobs-cool-hosting.

    Give your bucket and a name and select a region
    Give your bucket and a name and select a region
  4. Select a region to host your bucket in. This will be geographically where your files are served from.  It’s best to choose a location close to where your users visit from. Click Next.
  5. The options can be left default, just click Next.

    Options can be left default
    Options can be left default
  6. Permissions set up is important. By default AWS S3 sets the bucket up to be secure and prevent it from being made publicly accessible. This is due to so many people just setting up buckets and accidentally or carelessly making them public, resulting security breaches. We want our bucket to be public because we’re hosting a website, so uncheck all the Public access settings and click Next.

    Permissions settings
    Permissions settings
  7. On the Review page you may be warned that this bucket may become public, that’s ok as we said so click Create bucket.

    Review page
    Review page
  8. So we’ve now created our bucket, as you can see here it’s marked “Objects can be public“. Click on the name of the bucket to open it.

    List of buckets
    List of buckets
  9. Click the Properties tab, then click Static website hosting.

    Select static website hosting
    Select static website hosting
  10. Click the option Use this bucket to host a website. Take note of the URL at the top, this will be used to access our website. Type in index.html as the index document and error.html as the error document. Click Save.

    Configure static website hosting
    Configure static website hosting
  11. If you now go to the URL we saw you’ll see it’s still saying 403 Forbidden. We now need to set up it’s permissions to enable public access.

    By default access is prevented
    By default access is prevented
  12. Click on the Permissions tab, then Bucket Policy. Copy in the following policy, being sure to change the bucket name in the Resource field from “my-serverless-wp” to match the name of your bucket. Click Save.
    {
     "Version": "2012-10-17",
     "Statement": [
     {
     "Sid": "PublicReadGetObject",
     "Effect": "Allow",
     "Principal": "*",
     "Action": "s3:GetObject",
     "Resource": "arn:aws:s3:::my-serverless-wp/*"
     }
     ]
    }

    Set up bucket policy
    Set up bucket policy
  13. Now create a test.html file with just a bit of text in it. On the Overview tab click Upload.

    Select Upload
    Select Upload
  14. Click Add File and Select the file you created and then click Next.
  15. Under Manage public permissions select Grant public read access to this object(s). Click Next.

    Set object to public
    Set object to public
  16. On the Set properties page the standard Storage Class is fine for this, click Next.

    Default properties are fine
    Default properties are fine
  17. Click Upload, our file will then be displayed in the list. 
  18. Go to the bucket url from step 10, enter this in a browser and add at the end “/test.html”. You should see your test.html page displayed.

    Test page is now displayed
    Test page is now displayed

Your S3 bucket is now ready to serve your website, but you’ll probably want to set up a DNS CNAME to give it a friendly domain name. I’ll explain how to do that in another article.