Created
February 8, 2016 16:39
-
-
Save tekbird/5540ddfd6b11323df4b2 to your computer and use it in GitHub Desktop.
Use this gist to copy an object from one bucket to another from bash
This file contains hidden or 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
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