Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Created S3 public bucket for hosting a static website
if [ -z "$1" ]
then
echo "Usage: `basename "$0"` <bucket_name>"
fi
bucket_name=$1
bucket_policy=`echo '{
"Version":"2012-10-17",
"Statement":[{
"Sid":"PublicReadGetObject",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::BUCKET_NAME/*"
]
}
]
}' | sed "s/BUCKET_NAME/$bucket_name/g"`
aws s3 mb s3://$bucket_name
echo "Hello $bucket_name" > /tmp/index.html
echo $bucket_policy > /tmp/public-policy.json
aws s3 cp /tmp/index.html s3://$bucket_name
aws s3api put-bucket-policy --bucket $bucket_name --policy file:///tmp/public-policy.json --output json
aws s3api put-bucket-acl --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers --bucket $bucket_name --output json
aws s3 website --index-document index.html s3://$bucket_name
echo "Your public url is http://${bucket_name}.s3-website-us-west-1.amazonaws.com/"
rm /tmp/index.html
rm /tmp/public-policy.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment