Sometimes, we need to copy S3 data between separate AWS accounts. Though Amazon API provides COPY functionality but that is only for buckets under same account.

It seems that if we want to copy data between buckets in different accounts, only option is to download the file to local system and then upload it to destination bucket.

Since bucket names are unique across all S3, we can copy a public-read file to destination bucket (in different account) using COPY. I tested this and it works perfectly.

For copying a private file, we need to temporarily give public-read permission on the file and then COPY it to different AWS accounts. Don’t forget to change permissions for file in source and destination bucket once copy is done.

Also, we don't have to worry about bandwidth charges since COPY operation is internal to AWS. No download of the actual file required.


#!/usr/bin/env ruby

require 'rubygems'
require 'right_aws'

srcBkt = 'SourceTest'
srcKey = 'test.ppt'
destBky = 'DestTest'
destKey = 'test.ppt'

# Put credentials of destination account
s3 ='access_key', 'secret_key)

#We can do a move operation as well if both the accounts are linked
s3.copy(srcBkt, srcKey, destBkt, destKey)
rescue Exception => e
puts e.inspect

Update: Please not that you will be able to COPY public content but can't MOVE (copy + delete) content across different accounts. If these accounts are linked with each other, you can MOVE as well.

Subscribe - To get an automatic feed of all future posts subscribe here, or to receive them via email go here and enter your email address in the box. You can also like us on facebook and follow me on Twitter @akashag1001.