Amazon added the ability to 'copy' a key within or between S3 buckets.

This functionality can also be used to change the metadata of an object too.

For example, using the thin-layer commands in Project AwsSum, you can do things like:

 $ s3-rad -b mybucket -k NewKey.jpg -K FromKey.jpg

As I said, you can also copy between buckets (so long as they are in the same location, either the States or Europe currently):

 $ s3-rad -b mybucket -B frombucket -k key.jpg

As you can see, you have to specify a destination bucket and key but you may leave off the source bucket and/or key. While the Amazon API requires everything, my S3 library fills in the blanks.

If you try to copy a key onto itself hwoever, you'll get an error back from Amazon:

 $ s3-rad copy -b mybucket -k image.jpg
 InvalidRequest: The Source and Destination may not be the same when the MetadataDirective is Copy.

but you are allowed to do this if all you want to do is change the metadata, in this case, the Content-Type:

 $ s3-rad copy -b mybucket -k image.jpg -m REPLACE -c 'image/jpg

Whilst the CopyObject operation in S3 is still beta, there has been much discussion about it on the AWS forums and I suspect the API will be final now.

Note: for those using s3bak you can now add a DefaultBucket to your ~/.awssum config file, thanks to a suggestion from Francois.


This post originated on http://chilts.org/.

Email me on andychilton -at- gmail -dot- com.