How to host a static website using Amazon S3

Steps:

  1. Create S3 bucket
  2. Upload index.html and error.html to the S3 bucket
  3. Enable website hosting on the bucket
  4. Add bucket policy to make the bucket public

Login to the AWS Management console and choose S3 on the services page. Create a bucket to host the website. I created a bucket with name makemywebsite. For more information on creating S3 buckets click here.

Upload your index.html and error.html pages to the S3 bucket.

Select the bucket and choose Static website hosting under Properties tab.

Select Use this bucket to host a website and enter the names of the html files for Index document and Error document and choose Save.

For website hosting, the contents of the bucket must be publicly accessible. To grant public access on the bucket, in the Permissions tab, choose Bucket policy and copy/paste the below json policy into the editor and choose Save. Replace bucket arn for your bucket.

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

If you receive access denied error while creating the bucket policy, check the public access settings on the bucket. Both options under “Manage public bucket policies” should be False. If they are True as shown below, choose Edit and disable the settings for public bucket policies and confirm. You will now be able to create the Bucket Policy without any errors.

Test if your website hosted on S3 is reachable by opening the end-point in a browser window. You will see your index page.

You can also test the error page by adding /test at the end of the url.

See also  How to find the size of a table in Redshift