将s3存储桶复制到另一个aws帐户CarrierWave Ruby gem
问题描述:
我试图将一些内容从存储桶复制到另一个aws帐户中的存储桶。我首先将上传对象加载到散列中。然后我尝试连接到另一个存储桶并使用该存储桶的凭据保存资产。将s3存储桶复制到另一个aws帐户CarrierWave Ruby gem
task :product_color_images => :environment do
CarrierWave.configure do |c|
c.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['COPY_FROM_AWS_KEY_ID'],
:aws_secret_access_key => ENV['COPY_FROM_AWS_KEY']
}
c.fog_directory = 'orig-bucket' # bucket copied from
end
image_storage = {}
ProductImage.all.each do |image|
puts 'storing product image'
image_storage[image.id] = image.image
end
CarrierWave.configure do |c|
c.reset_config
c.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['COPY_TO_AWS_KEY_ID'],
:aws_secret_access_key => ENV['COPY_TO_AWS_KEY']
}
c.fog_directory = 'target-bucket' # bucket copied to
end
image_storage.each do |k, v|
image = ProductImage.find(k)
image.image = v
puts 'saving product image'
image.save
end
end
试图从一个桶保存单个图像到另一在控制台表明未使用的靶桶的地址。
ruby-1.9.2-p290 :026 > image = ProductImage.find(197)
ruby-1.9.2-p290 :027 > image.image = image_storage[197]
=> https://orig-bucket.s3.amazonaws.com/uploads/product_image/image/197/product_image.png
ruby-1.9.2-p290 :028 > image.save
ruby-1.9.2-p290 :029 > image.image
=> https://orig-bucket.s3.amazonaws.com/uploads/product_image/image/197/product_image.png
答
SOmetimes它发生的时候,桶会给予足够的权限也确保您有足够的权限给图像,以便您可以实际下载它们。
我有一个更好的解决方案,你可以做的是安装和配置你的s3cmd并在两个桶之间做一个rsync。这会让你的红宝石在轨道上更快。
+0
感谢您将我指向s3cmd。我仍然很好奇,如果有可能连接到脚本中的不同帐户的两个桶或同步。 – schwabsauce 2013-03-29 00:03:00
我用brew来安装s3cmd。 配置为第一个帐户并下载了存储桶。 将其配置为第二个帐户并将内容上载到不同的存储桶。 然后登录到aws Web控制台并选择文件夹,使用操作菜单将内容设置为公开。 – schwabsauce 2013-03-29 00:03:15