A bucket is private when you create it. Nobody outside your account can read an object, and the account's Block Public Access settings stop you from changing that by accident. Serving a website means changing it on purpose, in three steps.
1. Lift the block
aws s3api get-public-access-block --bucket monster-market-h7frlm
aws s3api put-public-access-block --bucket monster-market-h7frlm \
--public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=false,RestrictPublicBuckets=falseFour switches, all true by default. Two concern ACLs, an older mechanism this course leaves off. BlockPublicPolicy refuses any policy that would make the bucket public; RestrictPublicBuckets ignores such a policy if one exists. Both go to false for a website bucket.
2. Attach a bucket policy
A policy is a JSON document of statements. This is your first one; Chapter 2 has the full grammar.
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::monster-market-h7frlm/*"
}]
}Effect allows. Principal * is anyone at all. Action s3:GetObject is reading an object, nothing else. Resource is every key in this bucket, by ARN. Save it as a file and attach it:
aws s3api put-bucket-policy --bucket monster-market-h7frlm --policy file://policy.json
aws s3api get-bucket-policy-status --bucket monster-market-h7frlmfile:// tells the CLI to read the parameter from a file. The status reports "IsPublic": true.
3. Turn on website hosting
aws s3 website s3://monster-market-h7frlm --index-document index.html --error-document error.htmlThe bucket now answers on its website endpoint, http://monster-market-h7frlm.s3-website-us-east-1.amazonaws.com. A request for / gets index.html; a missing key gets error.html with a 404.
curl -s http://monster-market-h7frlm.s3-website-us-east-1.amazonaws.com/Before the policy, the same request returns 403 Forbidden. That is the difference the two steps make.