Question

Difficulty: MediumAWS CodeBuild

A development team has configured an AWS CodeBuild project to run inside a private subnet of a VPC. During the build execution, the project fails because it cannot download external package dependencies from the internet. Additionally, subsequent runs are taking a long time because the dependencies are fully downloaded from scratch each time. Which two actions should the developer take to resolve the internet connectivity issue and speed up the builds? (Select TWO.)

  1. Configure a NAT gateway in a public subnet of the VPC, and update the private subnet's route table to route 0.0.0.0/00.0.0.0/0 traffic through the NAT gateway.Answer
  2. Enable local dependency caching in the CodeBuild project settings, and specify the package manager's cache directory in the `cache` section of the `buildspec.yml` file.Answer
  3. C
    Move the `buildspec.yml` file into a subdirectory named `.ebextensions` at the root of the source directory to automatically enable caching.
  4. D
    Add a trust policy to the CodeBuild service role that explicitly allows Systems Manager Parameter Store to assume the role and push cached dependencies.
  5. E
    Configure AWS Secrets Manager to store the compiled dependency binaries as secrets to enable automatic encryption and rotation between builds.

Answer

Configure a NAT gateway in a public subnet of the VPC, update the private subnet's route table to route traffic through the NAT gateway, enable local dependency caching in CodeBuild, and define the cache directories in the cache section of the buildspec file.
To resolve the issues, the developer must configure a NAT gateway in a public subnet and route outbound traffic from the private subnet to it. This provides the necessary internet access for CodeBuild to download external dependencies. Additionally, the developer must enable local caching in CodeBuild and define the target cache paths in the buildspec file. This ensures that dependencies are reused across builds instead of being downloaded from scratch.

Step-by-Step Solution

1
Address the outbound internet connectivity problem for resources inside the private subnet of the VPC.
Create a NAT gateway in a public subnet, and configure a route pointing 0.0.0.0/00.0.0.0/0 traffic to it in the private subnet's route table.
CodeBuild containers inside a private subnet cannot directly reach the internet to download external dependencies without a NAT gateway.
2
Implement a caching mechanism to avoid downloading dependencies from scratch on every run.
Configure local caching in CodeBuild project properties and add the cache directories (such as package manager cache folders) to the cache phase of the buildspec file.
This allows CodeBuild to persist downloaded files between build runs, significantly speeding up execution times.

Key Concept

AWS CodeBuild VPC network routing and local dependency caching configurations
Rate this question