简体   繁体   中英

How to apply acl policies using aws s3api to subfolders in S3 bucket

I have few folders in S3 bucket where I want to apply the below policy and also to the subfolders inside the specified path.

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

I cannot use regex * in the key so that it includes all subfolders.

Help me apply the policy to all subfolders inside the key path.

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
                        
                

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM