gpt4 book ai didi

ruby - 如何授予对 S3 存储桶文件的批量权限?

转载 作者:太空宇宙 更新时间:2023-11-03 16:55:08 32 4
gpt4 key购买 nike

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

最佳答案

由于我是 Ruby 的新手,这花了我一些时间才弄明白;但是,以下循环遍历存储桶中的所有文件并附加文件上指示的权限。 acl.grant command上的相关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

关于ruby - 如何授予对 S3 存储桶文件的批量权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12110436/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com