Skip to main content

AWS DVA-C02 Drill: CodeBuild Caching - Local vs. S3 Cache for Dependency Optimization

Jeff Taakey
Author
Jeff Taakey
21+ Year Enterprise Architect | AWS SAA/SAP & Multi-Cloud Expert.

Jeff’s Note
#

Jeff’s Note
#

“Unlike generic exam dumps, ADH analyzes this scenario through the lens of a Real-World Lead Developer.”

“For DVA-C02 candidates, the confusion often lies in understanding the practical difference between local and S3 caching in CodeBuild, and specifically what to cache. In production, this is about knowing exactly which buildspec.yaml directives map to which cache types and what artifacts they preserve. Let’s drill down.”

The Certification Drill (Simulated Question)
#

Scenario
#

FinServ Analytics is a financial technology company that processes large datasets. Their development team uses a CI/CD pipeline powered by AWS CodeBuild and stores proprietary Python libraries in AWS CodeArtifact. Each build job downloads between 0.5 GB and 1.5 GB of dependencies from their private CodeArtifact repository. The team runs builds multiple times per hour across different feature branches, and developers have complained that build times are averaging 12-15 minutes, with most time spent re-downloading the same dependencies repeatedly.

As the Lead Developer, you’ve been tasked with implementing a caching strategy that minimizes redundant dependency downloads without modifying the application code or dependency management configuration.

The Requirement:
#

Reduce build times by caching dependencies between CodeBuild executions while maintaining compatibility with the existing buildspec.yaml structure.

The Options
#

  • A) Specify an Amazon S3 cache in CodeBuild. Add the S3 cache folder path to the buildspec.yaml file for the build project.
  • B) Specify a local cache in CodeBuild. Add the CodeArtifact repository name to the buildspec.yaml file for the build project.
  • C) Specify a local cache in CodeBuild. Add the cache folder path to the buildspec.yaml file for the build project.
  • D) Retrieve the buildspec.yaml file directly from CodeArtifact. Add the CodeArtifact repository name to the buildspec.yaml file for the build project.

Correct Answer
#

Option C.

Quick Insight: The Build Performance Imperative
#

For DVA-C02, understanding cache types in CodeBuild is critical. Local caching uses Docker layer caching and custom cache directories, while S3 caching uploads/downloads from S3 buckets. The key is knowing what to specify in the cache section of buildspec.yaml and that you must explicitly define the paths to cache, not service names.

Content Locked: The Expert Analysis
#

You’ve identified the answer. But do you know the implementation details that separate a Junior from a Senior?


The Expert’s Analysis
#

Correct Answer
#

Option C: Specify a local cache in CodeBuild. Add the cache folder path to the buildspec.yaml file for the build project.

The Winning Logic
#

This solution is correct because:

  • Local Cache Mechanism: CodeBuild’s local cache stores build artifacts on the build instance itself, making retrieval significantly faster than downloading from external services (including S3).
  • Cache Paths in buildspec.yaml: The cache section requires explicit directory paths where dependencies are stored (e.g., /root/.m2, /root/.npm, or custom pip cache directories like /root/.cache/pip).
  • API-Level Implementation: When configuring the CodeBuild project via the AWS SDK or CLI, you use:
    "cache": {
      "type": "LOCAL",
      "modes": ["LOCAL_CUSTOM_CACHE"]
    }
    
  • buildspec.yaml Syntax: The corresponding buildspec.yaml entry looks like:
    cache:
      paths:
        - '/root/.cache/pip/**/*'
        - '/tmp/dependencies/**/*'
    
  • Performance Impact: Local caching can reduce build times by 40-70% for dependency-heavy projects because it eliminates network I/O for already-downloaded packages.

The Trap (Distractor Analysis):
#

  • Why not Option A? S3 caching is a valid CodeBuild feature, but it introduces additional network latency (upload to S3 after build, download before next build). For frequently-run builds with large dependencies, the S3 transfer overhead can negate performance gains. S3 caching is better suited for cross-environment sharing (e.g., sharing cache across multiple AWS accounts).

  • Why not Option B? This is technically nonsensical. CodeBuild cache configuration requires file system paths, not service names. Adding “CodeArtifact repository name” to the cache section would result in a buildspec.yaml validation error. The cache mechanism doesn’t integrate with CodeArtifact directly—it caches the output (downloaded dependencies), not the source.

  • Why not Option D? Storing buildspec.yaml in CodeArtifact violates the service’s purpose (it’s a package repository, not a configuration management tool). CodeBuild expects buildspec.yaml from the source repository (CodeCommit, GitHub, etc.) or inline in the project definition. This option completely misunderstands CodeBuild’s configuration model.


