【问题标题】:copying s3 bucket to another aws account with CarrierWave Ruby gem使用 CarrierWave Ruby gem 将 s3 存储桶复制到另一个 aws 帐户
【发布时间】:2013-03-27 06:53:56
【问题描述】:

我正在尝试将存储桶中的一些内容复制到不同 aws 帐户中的存储桶。我首先将上传器对象加载到哈希中。然后我尝试连接到另一个存储桶并使用该存储桶的凭据保存资产。

    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

【问题讨论】:

  • 我用brew安装s3cmd。为第一个帐户配置它并下载存储桶。为第二个帐户配置它并将内容上传到不同的存储桶。然后登录到 aws web 控制台并选择文件夹,使用操作菜单将内容设置为公开。

标签: ruby amazon-web-services amazon-s3 carrierwave buckets


【解决方案1】:

有时,存储桶将被授予足够的权限,同时确保您拥有足够的图像权限,以便您可以实际下载它们。

我有一个更好的解决方案给你,你可以做的是安装和配置你的 s3cmd 并在两个存储桶之间进行 rsync。这将比你的 ruby​​ on rails 更快。

【讨论】:

  • 感谢您将我指向 s3cmd。我仍然很好奇是否可以在一个脚本或同步中连接到来自不同帐户的两个存储桶。
猜你喜欢
  • 2019-06-28
  • 2012-03-28
  • 2018-11-22
  • 2023-02-01
  • 2020-01-03
  • 2017-07-21
  • 1970-01-01
  • 2020-07-05
  • 1970-01-01
相关资源
最近更新 更多