Question

Difficulty: MediumAWS CodeBuild

An application development team is migrating their continuous integration process to AWS CodeBuild. The build environment needs to compile a Node.js application, install packages, and build a container image. To optimize build performance, the team wants to cache both the downloaded node modules and the intermediate Docker image layers using local caching on the build host.

Which combination of actions must the developer perform to configure the required caching? (Select TWO.)

  1. In the buildspec.yml file, add a cache block specifying the path to the node packages (e.g., node_modules/**/*).Answer
  2. In the CodeBuild project configuration, enable local cache and select both custom cache and Docker layer cache.Answer
  3. C
    In the buildspec.yml file, add the /var/lib/docker directory path to the cache block to preserve intermediate container layers.
  4. D
    Modify the CodeBuild service role's trust policy to allow the Amazon S3 service to write and update cache artifacts.
  5. E
    Configure Systems Manager Parameter Store to store the compressed node package cache, and reference its parameter key in the env block of the buildspec.yml.

Answer

In the buildspec.yml file, add a cache block specifying the path to the node packages (e.g., node_modules/**/*), and in the CodeBuild project configuration, enable local cache and select both custom cache and Docker layer cache.
To cache custom paths such as dependency folders, the developer must specify the target directory in the buildspec.yml cache block. To use local host caching for both custom buildspec paths and intermediate Docker layers, the developer must also configure local cache in the project settings, explicitly enabling the custom cache and Docker layer cache types.

Step-by-Step Solution

1
Configure the buildspec file to define the custom folder to be cached.
A cache section is added to the buildspec.yml with the path 'node_modules/**/*'.
This instructs CodeBuild's caching mechanism which files to look for and package at the end of a build.
2
Configure the CodeBuild project's local caching behavior.
The project is configured to use local caching with 'Custom cache' and 'Docker layer cache' enabled.
This tells CodeBuild to store the custom path specified in buildspec.yml and intermediate Docker layers locally on the build host rather than uploading them to S3.

Key Concept

AWS CodeBuild Caching Configurations
Estimated Time:2m 0s
Rate this question