Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update ACL for all S3 objects in a folder with AWS CLI?

As part of an automated process in CodeBuild I want to update Access Control List for all files in a given folder (or more specifically all objects with given prefix). How to do it in a single line of bash code?

like image 349
Lech Migdal Avatar asked Dec 11 '18 14:12

Lech Migdal


People also ask

How do I update my AWS ACL?

AWS Management ConsoleIn the Buckets menu, select the bucket with the object ACLs you would like to modify. In the Objects tab, select an object to update. Select the Permissions tab to view the current ACL for the object. Select Edit to modify the existing ACL.

How do you change the access rights of a particular object in a bucket?

To set ACL permissions for an objectIn the Buckets list, choose the name of the bucket that contains the object. In the objects list, choose the name of the object for which you want to set permissions. Choose Permissions. Under Access control list (ACL), choose Edit.

Can S3 files be updated?

Using Hudi, you can perform record-level inserts, updates, and deletes on S3 allowing you to comply with data privacy laws, consume real time streams and change data captures, reinstate late arriving data and track history and rollbacks in an open, vendor neutral format.


2 Answers

The following one liner works perfectly

aws s3api list-objects --bucket $BUCKET_NAME$ --prefix $FOLDER_NAME$ --query "(Contents)[].[Key]" --output text | while read line ; do aws s3api put-object-acl --acl public-read --bucket $BUCKET_NAME$ --key $line ; done

it's not formatted as code, so that it's readable without scrolling!

like image 194
Lech Migdal Avatar answered Oct 18 '22 23:10

Lech Migdal


You can use aws s3 cp

aws s3 cp --grants foo=bar=baz s3://mybucket/mydir s3://mybucket/mydir

Reference https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html

like image 24
rocketspacer Avatar answered Oct 18 '22 23:10

rocketspacer