Soru

Zorluk: KolayIAM Policies and Roles

A developer is setting up an AWS CodeBuild project that needs to upload build artifacts to an Amazon S3 bucket named `app-build-artifacts-2026`. The project fails with an authorization error during the build phase. The developer reviews the IAM role created for CodeBuild, which currently has no permissions policies attached, and has the following trust policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}

Which two changes are required to allow the CodeBuild project to upload artifacts to the S3 bucket? (Select TWO.)

  1. Update the Service principal in the trust policy to codebuild.amazonaws.com.Cevap
  2. Attach a permissions policy to the role that allows s3:PutObject on the resource arn:aws:s3:::app-build-artifacts-2026/*.Cevap
  3. C
    Change the Service principal in the trust policy to s3.amazonaws.com.
  4. D
    Add s3:PutObject to the Action array inside the existing trust policy statement.
  5. E
    Hardcode the AWS access key and secret access key of an administrator IAM user within the build command script.

Cevap

The correct changes are to update the Service principal in the trust policy to codebuild.amazonaws.com, and to attach a permissions policy to the role that allows s3:PutObject on the resource arn:aws:s3:::app-build-artifacts-2026/*.
Updating the Service principal to codebuild.amazonaws.com allows CodeBuild to assume the execution role. Attaching a policy allowing s3:PutObject on arn:aws:s3:::app-build-artifacts-2026/* grants the required write permissions on the bucket's objects.

Adım Adım Çözüm

1
Inspect and fix the trust relationship of the IAM role.
The Service principal is changed from ec2.amazonaws.com to codebuild.amazonaws.com, allowing CodeBuild to assume the role.
Since CodeBuild is running the build process, it needs permission to assume the IAM role associated with the project.
2
Create and attach a permissions policy for S3 write access.
A policy containing s3:PutObject for the resource arn:aws:s3:::app-build-artifacts-2026/* is attached to the role.
The role currently has no permissions policies, so it has no rights to perform S3 actions. Adding this policy permits uploading objects to the bucket.

Anahtar Kavram

An IAM role must have a trust policy allowing the executing AWS service principal to assume it, and a permissions policy granting the specific API access needed for resources.
Bu soruyu puanla