-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsetup_website.sh
executable file
·53 lines (44 loc) · 1.21 KB
/
setup_website.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
set -e
BUCKET_NAME=YOUR_BUCKET_NAME
# if you want to use route53, make sure to read
# http://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html
REGION=us-east-1
cat << EOF > /tmp/website.json
{
"IndexDocument": {
"Suffix": "index.html"
},
"ErrorDocument": {
"Key": "error.html"
}
}
EOF
cat << EOF > /tmp/bucket_policy.json
{
"Version":"2012-10-17",
"Statement":[{
"Sid":"PublicReadForGetBucketObjects",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::$BUCKET_NAME/*"
]
}
]
}
EOF
create_website() {
aws s3api create-bucket --bucket $BUCKET_NAME --region $REGION
aws s3api put-bucket-policy --bucket $BUCKET_NAME --policy file:///tmp/bucket_policy.json
aws s3api put-bucket-website --bucket $BUCKET_NAME --website-configuration file:///tmp/website.json
aws s3api get-bucket-website --bucket $BUCKET_NAME
}
sync_files() {
aws s3 sync . s3://$BUCKET_NAME --exclude "*.sh" --exclude ".git/*" --exclude "README" --region $REGION
}
# main
create_website
sync_files
echo "Point your browser to the link"
echo http://$BUCKET_NAME.s3-website-$REGION.amazonaws.com