当您已有 CodeBuild 项目并将其集成到 CodePipeline 管道时,通常会发生这种情况。当您将 Codebuild 项目与 CodePipeline 集成时,该项目将从 CodePipeline Source 输出中检索其源代码。源输出将存储在工件存储位置中,该位置是一个 S3 存储桶,可以是 CodePipeline 创建的默认存储桶,也可以是您在创建管道时指定的存储桶。
因此,您需要向 CodeBuild Service 角色提供访问 S3 中的 CodePipline 存储桶的权限。该角色需要将 S3 对象放入存储桶以及获取对象的权限。
我尝试过的政策同样有效:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CodeBuildDefaultPolicy",
"Effect": "Allow",
"Action": [
"codebuild:*",
"iam:PassRole"
],
"Resource": "*"
},
{
"Sid": "CloudWatchLogsAccessPolicy",
"Effect": "Allow",
"Action": [
"logs:FilterLogEvents",
"logs:GetLogEvents"
],
"Resource": "*"
},
{
"Sid": "S3AccessPolicy",
"Effect": "Allow",
"Action": [
"s3:CreateBucket",
"s3:GetObject",
"s3:List*",
"s3:PutObject"
],
"Resource": "*"
}
]
}
政策模拟器
AWS 参考 https://docs.aws.amazon.com/codebuild/latest/userguide/setting-up.html#setting-up-service-role