Soru

Zorluk: OrtaAWS CodeBuild

A developer is configuring an AWS CodeBuild project to build a Docker image and push it to an Amazon Elastic Container Registry (ECR) repository. The CodeBuild project is configured to run inside a private VPC subnet to access internal databases. During the build execution, CodeBuild fails to pull the public base image from Docker Hub and fails to authenticate with the Amazon ECR repository. Which TWO actions should the developer take to resolve these issues?

  1. Configure a NAT Gateway in a public subnet of the VPC, and update the route table of the CodeBuild private subnet to route outbound traffic through the NAT Gateway.Cevap
  2. Add the ecr:GetAuthorizationToken permission and repository permissions (such as ecr:BatchCheckLayerAvailability and ecr:PutImage) to the IAM service role associated with the CodeBuild project.Cevap
  3. C
    Store the registry login credentials in Systems Manager Parameter Store and reference them in the secrets-manager section of the env block in the buildspec file.
  4. D
    Modify the trust policy of the Amazon ECR repository to allow the CodeBuild service principal to directly write to the registry.
  5. E
    Place the buildspec.yml file in a subdirectory named docker/ within the source repository to allow the Docker daemon to locate the build instructions.

Cevap

The developer should configure a NAT Gateway to allow internet access for CodeBuild's private subnet, and attach the required ECR permissions to the CodeBuild service role.
Routing outbound traffic through a NAT Gateway enables the CodeBuild container inside the private subnet to connect to the public Docker Hub registry. Additionally, attaching ECR permissions to the service role allows the build container to authenticate and push the compiled Docker image to Amazon ECR.

Adım Adım Çözüm

1
Analyze the network route for pulling external dependencies.
CodeBuild requires internet access to pull base images from public Docker Hub. Since CodeBuild is running in a private VPC subnet, a NAT Gateway must be configured in a public subnet to forward this outbound traffic.
Resolves the connection failure when attempting to pull the public base image.
2
Analyze IAM role permissions for ECR authentication and upload.
The CodeBuild project's service role needs permission to fetch an authorization token from ECR (ecr:GetAuthorizationToken) and perform repository write actions.
Resolves the authentication and push authorization failures when interacting with Amazon ECR.

Anahtar Kavram

AWS CodeBuild VPC routing and ECR IAM permissions
Bu soruyu puanla