【问题标题】:How to apply acl policies using aws s3api to subfolders in S3 bucket如何使用 aws s3api 将 acl 策略应用于 S3 存储桶中的子文件夹
【发布时间】:2021-12-07 22:06:27
【问题描述】:

我在 S3 存储桶中有几个文件夹,我想在其中应用以下策略以及指定路径内的子文件夹。

aws s3api put-object-acl --bucket BUCKET_NAME --key "FOLDER_PATH/" --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers --profile MYPROFILE

我不能在键中使用正则表达式 *,以便它包含所有子文件夹。

帮助我将策略应用到密钥路径内的所有子文件夹。

【问题讨论】:

标签: amazon-web-services amazon-s3 aws-cli aws-policies


【解决方案1】:
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
                        
                

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多