AWS S3 - Static Website Hosting

·

2 min read

Amazon S3, or Simple Storage Service, is a global storage service that allows access to stored data from anywhere, provided the correct access permissions are in place. In S3, all data is stored as objects, and these objects are organized into buckets, acting as central repositories for the stored data. Each bucket in S3 must have a unique name across all of AWS.

In the previous article, we have seen about how to create bucket, add object to it and its key feature.

This article is about hosting a static website using S3.

  1. AWS console -> S3 -> Create Bucket

  2. Enter the bucket name and select the region for S3 bucket.

  3. Unblock the Block All public Access settings

  4. Open the bucket and go to properties tab

  5. Scroll Down till Static Website Hosting Section and click Edit.

  1. Enable the static website hosting and give index document and select save changes.

Index Document - Specifies the default page of the website

  1. Open the link in the static website hosting section

    1. You will get Forbidden 403 as response

      Because we haven't provided permission to access the object.

    2. Go to permission section -> Bucket Policy

    3. Select edit in the Bucket Policy and add the following code to it.

      {

      "Version": "2012-10-17",

      "Statement": [

      {

      "Sid": "PublicReadGetObject",

      "Effect": "Allow",

      "Principal": "*",

      "Action": [ "s3:GetObject" ],

      "Resource": [ "arn:aws:s3:::/*" ]

      }

      ]

      }

    4. Now open the link again

      We have successfully hosted the static website in s3 bucket.

CONCLUSION :

In conclusion, S3 provides a reliable and cost effective way of hosting static applications. By simply enabling website hosting on bucket and configuring the neccessary setting, you can make the website accessible to users worldwide.Overall AWS S3 is a better option for hosting static websites.

Did you find this article valuable?

Support Gopinath J by becoming a sponsor. Any amount is appreciated!