Courseiva

DOP-C02 Configuration Management and IaC Practice Question

A DevOps team is using AWS CodeBuild to run unit tests and package a Java application. They want to cache the Maven local repository (~/.m2) between builds to improve build times. Which TWO steps are necessary to enable caching in CodeBuild? (Select TWO.)

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

Add a 'cache' section in the buildspec file specifying the paths to cache.

To enable caching for the Maven local repository in AWS CodeBuild, two steps are required: (1) Add a `cache` section in the buildspec file specifying the paths to cache (e.g., ~/.m2) — this is option D. (2) Create an S3 bucket to store the cache and configure the CodeBuild project to use that bucket for caching — this is option E. Option A (setting MAVEN_OPTS) is not necessary because the default Maven repository path is already ~/.m2. Option B (uploading as a build artifact) is for saving output artifacts, not for caching. Option C ('Local cache' mode) is a different feature used for Docker layer caching, not for Maven dependencies. Therefore, options D and E are correct.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    Set the MAVEN_OPTS environment variable to use a custom repository path.

    Why it's wrong here

    Setting MAVEN_OPTS to a custom repository path only changes where Maven writes its local dependencies on the build machine; it does not tell CodeBuild to cache those files across runs. CodeBuild's dependency caching is a separate feature configured in the project or buildspec, and without that configuration, the custom path would be discarded when the build environment is torn down. Environment variables alone cannot persist state.

  • ✗

    Configure the buildspec to upload the Maven repository as a build artifact.

    Why it's wrong here

    Uploading the Maven repository as a build artifact packages it as build output, which is stored after the build and downloaded only when you explicitly retrieve it. Artifacts are not automatically restored to the build environment at the start of a subsequent build, nor do they feed a dependency cache that speeds up resolution. Build artifacts serve a different purpose, such as deployable files, and using them for caching would also pollute the artifact namespace.

  • ✗

    Enable 'Local cache' mode in the CodeBuild project.

    Why it's wrong here

    The 'Local cache' option in a CodeBuild project controls disk-level caching on the build host, primarily for Docker layers, and in general does not persist across separate build runs unless the same build host is reused. It is not designed to cache arbitrary Maven repository content such as ~/.m2, and it does not provide the durable, centralized cache backed by S3 that CodeBuild uses for dependency caching. Relying on the 'Local cache' toggle would not satisfy the requirement to cache the Maven repository.

  • ✓

    Add a 'cache' section in the buildspec file specifying the paths to cache.

    Why this is correct

    Adding a 'cache' section to the buildspec is the correct way to declare which paths CodeBuild should cache. You specify relative or absolute paths, such as /root/.m2, and CodeBuild saves the contents to a configurable S3 cache bucket after the build. On subsequent builds, CodeBuild restores those paths before the build starts, so dependency resolution skips re-downloading artifacts. This is the official mechanism for Maven dependency caching in CodeBuild.

  • ✓

    Create an S3 bucket to store the cache.

    Why this is correct

    Creating an S3 bucket is required because CodeBuild stores the cache in a user-specified S3 bucket, which acts as the durable backing store for cached files. The bucket must be configured in the project's 'Cache' settings, and the cache is stored using a cache key that lets CodeBuild retrieve the correct snapshot for each build. Without the S3 bucket, there is nowhere for CodeBuild to persist the cached Maven repository across builds, so this step is an essential part of the correct solution.

Quick reference

AWS S3 Storage Class Comparison

Storage ClassMin DurationRetrievalUse Case
S3 StandardNoneImmediateFrequently accessed data
S3 Standard-IA30 daysImmediateInfrequent access, rapid retrieval
S3 One Zone-IA30 daysImmediateNon-critical infrequent data
S3 Intelligent-TieringNoneImmediate–hoursUnknown or changing access patterns
S3 Glacier Instant90 daysMillisecondsArchive with instant retrieval
S3 Glacier Flexible90 daysMinutes–hoursArchive, flexible retrieval
S3 Glacier Deep Archive180 daysHoursLong-term compliance archive

About these practice questions

This DOP-C02 question is part of Courseiva's 1,298-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This DOP-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DOP-C02 exam.