我正在将资源策略文档添加到 S3 存储桶。
当我创建一个新的 Bucket 时它工作正常:
const newbucket = new s3.Bucket(this, 'newBucket', {
websiteIndexDocument : 'index.html',
bucketName : 'NewBucket'
});
newbucket.addToResourcePolicy(new iam.PolicyStatement({
effect : iam.Effect.ALLOW,
actions: ['s3:*'],
resources: [newbucket.arnForObjects('*')],
principals: [new iam.AnyPrincipal],
}));
newbucket.addToResourcePolicy(new iam.PolicyStatement({
effect : iam.Effect.DENY,
actions: ['s3:*'],
resources: [newbucket.arnForObjects('*')],
principals: [new iam.AnyPrincipal],
conditions : {
'NotIpAddress' : {
'aws:SourceIp' : '***.***.***.***'
}
}
}));
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试获取已经存在的存储桶并添加策略文档,则它不起作用:
const existingbucket = Bucket.fromBucketAttributes(this, 'ImportedBucket',{
bucketName :'ExistingBucket'
})
existingbucket.addToResourcePolicy(new iam.PolicyStatement({
effect : iam.Effect.ALLOW,
actions: ['s3:*'],
resources: [existingbucket.arnForObjects('*')],
principals: [new iam.AnyPrincipal],
}));
Run Code Online (Sandbox Code Playgroud)
不会添加资源策略文档。 …