DEV Community

Cover image for Static Website Hosting Using S3 Bucket
Clinton Ogechi
Clinton Ogechi

Posted on • Edited on

Static Website Hosting Using S3 Bucket

Amazon S3 (Simple Storage Service) offers a cost-effective and scalable solution for hosting static websites that consist solely of HTML, CSS, and JavaScript files. Amazon S3 offers a robust infrastructure that allows you to store and serve your website's content to users globally, without the need to manage servers. Below is a hand-on steps for achieving this.

Steps

1. Create an S3 Bucket

  • Navigate to the S3 service in the AWS Management Console.
  • Click on “Create bucket” and provide a unique bucket name (e.g., my-website-bucket-yourname).
  • Choose a region and leave other settings as default.
  • Click “Create bucket”.

Image description

Image description

Image description

Image description

2. Upload Website Content

  • Select the newly created bucket.
  • Click “Upload” and add your website files (HTML, CSS, JS).

Image description

Image description

3. Set permissions to make your website files publicly accessible.

  • Go to the AWS Management Console and open the S3 service.
  • Click on the bucket name that contains your website files.
  • In the bucket, go to the Permissions tab.
  • Scroll down to the Bucket Policy section and click on Edit.
  • Add the following bucket policy to allow public access to all objects in the bucket:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::your-bucket-name/*"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode
  • Replace your-bucket-name with the name of your bucket.
  • Click on Save changes.

Image description

Image description

4. Enable Static Website Hosting

  • In the bucket settings, select the “Properties” tab.
  • Click “Static website hosting” and enable it.
  • Specify the index document (e.g., index.html).
  • Save the changes.

Image description

Image description

5. Access Your Website Using the S3 Endpoint

  • Once you enable static website hosting, AWS will provide an S3 website endpoint. This endpoint typically looks like:
http://my-website-bucket.s3-website-region.amazonaws.com
Enter fullscreen mode Exit fullscreen mode
  • Replace my-website-bucket with your bucket name and region with the region code (e.g., us-east-1).
  • You can now access your static website by navigating to this endpoint in your web browser.

Image description

Conclusion

By following these steps, you've successfully set up a static website hosted on Amazon S3, leveraging AWS's scalable and reliable infrastructure without the need to manage servers. Your website is now globally accessible via the S3 endpoint, allowing you to deliver content efficiently to users around the world. This setup not only simplifies the process of hosting a static website but also provides a cost-effective solution with the flexibility to scale as your website's traffic grows.

Top comments (0)