-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_s3_bucket.sh
executable file
·24 lines (18 loc) · 1.08 KB
/
create_s3_bucket.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
#!/usr/bin/env bash
set -e;
if [ -z "${AWS_REGION}" ]; then read -e -p "Please enter your AWS region [eu-west-1]: " inAwsRegion; else export inAwsRegion=$AWS_REGION; fi
if [ -z "$1" ]; then read -e -p "Please enter the AWS s3 bucket name: " inAwsS3BucketName; else export inAwsS3BucketName=$1; fi
awsRegion="${inAwsRegion:-eu-west-1}"
awsS3BucketName="${inAwsS3BucketName}"
set +e;
bucketstatus=$(aws s3api head-bucket --bucket ${awsS3BucketName} 2>&1)
if echo ${bucketstatus} | grep 'Not Found'; then
echo "creating bucket ${awsS3BucketName} ......."
aws s3 mb s3://${awsS3BucketName} --region "${awsRegion}"
echo "enabling versioning for ${awsS3BucketName} ......"
aws s3api put-bucket-versioning --region "${awsRegion}" --bucket "${awsS3BucketName}" --versioning-configuration "Status=Enabled"
echo "enabling encryption for ${awsS3BucketName} ......"
aws s3api put-bucket-encryption --bucket "${awsS3BucketName}" --server-side-encryption-configuration '{"Rules": [{"ApplyServerSideEncryptionByDefault": {"SSEAlgorithm": "AES256"}}]}'
else
echo "Bucket ${awsS3BucketName} exists";
fi