DEV Community

Cover image for 🌐 Host a Static Website on AWS S3: Step-by-Step Guide for Beginners
38 2 3 4 3

🌐 Host a Static Website on AWS S3: Step-by-Step Guide for Beginners

👋 Hey there! I’m Sarvar, a Cloud Architect passionate about cutting-edge technologies. With extensive experience in Cloud Operations (AWS & Azure), Data Operations, Data Analytics, DevOps, and GenAI, I've had the privilege of working with global clients to deliver impactful solutions. I’m always exploring the latest tech trends and love sharing my learnings. Let’s dive into the world of cloud and tech together! 🚀

In today’s digital world, having a website is one of the best ways to share information, showcase your work, or run a business. If you have a static website which means a website made with HTML, CSS, and JavaScript (without any backend or server-side code like PHP or Node.js) then AWS S3 is one of the easiest and cheapest ways to host it.

What We Are Doing

In this guide, we’ll host a simple static website on AWS S3. We’ll upload our website files (like index.html, images, etc.) to an S3 bucket and configure it to serve as a publicly accessible website.

Why Use AWS S3?

There are a few different ways to host a website on AWS. For example, you could use Amazon EC2, which gives you full control over a virtual server where you can install anything. While EC2 is powerful, it also requires more setup, maintenance, and can be more expensive for simple use cases. That’s where S3 (Simple Storage Service) shines. It’s ideal for hosting static websites meaning websites that don’t have a backend or database, and are mostly made up of HTML, CSS, JavaScript, and media files. S3 is simple, scalable, and cost-effective, and it takes just a few clicks to get your site live.


🚀 Step-by-Step: Hosting a Static Website on S3

Let’s go through each step in detail. We will host a very simple website with just one HTML file and an image.


1. Prepare Your Website Files

Let’s say you have the following structure:

my-website/
├── index.html
└── images/
    └── logo.png
Enter fullscreen mode Exit fullscreen mode

Image description

Your index.html might look like this:

<!DOCTYPE html>
<html>
<head>
  <title>My First S3 Website</title>
</head>
<body>
  <h1>Hello from AWS S3!</h1>
  <img src="images/logo.png" alt="Logo">
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Tip: Make sure your site works locally before uploading it. Just open the index.html file in your Google Chrome browser.

Download your logo.png from HERE

Once downloaded:

  1. Create an images folder inside your my-website directory (if it doesn't already exist).
  2. Move the downloaded PNG image into the images folder.
  3. Rename the image to logo.png.

2. Create an S3 Bucket

  1. Go to the AWS Management Console, search for S3, and open it.

    Image description

  2. Click Create bucket.

    Image description

  3. Set a unique name like dev-to-static-website-demo.

  4. Leave all other settings as default for now and click Create bucket.

    Image description

  5. Your S3 bucket is created successfully.

    Image description


3. Upload Your Website Files

  1. Open your bucket.

    Image description

  2. Click UploadAdd files, then select your index.html.

    Image description

  3. Click Add folder, then select your images/ folder.

    Image description

  4. Finally, click Upload.

    Image description


4. Enable Static Website Hosting

  1. Go to the Properties tab of your bucket. Scroll down to Static website hosting and click Edit.

    Image description

    Image description

  2. Select Enable, then choose Host a static website.

  3. For Index document, type: index.html.

    Image description

  4. Leave the Error document blank or enter error.html if you have one, and click Save changes.

    Image description


5. Make the Bucket Public

By default, S3 blocks public access. To allow anyone to access your website:

  1. Go to the Permissions tab and under Block public access, click Edit.

    Image description

  2. Uncheck Block all public access, confirm the warning, and click Save changes.

    Image description

    Image description


6. Update Object Ownership and Permissions

  1. Still in the Permissions tab, scroll down to Object Ownership and click Edit.

    Image description

    Image description

  2. Select ACLs enabled, check the acknowledgment box, and click Save changes.

    Image description

    Image description


7. Make Your Files Public

  1. Go back to the Objects tab in your S3 bucket.

  2. Select all files and folders, then click ActionsMake public using ACL.

    Image description

    Image description

  3. Confirm the changes to make your files publicly accessible.

    Image description


8. Access Your Website

Here’s the final section, wrapped up cleanly and ready to go:

  1. Go to the Properties tab > Static website hosting, and copy the Bucket website endpoint URL.

    Image description

  2. Open the URL in your browser.

    🎉 Congratulations! You should now see your website live on the internet!

    Image description


Conclusion: That’s it! With just a few steps, I hosted a static website using Amazon S3. The best part is that I didn’t need to set up any servers, install software, or worry about traffic scaling. S3 takes care of all that in the background. Compared to EC2 or other traditional hosting solutions, using S3 is much easier for static content. It’s fast, cost-effective, and scalable. Whether you’re hosting a portfolio, a personal site, or a landing page, S3 is a fantastic choice.

— — — — — — — —
Here is the End!

Thank you for reading! ✨ I hope this article helped simplify the process and gave you valuable insights. As I continue to explore the ever-evolving world of technology, I’m excited to share more guides, tips, and updates with you. 🚀 Stay tuned for more content that breaks down complex concepts and makes them easier to grasp. Let’s keep learning and growing together! 💡

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (10)

Collapse
 
pkkolla profile image
PHANI KUMAR KOLLA

Good read!

Please try to include table of contents.

You can refer to my post as a reference:
dev.to/pkkolla/amazon-rds-unlocked...

Happy blogging!

Collapse
 
sarvar_04 profile image
Sarvar Nadaf

Thanks 😊

Collapse
 
ansellmaximilian profile image
Ansell Maximilian

Cool! A lot simpler than I expected

Collapse
 
sarvar_04 profile image
Sarvar Nadaf

Yes 😎

Collapse
 
techie_1414 profile image
Techie

This is a great article! I’m just curious since the S3 static website is publicly accessible, is there a way to secure it? And can we expect an upcoming article covering those security best practices?

Collapse
 
sarvar_04 profile image
Sarvar Nadaf

Yes, you can secure an S3 static website using CloudFront with signed URLs, disabling public access, and adding AWS WAF. And yes, an article on this is coming soon!

Collapse
 
techie_1414 profile image
Techie

Thank you

Thread Thread
 
sarvar_04 profile image
Sarvar Nadaf

Your Welcome

Collapse
 
nevodavid profile image
Nevo David

I think setting stuff up on S3 was way easier than I expected, honestly. Anyone else struggle with permissions the first time? That part always trips me up.

Collapse
 
sarvar_04 profile image
Sarvar Nadaf

Totally relatable! S3 setup is surprisingly smooth until you hit access denied error. It took me a few tries (and a lot of trial and error) to get public access. You're not alone!

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay