Skip to content

Instantly share code, notes, and snippets.

@tekbird tekbird/s3copy.sh
Created Feb 8, 2016

Embed
What would you like to do?
Use this gist to copy an object from one bucket to another from bash
s3key=your key
s3secret=your secret
function putS3
{
object=$1
sourceBucket='bucket'
destinationBucket='bucket'
date=$(date +"%a, %d %b %Y %T %z")
string="PUT\n\n\n$date\nx-amz-copy-source:/$sourceBucket/$object\n/$destinationBucket/$object"
echo "$string"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${s3secret}" -binary | base64)
echo "$signature"
curl -X PUT \
-H "Host: $destinationBucket.s3.amazonaws.com" \
-H "Date: $date" \
-H "x-amz-copy-source: /$sourceBucket/$object" \
-H "Authorization: AWS ${s3key}:$signature" \
"https://$destinationBucket.s3.amazonaws.com/$object"
}
putS3 "your object"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.