如何让用户上传文件到S3存储桶,但不能覆盖或删除?

我有一个用户的以下IAM策略

{ "Version": "2012-10-17", "Statement": [ { "Sid": "Stmt1395161912000", "Effect": "Allow", "Action": [ "s3:ListBucket", "s3:PutObject", "s3:*" ], "Resource": [ "arn:aws:s3:::bucketname" ] }, { "Sid": "list", "Effect": "Allow", "Action": [ "s3:ListAllMyBuckets" ], "Resource": [ "arn:aws:s3:::*" ] } ] } 

目标是让用户将file upload到存储桶,但不能覆盖或删除。 这是为了备份。 我开始与ListBucketPutObject ,但添加*因为它不工作。 甚至没有*让用户上传文件,只是得到Access Denied

当我尝试模拟器,它会返回Denied - Implicitly denied (no matching statements found).ListBucket ,这似乎很奇怪,因为我已经隐式允许。

我已经尝试了Cyber​​duck和3Hub作为S3客户端。

任何想法有什么不对?

为Amazon S3制定Amazon IAM策略时,需要了解服务操作 (例如ListAllMyBuckets ), 操作桶 (例如ListBucket )和操作对象 (例如GetObject )之间的区别。

具体而言,您的策略的Resource规范需要根据以下模式来处理适当的目标实体(请参阅各种Amazon S3示例策略 ):

  • 服务运营 – arn:aws:s3:::*
  • 对桶的操作 – arn:aws:s3:::<bucket>
  • 对象操作 – arn:aws:s3:::<bucket>/<object>

您遇到Access Denied ,因为您已经为PutObject指定了存储桶级别资源,这需要像arn:aws:s3:::<bucket>/*这样的对象级资源规范,因此,以下策略应涵盖您的示例使用案件:

 { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:ListAllMyBuckets" ], "Resource": [ "arn:aws:s3:::*" ] }, { "Effect": "Allow", "Action": [ "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::bucketname" ] }, { "Effect": "Allow", "Action": [ "s3:PutObject" ], "Resource": [ "arn:aws:s3:::bucketname/*" ] } ] }