DEV Community

Carlos Henrique
Carlos Henrique

Posted on

Hosting a Static Website on Amazon S3 – A Step-by-Step Guide πŸš€

Hosting a Static Website on Amazon S3 – A Step-by-Step Guide

Many times, we need to host a simple website, whether for a portfolio, a landing page, or a static project. Instead of investing in complex servers, Amazon S3 offers a practical and cost-effective solution for this need. In just a few steps, we can configure an S3 bucket to serve a static website accessible via the internet.

In this tutorial, I will walk you through the step-by-step configuration process.

What is Amazon S3?

Amazon S3 (Simple Storage Service) is a cloud-based object storage service provided by AWS. It allows you to store and retrieve any amount of data at any time, ensuring high durability, availability, and scalability. S3 is widely used for backups, content distribution, and simple, efficient static website hosting.

S3 stores data in buckets, which function like "folders" in the cloud. Each bucket can contain individual files (objects) such as images, documents, and web pages. When enabling static hosting, S3 serves these files directly over the internet without the need for traditional servers.

Advantages and Disadvantages of Amazon S3

βœ… Advantages:

  • Low Cost: You only pay for storage and data transfer, with no fixed costs.
  • High Availability: AWS's robust infrastructure ensures reliable access to the site.
  • Scalability: Can handle a high number of requests without the need to configure additional servers.
  • Easy Configuration: Your website can be live in just a few steps without requiring web servers.
  • Integration with Other AWS Tools: Such as CloudFront for CDN and Route 53 for custom domains.

❌ Disadvantages:

  • No Support for Dynamic Applications: S3 is only suitable for static websites (HTML, CSS, and plain JavaScript).
  • Permission Management: You need to configure permissions correctly to ensure public access to the site.
  • Unfriendly Default URL: The link generated by S3 can be long and complex, requiring a custom domain for better user experience.
  • No Native HTTPS: To enable HTTPS, you need to configure Amazon CloudFront or another CDN service.

Step 1: Creating an S3 Bucket

  1. Log in to the AWS Management Console.
  2. Go to the S3 service.
  3. Click on Create bucket.
  4. Choose a unique name for your bucket (e.g., mywebsite-example).
  5. Select a region close to your target audience.
  6. Uncheck the Block all public access option to allow your site to be publicly accessible.
  7. Confirm the settings and click Create bucket.

Step 2: Enabling Static Website Hosting

  1. In S3, click on the bucket you created.
  2. Go to the Properties tab.
  3. Scroll down to Static website hosting and click Edit.
  4. Select Enable.
  5. In the Index document field, enter index.html.
  6. Click Save changes.

This makes S3 serve index.html as the homepage of your site.


Step 3: Making Files Public

  1. Go to the Permissions tab of your bucket.
  2. Scroll to Bucket policy and click Edit.
  3. Paste the following policy to allow public access:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::mywebsite-example/*"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode
  • Replace mywebsite-example with your bucket name.
  • Click Save changes.

Now, anyone can access your bucket’s files via HTTP.


Step 4: Uploading Your Files

  1. Go to the Objects tab in S3.
  2. Click Upload.
  3. Select your website files (index.html, styles.css, etc.).
  4. Click Upload.

Step 5: Accessing Your Website

After completing the steps above, your website will be available at a link similar to:

http://mywebsite-example.s3-website-us-east-1.amazonaws.com

Replace mywebsite-example and the region as needed.


Final Thoughts

Now your website is live! To make access more professional, you can configure CloudFront as a CDN and use a custom domain with Route 53.

If you enjoyed this tutorial, feel free to leave a comment. If you have any suggestions, I’d love to discuss them here! πŸš€

Top comments (0)