The Technical Blueprint
#

# buildspec.yaml with LOCAL cache configuration
version: 0.2

phases:
  install:
    runtime-versions:
      python: 3.11
    commands:
      - pip install awscli
      - aws codeartifact login --tool pip --repository my-repo --domain my-domain --domain-owner 123456789012
  build:
    commands:
      - pip install -r requirements.txt --cache-dir /root/.cache/pip
      - python -m pytest tests/

cache:
  paths:
    - '/root/.cache/pip/**/*'
    - '/root/.m2/**/*'  # If using Maven
    - 'node_modules/**/*'  # If using npm

Corresponding AWS CLI configuration:

aws codebuild update-project \
  --name my-build-project \
  --cache type=LOCAL,modes=LOCAL_CUSTOM_CACHE \
  --region us-east-1

Key API Parameters (boto3 example):

import boto3

client = boto3.client('codebuild')

response = client.update_project(
    name='my-build-project',
    cache={
        'type': 'LOCAL',
        'modes': ['LOCAL_CUSTOM_CACHE']
    }
)

The Comparative Analysis
#

Option API Complexity Performance Impact Network I/O Use Case Exam Relevance
A (S3 Cache) Medium (requires S3 bucket + IAM permissions) Moderate improvement (30-50%) High (upload/download to S3) Cross-account cache sharing, infrequent builds Valid but suboptimal for this scenario
B (Local + Repo Name) N/A (Invalid configuration) None (fails validation) N/A None - this is a distractor Tests understanding of cache vs. source configuration
C (Local + Paths) Low (project-level setting only) High improvement (50-70%) Minimal (local disk I/O) Frequent builds, large dependencies Correct answer - optimal for scenario
D (buildspec from CodeArtifact) N/A (Architectural mismatch) None (CodeArtifact doesn’t serve buildspecs) N/A None - misunderstands service boundaries Tests understanding of service integration patterns

Real-World Application (Practitioner Insight)
#

Exam Rule
#

“For the DVA-C02 exam, when you see ‘reduce dependency download time’ + ‘CodeBuild’ + ‘frequently run builds’, always prefer LOCAL cache with explicit paths in buildspec.yaml. Remember: cache configuration requires file system paths, never service names or repository identifiers.”

Real World
#

“In production environments, we often use hybrid caching strategies:

  • Local cache for hot paths (frequently-used dependencies like pip/npm packages)
  • S3 cache for build artifacts shared across multiple projects or regions
  • Custom cache invalidation logic in buildspec.yaml to force fresh downloads when dependency versions change

We also monitor CloudWatch Logs for cache hit rates using custom metrics:

# In build phase
cache_hit_rate = (cached_files / total_files) * 100
cloudwatch.put_metric_data(
    Namespace='CustomBuild',
    MetricData=[{
        'MetricName': 'CacheHitRate',
        'Value': cache_hit_rate,
        'Unit': 'Percent'
    }]
)

Additionally, for truly massive dependency sets (multi-GB), consider pre-baking dependencies into custom Docker images and referencing those in CodeBuild’s environment configuration—this shifts caching from runtime to image layers.”


(CTA) Stop Guessing, Start Mastering
#


Disclaimer

This is a study note based on simulated scenarios for the DVA-C02 exam. Always refer to the official AWS documentation for the most current service capabilities and best practices. CodeBuild caching features and syntax may evolve with service updates.

The DevPro Network: Mission and Founder

A 21-Year Tech Leadership Journey

Jeff Taakey has driven complex systems for over two decades, serving in pivotal roles as an Architect, Technical Director, and startup Co-founder/CTO.

He holds both an MBA degree and a Computer Science Master's degree from an English-speaking university in Hong Kong. His expertise is further backed by multiple international certifications including TOGAF, PMP, ITIL, and AWS SAA.

His experience spans diverse sectors and includes leading large, multidisciplinary teams (up to 86 people). He has also served as a Development Team Lead while cooperating with global teams spanning North America, Europe, and Asia-Pacific. He has spearheaded the design of an industry cloud platform. This work was often conducted within global Fortune 500 environments like IBM, Citi and Panasonic.

Following a recent Master’s degree from an English-speaking university in Hong Kong, he launched this platform to share advanced, practical technical knowledge with the global developer community.


About This Site: AWS.CertDevPro.com


AWS.CertDevPro.com focuses exclusively on mastering the Amazon Web Services ecosystem. We transform raw practice questions into strategic Decision Matrices. Led by Jeff Taakey (MBA & 21-year veteran of IBM/Citi), we provide the exclusive SAA and SAP Master Packs designed to move your cloud expertise from certification-ready to project-ready.