How to optimize CodeBuild performance with caching?

A developer has a continuous integration and continuous delivery (CI/CD) pipeline that uses AWS CodeArtifact and AWS CodeBuild. The build artifacts are between 0.5 GB and 1.5 GB in size. The builds happen frequently and retrieve many dependencies from CodeArtifact each time. The builds have been slow because of the time it takes to transfer dependencies. The developer needs to improve build performance by reducing the number of dependencies that are retrieved for each build. Which solution will meet this requirement?

  1. Specify an Amazon S3 cache in CodeBuild. Add the S3 cache folder path to the buildspec.yaml file for the build project.
  2. Specify a local cache in CodeBuild. Add the CodeArtifact repository name to the buildspec.yaml file for the build project.
  3. Specify a local cache in CodeBuild. Add the cache folder path to the buildspec.yaml file for the build project. Source Reference Answer
  4. Retrieve the buildspec.yaml file directly from CodeArtifact. Add the CodeArtifact repository name to the buildspec.yaml file for the build project.

Community Votes

C
100%

100% of anonymous learners picked answer C. Votes are pick records left by other test-takers — they are not the verified answer.

Community Insight

The question tests knowledge of CodeBuild caching modes, specifically distinguishing between S3 and local caches and the correct buildspec configuration (paths vs. repository names).

To improve AWS CodeBuild performance when handling large dependencies from AWS CodeArtifact, developers should implement a local cache. This reduces network transfer time by storing dependencies on the build host for subsequent builds.

Selecting Option B is a common error because while it correctly identifies 'local cache,' it incorrectly suggests adding the repository name to the buildspec instead of the specific cache folder paths.

Community Discussion (4 comments)

Alabi 👍 7 Selected: C
Explanation Using a local cache in CodeBuild allows you to cache dependencies locally on the build host, which can significantly reduce the time it takes to retrieve dependencies during subsequent builds.
Duke315 👍 1 Selected: C
version: 0.2 phases: install: Anyone want cheaper contributor PDF then check certificationtest[.]net Using a local cache in CodeBuild allows you to cache dependencies locally on the build host, which can significantly reduce the time it takes to retrieve dependencies during subsequent builds.
albert_kuo 👍 1 Selected: C
update buildspec.yaml version: 0.2 phases: install: commands: - echo Installing dependencies... - pip install -r requirements.txt build: commands: - echo Build started on date - echo Compiling the Python code... - python setup.py build cache: paths: - '/root/.cache/pip/*/' # dependencies cache
cachac 👍 1 Selected: B
C does not specify how to integrate it with CodeArtifact

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

Expert Analysis

Why the Answer Is Correct

Local caching in CodeBuild stores dependencies on the build environment's storage, which is significantly faster than downloading them over the network from CodeArtifact for every build. By specifying the cache folder path in buildspec.yaml (e.g., /root/.m2 or node_modules), CodeBuild preserves these directories between builds, minimizing download times for the 0.5 GB to 1.5 GB artifacts.

Why the Other Options Are Wrong

Option A suggests an S3 cache, which incurs network latency for uploading and downloading cache archives, making it slower than a local cache for frequent builds. Option B is incorrect because you configure cache paths in the buildspec, not the CodeArtifact repository name; the repository is used in the build commands, not the cache definition. Option D is invalid because buildspec files are sourced from CodeCommit, S3, or GitHub, not CodeArtifact, and this approach does not address dependency caching.

Community Comment Notes

The community strongly supports Option C (90 votes), emphasizing that local caching reduces retrieval time. One comment (Comment [4]) incorrectly argues for Option B, claiming Option C lacks CodeArtifact integration, but caching works based on file paths regardless of the package source. Another comment (Comment [3]) provides a practical example of configuring cache paths for pip dependencies.

Official Reference

Exam Strategy

When asked to improve build speed related to dependencies, immediately look for 'Local Cache' as the preferred solution over S3 cache due to lower latency, provided the build environment supports it.

Related Analysis

Practice All DVA-C02 Questions

Access 100 questions with complete answers and detailed explanations.

View Full DVA-C02 Practice Test →

← Back to DVA-C02 Study Guide