Last active
August 7, 2024 10:36
-
-
Save huevos-y-bacon/20e042a02fefbcf9f0a2a998578ba7b7 to your computer and use it in GitHub Desktop.
AWS S3 - Create presigned URLs for every object in a given S3 bucket & output to Markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Generate presigned URLs for every object in a given bucket | |
# Outputs markdown. Preview in IDE and copy to email. | |
# Prereqs: awscli, jq | |
EXPIRY=604800 # in SECONDS | |
BUCKET=$1 | |
OUTFILE=$BUCKET-signed-urls.md | |
echo "" > $OUTFILE | |
IFS=$'\n' | |
if [[ -z $BUCKET ]]; then echo "Specify bucket name, either via \$BUCKET var or via \$1 argument."; exit 1; fi | |
MINUTES=$(expr $EXPIRY / 60) | |
HOURS=$(expr $EXPIRY / 60 / 60) | |
DAYS=$(expr $EXPIRY / 60 / 60 / 24) | |
echo -e "# Presigned URLs for all objects in bucket: $BUCKET\n\n*Validity of $EXPIRY seconds ($MINUTES mins / $HOURS hours / $DAYS days) from $(date)*\n" >> $OUTFILE | |
for i in $(aws s3api list-objects --bucket $BUCKET | jq '.Contents[].Key' -r | grep -v DS_Store); do | |
echo -e "- [${i}]($(aws s3 presign --expires-in ${EXPIRY} "s3://${BUCKET}/${i}"))" >> $OUTFILE | |
done | |
cat $OUTFILE | |
unset IFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment