Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Created S3 public bucket for hosting a static website
if [ -z "$1" ]
echo "Usage: `basename "$0"` <bucket_name>"
bucket_policy=`echo '{
"Principal": "*",
}' | 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= --bucket $bucket_name --output json
aws s3 website --index-document index.html s3://$bucket_name
echo "Your public url is http://${bucket_name}"
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