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.
Code:
#!/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 = RightAws::S3Interface.new('access_key', 'secret_key)
begin
#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
end
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.
This is an excellent article. Your essay is very easy to understand. Thank you for providing us with this useful information.Custom Website Design
This is an excellent website. This is my first visit to this blog, and I think it's amazing. The most important thing is that this blog's information is written in a clear and understandable manner.
Developers On Demand