A developer is setting up an AWS CodeBuild project to automate a build pipeline. The project is configured to use a custom service role named CodeBuildServiceRole to access AWS resources. However, when starting a build run, the build fails immediately during the provisioning phase with the following error:
Failed to assume role: CodeBuild is not authorized to perform: sts:AssumeRole on the role CodeBuildServiceRole
The developer examines the trust policy for CodeBuildServiceRole, which contains the following JSON document:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Which modification should the developer make to the trust policy to resolve this error?
- AAttach an IAM permissions policy to the role that grants the sts:AssumeRole action to codebuild.amazonaws.com.
- Change the Service principal in the trust policy statement from ec2.amazonaws.com to codebuild.amazonaws.com.Answer
- CConfigure the buildspec.yml file to define temporary AWS access keys and secret keys under the environment variables section.
- DModify the Principal element of the trust policy to use "AWS": "codebuild.amazonaws.com" instead of the Service block.