Skip to content

Instantly share code, notes, and snippets.

@jonmabe
Created January 30, 2014 01:11
Show Gist options
  • Save jonmabe/8700764 to your computer and use it in GitHub Desktop.
Save jonmabe/8700764 to your computer and use it in GitHub Desktop.
script to generate a 24hr url to a s3 file given a bucket and key. expects AWS access and secret key to be at $AWS_SECRET_KEY and $AWS_ACCESS_KEY
#!/bin/sh
BUCKET=$1
KEY=$2
#create 24hr user public url
S3EXPIRES=$(($(date +%s) + 24*60*60))
S3STRINGTOSIGN="GET\n\n\n$S3EXPIRES\n/$BUCKET/$KEY\c"
S3SIGNATURE=$(echo "$S3STRINGTOSIGN" | openssl dgst -binary -sha1 -hmac $AWS_SECRET_KEY | openssl base64)
S3SIGNATURE="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$S3SIGNATURE")"
S3URL="https://$BUCKET.s3.amazonaws.com/$KEY?AWSAccessKeyId=$AWS_ACCESS_KEY&Expires=$S3EXPIRES&Signature=$S3SIGNATURE"
echo $S3URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment