Back to Home

S3 for Hosting Static Website

Configure your AWS S3 bucket for static website hosting using CloudShell commands.

1. Create Your Bucket

Go to CloudShell and type:

aws s3 mb s3://your-unique-bucket-name --region us-east-1

2. Enable Website Hosting

Enable static website hosting on your S3 bucket:

aws s3 website s3://your-bucket-name --index-document index.html --error-document index.html

3. Turn Off Block Public Access

Disable block public access settings for the bucket:

aws s3api put-public-access-block \
--bucket your-bucket-name \
--public-access-block-configuration "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"

4. Apply Public Read Policy

Create a bucket policy allowing public read access and apply it to your bucket:

cat <<EOF > policy.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "PublicReadGetObject",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::your-bucket-name/*"
    }
  ]
}
EOF

aws s3api put-bucket-policy --bucket your-bucket-name --policy file://policy.json

If that didn't work, go to Permissions > Bucket policy in the AWS Management Console and paste the policy instead.