AWS S3 is great for hosting highly available and reliable files. The files can then be accessed via web browser if public access is enabled on your S3 bucket. A public S3 bucket however does not allow for the followings:

  • Custom domain name
  • Custom error pages
  • Index document for root path
  • 301 redirects

AWS S3 bucket can be used to host highly scalable and available static website by enabling Static Website Hosting option for the S3 bucket.

Steps to host static website on AWS S3:

  1. Create a public S3 bucket.
  2. Go to S3 section of your AWS Management Console
  3. Go to the public bucket that you want to enable static website hosting by clicking on the bucket name.
  4. Upload static website files to the S3 bucket.
    1. Click on the Upload button to open the file upload dialog.
    2. Click Add files to select files to upload.
    3. Select files to upload and and click on the Open button.

      The select dialog allows for multiple file selection.

    4. Click Upload to begin uploading the files.
  5. Configure Static Website Hosting for the bucket.
    1. Click on the Properties tab.
    2. Click on the Static website hosting card.
    3. Select Use this bucket to host a website.
    4. Configure options for static website hosting and click Save.
      • Index document
        • Default page for website.
      • Error document
        • Page to show when errors such as 404 File not found occurs.
      • Redirection rules
        • Rules for website redirection.

  6. Test if your static website hosting is properly configured.
    1. Directly access files you've uploaded using the following format:

    2. Access root document.

      Should display content of Index document

    3. Access nonexistent file to simulate a file not found error.

      Should display content of Error document

Discuss the article:

Comment anonymously. Login not required.