How to Host a Website Using AWS S3
Have you ever wondered how a website can be hosted without managing a traditional web server?
Amazon Web Services (AWS) makes this possible with Amazon S3 (Simple Storage Service).
Amazon S3 is a cloud storage service that allows you to store files such as HTML, CSS, JavaScript, images, and documents. It can also be used to host static websites.
In this article, we'll understand how S3 website hosting works and learn how to deploy a simple website step by step.
What is Amazon S3?
Amazon S3 is an object storage service provided by AWS. It stores data as objects inside containers called buckets.
For website hosting, an S3 bucket can store all the files required to display your website.
For example:
- HTML files – Website structure
- CSS files – Website design
- JavaScript files – Website functionality
The best part is that you don't need to manage a traditional web server for a static website.
How Does S3 Website Hosting Work?
The process is simple:
- Upload your website files.
- Enable static website hosting.
- Configure the required permissions.
- Access your website through its website endpoint.
Once configured, visitors can access your website through the provided URL.
Step-by-Step: Host Your First Website Using AWS S3
Step 1: Create an AWS S3 Bucket
- Log in to your AWS Management Console.
- Enter a unique bucket name, such as
my-first-static-website .
- Select your preferred AWS Region.
Remember that S3 bucket names must be globally unique.
Step 2: Prepare Your Website Files
Before uploading files, create a simple website on your computer.
Your project structure can look like this:
my-website/
│
├── index.html
├── style.css
└── script.js
You can use the following basic HTML code:
<!DOCTYPE html>
<html>
<head>
<title>My First AWS Website</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Hello from AWS S3!</h1>
<p>My first website is hosted on the cloud.</p>
</body>
</html>
Step 3: Upload Website Files
- Open your newly created S3 bucket.
- Select the Upload option.
- Add your
index.html , style.css , and script.js files.
Your website files are now stored in Amazon S3.
Step 4: Enable Static Website Hosting
- Navigate to the Properties tab.
- Scroll down to Static website hosting.
- Choose Host a static website.
- Enter
index.html as the Index document.
AWS will now provide a website endpoint for your bucket.
Step 5: Configure Website Permissions
For direct S3 website hosting, visitors need permission to read the website files.
AWS blocks public access by default. For this learning example, you can configure a dedicated bucket containing only public website files.
If you choose direct public S3 hosting:
- Open the Permissions tab.
- Edit Block public access settings for the bucket.
- Review the security warning before changing the settings.
- Allow public access only for this dedicated website bucket.
- Add a bucket policy that grants read-only access.
Example bucket policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-first-static-website/*"
}
]
}
Replace my-first-static-website with your actual bucket name.
Important: This policy makes website objects publicly readable. Never store passwords, private documents, API secrets, or personal information in this bucket.
For production websites, AWS recommends using Amazon CloudFront with Origin Access Control (OAC), keeping the S3 bucket private. AWS Amplify Hosting is another recommended option for static websites.
Step 6: Open Your Website
- Go to the Properties tab.
- Find Static website hosting.
- Copy the Bucket website endpoint.
- Open the endpoint in your browser.
Congratulations! Your first website is now hosted using Amazon S3.
Important Things to Remember
- S3 is suitable for static websites.
- It can host HTML, CSS, JavaScript, and image files.
- S3 does not run server-side code such as PHP or Node.js.
- The direct S3 website endpoint supports HTTP, not HTTPS.
- CloudFront can provide HTTPS, caching, and improved global delivery.
- Always review your bucket permissions before making content public.
Why Use Amazon S3 for Website Hosting?
Some important advantages include:
- Scalability: Store and serve website files without managing a traditional web server.
- Cost Efficiency: Pay based on the storage and requests you use.
- Durability: S3 is designed for highly durable object storage.
- Easy Deployment: Update your website by uploading new files.
- AWS Integration: Easily integrate with services such as CloudFront and Route 53.
Conclusion
Hosting a website using Amazon S3 is a great way to understand cloud computing practically.
Instead of just learning AWS concepts, you can create a bucket, upload your files, configure hosting, and see your website running online.
If you're a beginner learning AWS, this is a useful hands-on project to add to your cloud computing journey.
In the next article (Part 06), we'll learn how to connect an EC2 instance using SSH and deploy a website on it.
Keep learning, keep building, and keep exploring AWS!
Loading article