s3api getobject 权限被拒绝

s3api getobject permission denied

我正在尝试使用 aws-cli 从 s3 获取文件

aws s3api get-object --bucket <bucket_name> --key /foo.com/bar/summary-report-yyyymmdd.csv.gz temp_file.csv.gz --profile <profile_name>

但我收到以下错误 -

An error occurred (AccessDenied) when calling the GetObject operation: Access Denied

我已经使用

重新检查了我的配置
aws configure --profile <profile_name>

而且那里的一切似乎都是正确的。我使用相同的凭据在 S3 浏览器上浏览和获取文件,没有任何问题。

文档的用处很小,因为我对该存储桶的访问权限非常有限。我无法验证权限或使用

aws s3 --profile <profile_name> ls

AccessDenied 可能意味着您没有权限,但如果对象不存在则返回错误(您可以阅读 here 了解使用此错误的原因)

您可以使用 aws s3api list-objects 命令(例如

)确保您可以访问存储桶
aws s3api list-objects --bucket <bucket_name> --query 'Contents[].{Key: Key, Size: Size}' --profile <profile_name>

在您的情况下,问题很可能出在密钥

前面的 / 的用户身上
aws s3api get-object --bucket <bucket_name> --key foo.com/bar/summary-report-yyyymmdd.csv.gz temp_file.csv.gz --profile <profile_name>

对我来说,问题是 kms 访问。我发现这很有帮助: https://aws.amazon.com/premiumsupport/knowledge-center/s3-troubleshoot-403/