简体   繁体   English

如何使用 aws cli 为 S3 存储桶中的文件设置权限?

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

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.我是 aws cli 的新手,我在文档中花了很多时间,但在上传文件后我不知道如何设置文件的权限。 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? aws cli 中是否有等效于chmod 644的内容?

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?我知道我可以将--acl public-read标志与aws s3 cp但如果我不这样做,我可以在不重复完整复制命令的情况下设置访问权限吗?

The awscli supports two groups of S3 actions: s3 and s3api . awscli 支持两组 S3 操作: s3s3api

You can use aws s3api put-object-acl to set the ACL permissions on an existing object.您可以使用aws s3api put-object-acl来设置现有对象的 ACL 权限。

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 s3 :具有类似文件系统功能的高级抽象,例如lscpsync
  • s3api : one-to-one with the low-level S3 APIs such as put-object , head-bucket s3api :与低级 S3 API(例如put-objecthead-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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 AWS CLI 将名称每天更改的文件移动到 AWS S3 存储桶? - How do I move files whose name changes daily to AWS S3 bucket using AWS CLI? AWS s3 rb 在 CLI 中不起作用,如何删除 s3 存储桶中的文件? - AWS s3 rb doesn't work in the CLI, how do I delete files in my s3 bucket? 如何使用 AWS CLI 删除 S3 存储桶中的多个文件 - How to delete multiple files in S3 bucket with AWS CLI 如何使用 AWS CLI 找到我的 AWS S3 存储桶的确切字节数? - How do I find the exact number of bytes of my AWS S3 bucket using AWS CLI? 如何使用 AWS CLI 仅复制 S3 存储桶中与给定字符串模式匹配的文件 - How to use AWS CLI to only copy files in S3 bucket that match a given string pattern 如何使用 AWS CLI 获取包含给定字符串的 S3 存储桶的全名? - How do I get the full name of an S3 bucket which contains a given string using AWS CLI? 如何使用 CLI 删除 AWS S3 中的版本化存储桶? - How do I delete a versioned bucket in AWS S3 using the CLI? 如何设置权限,以便IAM可以使用C#上传到Amazon S3存储桶? - How do I set permissions so an IAM can upload to an Amazon S3 bucket in C#? 如何正确设置S3和IAM以将文件上传到S3存储桶? - How do I set up S3 and IAM properly to upload files to a S3 bucket? 如何将 AWS S3 存储桶与远程非 AWS 服务器上的文件同步? - How do I sync an AWS S3 bucket with files on a remote non-AWS server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM