Skip to content

Instantly share code, notes, and snippets.

@ThabetAmer
Created October 5, 2020 09:34
Show Gist options
  • Save ThabetAmer/e5a65a1b44d96863b9854eaa6bb8de21 to your computer and use it in GitHub Desktop.
Save ThabetAmer/e5a65a1b44d96863b9854eaa6bb8de21 to your computer and use it in GitHub Desktop.
AWS S3 bash script to make recent objects uploaded by other owners publicly accessible
#!/bin/bash
BUCKET=
PROFILE_OTHER=
PROFILE_MINE=
DATE=$(date +%Y-%m-%dT%H:00:00)
IFS=$'\t'
for KEY in $(aws --profile $PROFILE_MINE s3api list-objects --bucket $BUCKET --query 'Contents[?LastModified>="'$DATE'"][].Key' --output text)
do
echo $KEY
# grant access to the account holder
aws --profile $PROFILE_OTHER s3api put-object-acl --bucket $BUCKET --key "$KEY" --acl bucket-owner-full-control
# make the object public
aws --profile $PROFILE_MINE s3api put-object-acl --bucket $BUCKET --key "$KEY" --acl public-read
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment