How to Set Up an S3 Bucket for Static Website Hosting in AWS

Amazon S3 Simple Storage Service is a service that lets you store files in the cloud. You can also use S3 to host static websites, which are websites that don’t require server-side processing like HTML, CSS, and JavaScript files. In this guide, we’ll show you how to set up an S3 bucket for static website hosting in very simple steps.

What You’ll Need

  1. An active AWS account.
  2. Basic knowledge of S3 and the AWS Management Console.
  3. An existing S3 bucket.

Step 1. Enable Static Website Hosting.

  1. After creating the bucket, click on the bucket name to open it. In the bucket dashboard.
    Bucket name
  2. Go to Bucket Properties.
    Bucket Properties

Enable Static Website Hosting

  1. Scroll down to the Static website hosting section.
  2. Click Edit and then select Enable.
    Edit Button
  3. In the Index document field, enter index.html. This is the main page of your website.
    Fields
  4. Optionally, you can also set an Error document (like error.html), which will show up if a page isn’t found.
  5. Click Save Changes when done.

Step 2. Set Bucket Permissions.

Make the Bucket Public

By default, S3 buckets are private, meaning only you can access them. To make the website publicly accessible, you need to adjust the permissions.

Add a Bucket Policy

  1. Go to the Permissions tab in your bucket settings.
    Permission Tab
  2. Scroll to Bucket Policy and click Edit.
  3. Copy and paste the following policy into the policy editor.
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Principal": "*",
          "Action": "s3:GetObject",
          "Resource": "arn:aws:s3:::codemaster000/*"
        }
      ]
    }
  4. Replace YOUR-BUCKET-NAME with the name of your bucket.
    Bucket Policy
  5. Click Save to apply the policy.

Step 3. Upload Your Website Files.

Upload Your Files

  1. In your S3 bucket, click on Upload.
    Click Upload
  2. Select the files you want to upload (e.g., index.html, styles.css, images/).
  3. Click Upload to add the files to your S3 bucket.
    Files

Step 4. Access Your Static Website.

Find Your Website URL

  1. Once your files are uploaded, go back to the Properties tab of your bucket.
  2. Under the Static website hosting section, you will see an Endpoint URL. This is the link to your static website.
  3. Example URL: http://YOUR-BUCKET-NAME.s3-website-REGION.amazonaws.com
    URL

Visit Your Website

Open the endpoint URL in your browser, and you should see your static website live.

Output

Conclusion

Setting up an S3 bucket for static website hosting is simple, and it’s a great way to host lightweight websites without worrying about servers. With just a few clicks, you can have your site live on the web. You can also explore more advanced features like custom domains and SSL certificates as you get more comfortable with AWS S3.


Similar Articles