forked from swoodford/aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3-setup-buckets.sh
executable file
·61 lines (55 loc) · 1.19 KB
/
s3-setup-buckets.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
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
# This script will create S3 buckets, set CORS config and tag bucket with client name
# Requires awscli
# Verify AWS CLI Credentials are setup
# http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
if ! grep -q aws_access_key_id ~/.aws/config; then
if ! grep -q aws_access_key_id ~/.aws/credentials; then
echo "AWS config not found or CLI not installed. Please run \"aws configure\"."
exit 1
fi
fi
read -r -p "Enter the client name: " CLIENT
function createbucket(){
aws s3api create-bucket --bucket $CLIENT-$ENV
}
function setcors(){
aws s3api put-bucket-cors --bucket $CLIENT-$ENV --cli-input-json \
'{
"CORSConfiguration": {
"CORSRules": [
{
"AllowedOrigins": ["*"],
"AllowedMethods": ["GET"],
"MaxAgeSeconds": 3000,
"AllowedHeaders": ["*"]
}
]
}
}'
}
function tag(){
aws s3api put-bucket-tagging --bucket $CLIENT-$ENV --tagging \
'{
"TagSet": [
{
"Key": "Client",
"Value": "'$CLIENT'"
}
]
}'
}
echo "Creating Buckets, setting CORS Configuration, creating Tags..."
ENV=dev
createbucket
setcors
tag
ENV=production
createbucket
setcors
tag
ENV=staging
createbucket
setcors
tag
echo "Completed!"