Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the aws cli to set permissions on files in an S3 bucket?

Tags:

I am new to the aws cli and I've spent a fair amount of time in the documentation but I can't figure out how to set permissions on files after I've uploaded them. So if I uploaded a file with:

aws s3 cp assets/js/d3-4.3.0.js s3://example.example.com/assets/js/

and didn't set access permissions, I need a way to set them. Is there an equivalent to chmod 644 in the aws cli?

And for that matter is there a way to view access permission?

I know I could use the --acl public-read flag with aws s3 cp but if I didn't, can I set access without repeating the full copy command?

like image 202
Amanda Avatar asked Dec 10 '16 01:12

Amanda


People also ask

How do I change permissions on my S3 bucket?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to set permissions for. Choose Permissions. Under Access control list, choose Edit.

Which command is used in CLI to upload a group of files on S3 bucket?

cp --recursive is the command used to copy files recursively to an s3 bucket. You can also use Sync command with the default recursive keyword.


1 Answers

The awscli supports two groups of S3 actions: s3 and s3api.

You can use aws s3api put-object-acl to set the ACL permissions on an existing object.

The logic behind there being two sets of actions is as follows:

  • s3: high-level abstractions with file system-like features such as ls, cp, sync
  • s3api: one-to-one with the low-level S3 APIs such as put-object, head-bucket

In your case, the command to execute is:

aws s3api put-object-acl --bucket example.example.com --key assets/js/d3-4.3.0.js --acl public-read 
like image 139
jarmod Avatar answered Oct 13 '22 07:10

jarmod