Created
November 30, 2018 13:33
-
-
Save Kif11/786d3d52c20120f270b7c75046f6427f to your computer and use it in GitHub Desktop.
Created S3 public bucket for hosting a static website
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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