How To Host Website On AWS S3? Step By Step Guide

Sharing is Caring:

To host a static website on AWS S3, follow these steps:

Step 1: Create an S3 Bucket

  1. Login to AWS Management Console:
    • Go to the S3 service in the AWS Management Console.
  2. Create a New Bucket:
    • Click on Create bucket.
    • Provide a unique Bucket name (this name must be globally unique).
    • Select the Region where you’d like to host the bucket.
    • Click on Create bucket.

Step 2: Upload Your Website Files

  1. Open your newly created bucket.
  2. Click on the Upload button.
  3. Add all your static files (HTML, CSS, JavaScript, images, etc.).
  4. Click Upload to finish the process.

Step 3: Enable Static Website Hosting

  1. In the S3 console, navigate to your bucket.
  2. Click on the Properties tab.
  3. Scroll down to Static website hosting.
  4. Click on Enable.
  5. Specify the following:
    • Index document: Enter the filename of your homepage, typically index.html.
    • Error document (optional): Enter the filename for error pages, typically error.html.
  6. Click Save changes.

Step 4: Set Permissions

  1. Go to the Permissions tab of your bucket.
  2. Click on Bucket policy and add the following policy to allow public access to your files:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::YOUR-BUCKET-NAME/*"
    }
  ]
}

Replace YOUR-BUCKET-NAME with the name of your S3 bucket.

3. Click Save.

Note: This policy makes the contents of the bucket publicly accessible. Ensure that no sensitive information is stored in the S3 bucket.

Step 5: Access Your Website

  1. Once the static website hosting is enabled, you will see a Bucket Website Endpoint in the Static website hosting section.
  2. Use this endpoint to access your website. It will look like:
http://YOUR-BUCKET-NAME.s3-website-YOUR-REGION.amazonaws.com

Step 6 (Optional): Use a Custom Domain with Route 53

  1. To use a custom domain (e.g., www.example.com), you can configure DNS settings using Amazon Route 53.
  2. Create a CNAME record that points to the S3 website endpoint.
  3. You may need to configure SSL/TLS (using AWS Certificate Manager) and CloudFront for HTTPS access.

That’s it! Your static website is now hosted on AWS S3.

Sharing is Caring:
Asad
Asad

Hi, I'm Asad Mahmood, a passionate Cloud Technology Enthusiast. With a fervent interest in the transformative power of cloud computing, I'm dedicated to exploring its capabilities and leveraging them to drive innovation and efficiency in the digital landscape.

Articles: 14

Leave a Reply

Your email address will not be published. Required fields are marked *