A developer is setting up a new AWS CodeBuild project to compile an application. The developer creates an IAM role named CodeBuildServiceRole to serve as the service role for the project and attaches policies allowing access to Amazon S3 and Amazon CloudWatch Logs. However, when the developer attempts to start the build run, it fails immediately with the following error:
CodeBuild is not authorized to perform: sts:AssumeRole on arn:aws:iam::123456789012:role/CodeBuildServiceRole
What action should the developer take to resolve this authorization failure?
- Update the trust policy of CodeBuildServiceRole to allow the codebuild.amazonaws.com service principal to perform the sts:AssumeRole action.Cevap
- BAdd a statement to the IAM permissions policy attached to CodeBuildServiceRole that allows the sts:AssumeRole action.
- CDefine the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables inside the buildspec.yml file to authorize CodeBuild.
- DConfigure an Amazon Cognito Identity Pool to authenticate the CodeBuild agent and provide temporary security credentials.
Cevap
Update the trust policy of the IAM service role to allow the CodeBuild service principal (codebuild.amazonaws.com) to assume the role.
The error indicates that the AWS CodeBuild service itself is not authorized to assume the role specified. For an AWS service to assume an IAM role, the role's trust policy (trust relationship) must explicitly grant 'sts:AssumeRole' permission to the service principal, in this case, 'codebuild.amazonaws.com'. Updating the trust policy resolves this failure.
Adım Adım Çözüm
Anahtar Kavram
IAM Service Role Trust Policies