amazon-web-services - 如何使用 aws s3api 将 acl 策略应用于 S3 存储桶中的子文件夹
问题描述
我在 S3 存储桶中有几个文件夹,我想在其中应用以下策略以及指定路径内的子文件夹。
aws s3api put-object-acl --bucket BUCKET_NAME --key "FOLDER_PATH/" --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers --profile MYPROFILE
我不能在密钥中使用正则表达式 *,以便它包含所有子文件夹。
帮助我将策略应用于密钥路径内的所有子文件夹。
解决方案
import boto3
import os
def lambda_handler(event, context):
prefix = "folderpath" #folder path without trailing slash (eg foldername1/foldername2 )
bucket = 'bucketnamehere' # S3 bucket name here
s3 = boto3.resource('s3')
bucket = s3.Bucket(name=bucket)
s3_cl = boto3.client('s3')
for obj in bucket.objects.filter(Prefix=prefix):
folders = obj.key
if(folders[-1] == '/'):
print(folders)
# Add ACL policy here
推荐阅读
- angular - 如何使用 Angular 和 ThreeJS 设置 plnkr
- java - BLE Scanner 只显示一条记录
- tensorflow - 如何通过 Tensorflow conv2d 输入批量图像序列
- javascript - 如何使用innerHTML分割字符串的最后一个字符
- r - R只有1个图例的时间序列xts的多个图
- sql - 使用case语句psql更新jsonb中的多个属性
- null - 服务器套接字编程中的 readLine 为空
- php - 运行 phpdbg 分析“实时”代码覆盖率
- c++ - 使用 lambda 编译 constexpr 时出现 MSVS2017 错误“表达式未计算为常量”
- java - FirebaseRecyclerAdapter 类