AWS Builder Center

Deploy a Static Website on Amazon S3: A Beginner-Friendly Guide

Learn how to host a static website using Amazon S3, configure website hosting, upload HTML and CSS files, and understand the basics of making your website accessible on the web.

Introduction

Amazon Simple Storage Service (Amazon S3) is an object storage service that allows you to store and retrieve data. One useful application of Amazon S3 is hosting static websites containing HTML, CSS, JavaScript, and images.
In this tutorial, we will learn how to create a simple static website and host it using Amazon S3.

What You Will Learn

  • What Amazon S3 is and how it works.
  • How to create an S3 bucket.
  • How to upload website files.
  • How static website hosting works.
  • Important security considerations when hosting a website.

Prerequisites

Before starting, you should have:
  • An AWS account.
  • Basic knowledge of HTML.
  • Access to the AWS Management Console.

Step 1: Create an S3 Bucket

  1. Sign in to the AWS Management Console.
  2. Open the Amazon S3 service.
  3. Choose Create bucket.
  4. Enter a globally unique bucket name.
  5. Select your preferred AWS Region.
  6. Review the settings and create the bucket.
For a simple static website using the S3 website endpoint, the bucket name can be chosen independently of your website's display name.

Step 2: Create a Simple Website

Create a file named index.html with the following content:
1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My AWS Website</title>
</head>
<body>
<h1>Welcome to My Website!</h1>
<p>This website is hosted on Amazon S3.</p>
</body>
</html>
Save the file on your computer.

Step 3: Upload the Website File

  1. Open your S3 bucket.
  2. Choose Upload.
  3. Add your index.html file.
  4. Complete the upload.
Your website file is now stored in Amazon S3.

Step 4: Enable Static Website Hosting

  1. Open the bucket's Properties tab.
  2. Find the Static website hosting section.
  3. Choose Edit.
  4. Enable static website hosting.
  5. Select Host a static website.
  6. Set index.html as the index document.
  7. Save the changes.
AWS will provide a website endpoint for the bucket.

Step 5: Configure Access and Test

An S3 website endpoint does not automatically make your website publicly accessible.
For a public demonstration, you must configure access appropriately. This can involve bucket permissions and Block Public Access settings. Only make the minimum necessary content public, and never expose private files or sensitive information.
S3 website endpoints support HTTP, not HTTPS. For a production website, consider using Amazon CloudFront with HTTPS and an appropriate origin access configuration.
After configuring access, open the website endpoint in your browser and verify that your page loads.

Security Best Practices

  • Never upload passwords, access keys, or confidential data.
  • Keep private buckets private.
  • Review bucket policies before allowing public access.
  • Consider Amazon CloudFront for HTTPS delivery.
  • Monitor usage and understand applicable AWS charges.

Conclusion

Amazon S3 provides a straightforward way to store website assets and host static website content. By creating a bucket, uploading HTML files, and configuring website hosting, you can build a simple web project using AWS.
This project is a useful starting point for learning cloud storage, website hosting, and AWS security fundamentals.

References

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article