在账户 A 中,我使用 cloudformation 创建了一个 s3 存储桶,CodeBuild 构建了一个工件并上传到该存储桶。在账户 B 中,我尝试使用 cloudformation 创建堆栈,并使用账户 A 存储桶中的工件来部署我的 Lambda 函数。但是,我收到拒绝访问错误。有谁知道解决方案吗?谢谢...
"TestBucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"Properties": {
"AccessControl": "BucketOwnerFullControl"
}
},
"IAMPolicy": {
"Type": "AWS::S3::BucketPolicy",
"Properties": {
"Bucket": {
"Ref": "TestBucket"
},
"PolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::xxxxxxxxxxxx:root",
"arn:aws:iam::xxxxxxxxxxxx:root"
]
},
"Action": [
"s3:GetObject"
],
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "TestBucket"
},
"/*"
]
]
},
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "TestBucket"
}
]
]
}
]
}
]
}
}
}
最佳答案
假设下面语句中的xxxxx是账户B的账号:
"AWS": [
"arn:aws:iam::xxxxxxxxxxxx:root",
"arn:aws:iam::xxxxxxxxxxxx:root"
]
您是说此存储桶根据账户 B 在账户 B IAM 服务中持有的 IAM 权限/策略向账户 B 授予访问权限。
因此,基本上所有具有显式 S3 访问权限的用户/实例配置文件/策略都将能够访问账户 A 的此存储桶。这意味着您附加到账户 B 中的 lambda 角色的 IAM 策略可能无法访问该存储桶。具有显式 S3 访问权限。
我建议让 S3 访问您的 Lambda 函数,这应该可行。
请注意,将来如果您想从账户 B 写入账户 A 的 S3 存储桶,您必须确保将存储桶所有者完全控制 acl以便所有帐户都可以使用这些对象。
示例:
使用 CLI: $ aws s3api put-object --acl bucket-owner-full-control --bucket my-test-bucket --key dir/my_object.txt --body/path/to/my_object.txt
关于amazon-web-services - S3 存储桶访问被拒绝 [悬而未决],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42080079/