AWS S3 Web Hosting With CLI

Note: This file contains experimental configurations and may need verification.

Web Hosting on AWS S3 Using CLI

This guide demonstrates how to set up static website hosting on Amazon S3 using the AWS Command Line Interface.

Enable static website hosting

aws s3 website s3://pratheba.com-bucket --index-document index.html --error-document error.html

Make the bucket publicly readable

Your bucket needs a public read policy:

# Create a bucket policy file (bucket-policy.json)
cat > bucket-policy.json << EOF
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::pratheba.com-bucket/*"
        }
    ]
}
EOF

Apply the policy

aws s3api put-bucket-policy --bucket pratheba.com-bucket --policy file://bucket-policy.json

Disable “Block Public Access” settings

aws s3api put-public-access-block --bucket pratheba.com-bucket --public-access-block-configuration "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"

Get your website endpoint

After enabling static hosting, your website will be available at: http://pratheba.com-bucket.s3-website-.amazonaws.com

You can find the exact URL in the S3 console under Properties > Static website hosting.

Optional: Set up custom domain

If you want to use pratheba.com as your domain, you’ll need to:

  1. Configure Route 53 or your DNS provider to point to the S3 website endpoint
  2. Consider using CloudFront for HTTPS support and better performance
  3. Ensure proper folder structure - Your index.html file should be in the root directory

Upload your website files

# Upload all website files to your S3 bucket
aws s3 sync ./your-website-folder/ s3://pratheba.com-bucket/

# Verify the upload
aws s3 ls s3://pratheba.com-bucket/