这是我第一次设置Gulp任务进行发布,并且我第一次使用AWS进行更深入的工作,而不仅仅是使用已经由其他人设置的内容。
我调用任务时得到的错误是AccessDenied: Access Denied
,我的代码是:
gulp.task('publish-staging', function() {
var publisher = awspublish.create({
params: {
Bucket: 'my-bucket',
key: 'mykey',
secret: 'mysecret',
region: 'myregion'
}
});
var headers = {
'Cache-Control': 'max-age=315360000, no-transform, public',
'Content-Encoding': 'gzip'
};
return gulp.src('build/**')
.pipe(awsPubRouter({
routes: {
'^index\\.html$': {
headers: Object.assign({}, headers, { 'Cache-Control': 'no-cache' })
},
'^.+$': { headers: headers }
}
}))
.pipe(awspublish.gzip())
.pipe(parallelize(publisher.publish(), 10))
.pipe(awspublish.reporter());
});
我的桶政策是:
{
"Version": "2012-10-17",
"Id": "Policy1529361802241",
"Statement": [
{
"Sid": "statement-id-1",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::848046242589:user/[email protected]"
},
"Action": "s3:*",
"Resource": "arn:aws:s3:::my-bucket/*"
},
{
"Sid": "statement-id-2",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-bucket/*"
},
{
"Sid": "statement-id-3",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:PutObjectAcl",
"Resource": "arn:aws:s3:::my-bucket/*"
}
]
}
这有什么明显的错误,或者问题可能在其他地方吗?
也许它与Bucket的“公共访问设置”有关。
尝试解开“阻止新的公共ACL和上传公共对象”和“删除通过公共ACL授予的公共访问权限”,如下所示: