2

我有一个自定义 AMI,在上传中途失败,ec2-upload-bundle但其余项目是通过 AWS 控制面板上传的。但是,这意味着大约一半的存储桶捆绑部分缺少“za-team”受让人,这似乎是 AMI 成功启动所必需的。如何将“za-team”的相关“打开/下载”权限批量应用于存储桶中缺少的文件?

4

1 回答 1

0

由于我是 Ruby 新手,所以我花了一点时间才弄清楚;但是,以下循环遍历存储桶中的所有文件并附加文件上指示的权限。该acl.grant命令的相关 SDK 文档提供了一些关于脚本正在做什么的信息。

#!/usr/bin/ruby

# -----------------------------------------------------------------------------
# This script provides a means of updating all of the files in an S3 bucket to
# have the correct permissions. As this script is effectively throwaway it 
# doesn't do much beyond making sure it runs at least once, however, is worth
# keeping around as a reference in the event the problem arises again.
# -----------------------------------------------------------------------------
require 'rubygems'
require 'aws-sdk'

# The following is the Amazon ID for the za-team group which is used for EC2
# operations in S3 buckets
za_team = '6aa5a366c34c1cbe25dc49211496e913e0351eb0e8c37aa3477e40942ec6b97c'

# Note the configuration points
AWS.config({
  :access_key_id => '[Access Key Here]',
  :secret_access_key => '[Secret Access Key Here]',
})
bucket_name = '[Bucket Name Here]'

# Get the bucket information
s3 = AWS::S3.new
bucket = s3.buckets[bucket_name]

# Update the ACL for each item in the bucket
bucket.objects.each do |object| 
  puts object.key
  acl = object.acl
  acl.grant(:read).
      to(:canonical_user_id => za_team)
  object.acl = acl.to_xml
end
于 2012-08-24T13:53:30.567 回答