Skip to content

Instantly share code, notes, and snippets.

@tekbird
Created February 8, 2016 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tekbird/5540ddfd6b11323df4b2 to your computer and use it in GitHub Desktop.
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
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