通过遵循这里的示例从浏览器将照片上传到亚马逊S3,我可以将文件从浏览器上传到S3桶。但是,当我试图通过添加以下语句将策略修改得更具体时,我会得到一个访问拒绝错误:
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::[MY_BUCKET]/${cognito-identity.amazonaws.com:sub}",
"arn:aws:s3:::[MY_BUCKET]/${cognito-identity.amazonaws.com:sub}*"
]
}但是,下面的语句确实允许我上传到桶中:
{
"Effect": "Allow",
"Action": [
"*"
],
"Resource": [
"arn:aws:s3::[MY_BUCKET]/${cognito-identity.amazonaws.com:sub}",
"arn:aws:s3:::[MY_BUCKET]/${cognito-identity.amazonaws.com:sub}*"
]
}我使用联邦登录登录我的用户,并将它们放置到AWS标识池中。包含上述代码的策略由身份池的身份验证角色承担。我已经确认这个身份ID存在于我的身份池中。我所有的研究都告诉我,我应该能够对我的行为更加具体,所以我不知道这里出了什么问题。
编辑:
我意识到,首先知道这些文件是如何进入桶中的,这可能是有用的。我使用npm的aws和下面的代码将图像文件上传到桶中:
return new Promise(function (resolve, reject) {
const fileName = userId + '/' + utilities.getGUID();
s3.upload({
Key: fileName,
Body: file,
ACL: 'public-read'
}, function (err, data) {
if (err) {
dropzoneUtilities.setDropzoneFileCanceled(file);
console.log(err);
reject(err);
}
else {
dropzoneUtilities.setDropzoneFileComplete(file);
dropzoneUtilities.removeFile(file);
resolve({ data, name: file.name});
}
});
});发布于 2016-11-13 02:28:21
请在上传代码中注意这一点:
ACL: 'public-read'在这一点上,文档并不是明确的,但是包括这一点需要s3:PutObjectAcl权限。
http://docs.aws.amazon.com/AmazonS3/latest/dev/using-with-s3-actions.html#using-with-s3-actions-related-to-objects
https://stackoverflow.com/questions/40568803
复制相似问题