0

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.

SUBHAS PATIL
  • 176
  • 1
  • 13
  • Does this answer your question? [How to change permission recursively to folder with AWS s3 or AWS s3api](https://stackoverflow.com/questions/46572744/how-to-change-permission-recursively-to-folder-with-aws-s3-or-aws-s3api) – luk2302 Oct 21 '21 at 06:34
  • You have to iterate over all objects and apply the acl change. – Marcin Oct 21 '21 at 06:42

1 Answers1

0
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
                        
                
SUBHAS PATIL
  • 176
  • 1
  • 13
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 25 '21 at 08:02