Skip to content

Instantly share code, notes, and snippets.

@phainamikaze
Last active December 8, 2023 10:04
Show Gist options
  • Save phainamikaze/0a2458eed8b62ad23c471238fcadc4dd to your computer and use it in GitHub Desktop.
Save phainamikaze/0a2458eed8b62ad23c471238fcadc4dd to your computer and use it in GitHub Desktop.
Challenge Lab: Amazon S3
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": [
"arn:aws:s3:::<bucket-name>/file1.txt",
"arn:aws:s3:::<bucket-name>/file2.txt"
]
}
]
}
aws s3api create-bucket --bucket <bucket-name> --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2
mkdir files
touch files/file1.txt
touch files/file2.txt
touch files/file3.txt
echo "file1 content" > files/file1.txt
echo "file2 content" > files/file2.txt
echo "file3 content" > files/file3.txt
aws s3 sync files s3://<bucket-name>
### set public access block
aws s3api put-public-access-block --bucket <bucket-name> --public-access-block-configuration "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"
## set bucket policy
aws s3api put-bucket-policy --bucket <bucket-name> --policy file://policy1.json
### s3 url
https://<bucket-name>.s3.<region>.amazonaws.com/<object-key>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment