AWS S3 - Static Website Hosting
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.
AWS console -> S3 -> Create Bucket
Enter the bucket name and select the region for S3 bucket.
Unblock the Block All public Access settings
Open the bucket and go to properties tab
Scroll Down till Static Website Hosting Section and click Edit.
- Enable the static website hosting and give index document and select save changes.
Index Document - Specifies the default page of the website
Open the link in the static website hosting section
You will get Forbidden 403 as response
Because we haven't provided permission to access the object.
Go to permission section -> Bucket Policy
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:::/*" ]
}
]
}
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.