Skip to content

Instantly share code, notes, and snippets.

@ThabetAmer
Created February 3, 2020 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThabetAmer/bed6bf4c87abb8c229db0c0edac5b015 to your computer and use it in GitHub Desktop.
Save ThabetAmer/bed6bf4c87abb8c229db0c0edac5b015 to your computer and use it in GitHub Desktop.
Creating AWS S3 Bucket with bash and awscli
AWS_BUCKET="xyz"
AWS_REGION="eu-central-1"
AWS_ID="11111111111"
AWS_USER="s3-user"
# TODO: review access
cat > policy.json << EOL
{
"Version": "2012-10-17",
"Id": "Policy1554206237047",
"Statement": [
{
"Sid": "Stmt1554206230901",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::${AWS_ID}:user/${AWS_USER}",
"arn:aws:iam::${AWS_ID}:root"
]
},
"Action": [
"s3:GetObject",
"s3:GetObjectAcl",
"s3:ListBucket",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::${AWS_BUCKET}",
"arn:aws:s3:::${AWS_BUCKET}/*"
]
}
]
}
EOL
aws s3api create-bucket --bucket $AWS_BUCKET --region $AWS_REGION --acl private --create-bucket-configuration LocationConstraint=$AWS_REGION
aws s3api put-bucket-policy --bucket $AWS_BUCKET --policy file://policy.json
rm -f policy.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment