In this post you are going to learn more about Amazon Web Services (AWS) via a practical example, hosting a static website on Amazon Simple Storage Service (S3) . In few easy steps you can have a static website hosted on S3.
While there are many cloud providers available, I use AWS because:
They have the “Free Tier” which is a huge benefit when combined with already low costs.
Their services offer unmatched scale, elasticity, performance, and security.
It is one of the easiest to learn when you use it for practical examples.
Follow below steps to create s3 and add these files on the repo to s3
Clone below repository for the code with respect to this article and after that follow the mentioned steps :
https://github.com/rishabh1cr/static_website_s3.git
1.Create an S3 bucket:
Login to your AWS account, navigate to the S3 service and create a new bucket with a unique name. Choose the region where you want to host your website. And allow public access
2.Enable Static Website Hosting:
Select the bucket and click on the "Properties" tab, then click on the "Static website hosting" option. Choose "Use this bucket to host a website" and enter the default page(index.html) and error page(if any).
3.Set Bucket Permissions:
Click on the "Permissions" tab and scroll down to the "Bucket policy" section. Create a policy that allows public access to your bucket. Copy the mentioned code here to allow public access to all the objects within the bucket.
Bucket policy :
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket_name/*"
}
]
}
4.Upload Website Files:
Upload your website files to the bucket using the "Upload" button or a third-party tool like Cyberduck or S3cmd.
5.Configure Website URL:
Once the files are uploaded, you need to configure the website URL. Click on the "Static website hosting" option and note down the endpoint URL provided.
That's it! Your website is now live and accessible via the S3 URL.
The website with s3 static hosting is for this article from our repository is :
http://static-website-buckets.s3-website-us-east-1.amazonaws.com
Summary
Creating, managing, and hosting websites and webpages and sharing data publicly is very important and crucial as this provides the public face of most brands and organizations. Looking at this perspective, AWS has developed a great idea to publicly provide an easy and simple solution for their users to host content using the S3 bucket. This guide describes simple steps to host your static website using the AWS S3 bucket. I hope you found this article helpful.