back
written on 2 January 2024
How To Set Up A Web Server Using AWS S3
These steps will set up both your apex domain (example.com) and your www sub-domain (www.example.com). Replace example.com with your custom domain name.

  1. open the AWS S3 console and click on "Create a bucket"
  2. create a bucket named www.example.com (the name must match your custom domain)
  3. pick an AWS region near you or your customers (I picked U.S. West Oregon)
  4. turn off Block All Public Access (we will change this later) so no checkboxes are checked
  5. acknowledge that you are making it public, then click Create a bucket at the bottom
  6. back on the AWS Amazon S3 > Buckets page click on the bucket name you just created
  7. click on the Properties tab
  8. scroll to the bottom and click on the Edit button for Static website building
  9. click the enable button, enter "index.html" and optionally "error.html" and click Save changes
  10. click on the Permissions tab
  11. scroll down to the Bucket policy section and click on the Edit button
  12. add this JSON, changing the highlighted to your bucket name (keep the /* at the end)

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

  13. click Save Changes
  14. click on the Objects tab
  15. click on the file upload button on the right and drag and drop an index.html and error.html file
  16. index.html sample: Hello Web!
  17. error.html sample: Something terrible has happened!
  18. click on the Close button
  19. test the web server by changing the highlighted parts and going to:
    http://www.example.com .s3-website-us-west-2.amazonaws.com/
  20. now set up a second S3 bucket for the apex domain example.com (no www prefix)
  21. repeat steps 2 - 5 but with the bucket named example.com (no www prefix)
  22. click on the Properties tab
  23. enable web hosting
  24. this time set Hosting type to Redirect requests
  25. set the host name to www.example.com (so now everything gets redirected to www)
  26. set the protocol to https and click Save changes
  27. test the second bucket by replacing the highlights:
    http://www.example.com .s3-website-us-west-2.amazonaws.com/

References
  1. Logging web traffic - Amazon Simple Storage Service
  2. AWS has logging and metrics through CloudWatch
  3. How to host a static website using AWS S3 and Cloudflare - Mike Tabor
  4. How to Host a Website on S3 Without Getting Lost in the Sea - Kyle Galbraith
  5. GitHub list of S3 leaks
  6. S3: Connecting S3 and Cloudflare
  7. AWS: Tutorial: Configuring a static website on Amazon S3
  8. AWS: Hosting a static website using Amazon S3 - Amazon Simple Storage Service
  9. AWS: What is Amazon S3? - Amazon Simple Storage Service
  10. AWS: Creating an Amazon Simple Storage Service (S3) bucket
  11. AWS: Buckets overview - Amazon Simple Storage Service
  12. AWS: Adding a bucket policy by using the Amazon S3 console
  13. AWS: Bucket policy examples - Amazon Simple Storage Service
  14. AWS: Blocking public access to your Amazon S3 storage
  15. AWS: Setting permissions for website access - Amazon Simple Storage Service
  16. AWS: Configuring a webpage redirect - Amazon Simple Storage Service
  17. AWS: Using cross-origin resource sharing (CORS) - Amazon Simple Storage Service
  18. AWS: Troubleshoot Access Denied (403 Forbidden) errors in Amazon S3