Builds with CodeBuild and buildspec: DOP-C02 study notes and practice questions
What to know about Builds with CodeBuild and buildspec for the DOP-C02 exam, from the SDLC Automation domain (22% of the exam guide), then 2 free questions to test it. Part of the DOP-C02 study guide.
A command that exits non-zero fails the build. exported-variables pass values to later pipeline actions.
Speed
Caching: S3 cache for dependencies across hosts, or local cache (source, Docker layer, custom) on the same host.
Batch builds run build graphs, lists or matrices in parallel.
Bigger compute types, reserved capacity fleets for no queueing, or Lambda compute for fast short builds.
Custom build images with tools preinstalled.
Network and permissions
VPC configuration lets builds reach private resources (databases, private package mirrors) through your subnets; add a NAT or endpoints for internet and AWS APIs.
The service role needs access to artifacts, logs, secrets and KMS keys.
Privileged mode is required to build Docker images.
Logs
Build logs go to CloudWatch Logs and/or S3. Build state changes are EventBridge events.
Common traps
Downloading all dependencies every build with no cache.
Building Docker images without privileged mode.
Public access to a private mirror when the build can run in the VPC.
One giant project for a monorepo; use webhook filters or batch builds.
An online retailer builds its checkout service into a container image with an AWS CodeBuild project that runs on every merge to main.
Each build takes about 14 minutes, because it downloads the same Node.js and Python dependencies from the internet every time and then compiles them again. The build must also reach a private package mirror that exists only inside the company's VPC.
The team wants to keep the existing project and buildspec file, and it does not want to run any build servers of its own.
Which TWO changes meet these requirements? (Choose two.)
Choose two answers.
AA. Increase the project's compute type to the largest size available, so that dependency downloads and compilation finish faster on every build.
BB. Add a cache section to the buildspec that stores the dependency directories in an Amazon S3 cache, so later builds restore packages from the cache instead of downloading them again.
CC. Move the builds onto a fleet of self-managed EC2 instances in an Auto Scaling group that runs a build agent and keeps its own package caches warm between jobs.
DD. Change the base image reference from a specific version tag to latest, so that each build pulls the newest base layers and the dependency downloads shrink.
EE. Attach the existing CodeBuild project to private subnets in the company's VPC, with a security group that allows outbound traffic to the internal package mirror.
Show the answer and explanation
Answers: B, E
A. Wrong: A larger compute type adds cost to every build but leaves the network downloads and repeated compilation in place. The time saved is small and the mirror access problem remains.
B. Right: Correct. CodeBuild can save and restore selected directories through an S3 cache, so most builds skip repeated downloads with only a buildspec change. The project and buildspec file stay in place, and no build servers are added. Learn more: Cache builds to improve performance (opens in a new tab)
C. Wrong: This can be fast, but it replaces the CodeBuild project and adds instances to patch and scale. The team asked to avoid running its own build servers.
CodeBuild can restore cached dependency directories from S3, which removes repeated downloads from the build path. Running the project inside the VPC lets it reach a private mirror without a public route. Larger compute, self-managed build fleets and unpinned base images either leave the slow path in place or add servers and unpredictability.
A game studio's CodeBuild project compiles its client for four platforms in one long build that runs on every pull request. Each platform takes about 20 minutes, and most pull requests change the code for only one platform.
The build runs the same buildspec in every case, so a change to a shell script for one platform can break the others without warning. The studio wants pull requests to build only the platforms whose folders changed, and wants those builds to run in parallel so that results arrive sooner.
The team wants to stay inside CodeBuild and add as little new infrastructure as possible.
Which approach meets these requirements?
Choose one answer.
AA. Create one CodeBuild project per platform and keep a shared buildspec that builds all four platforms in every project, so that each project can report its own status on the pull request.
BB. Add a Lambda function that compares each commit with the previous build and starts the full four-platform build only when any file changed, leaving the buildspec as it is.
CC. Run each platform's build on a separate EC2 instance in an Auto Scaling group, and have the pipeline start those instances with Systems Manager Run Command whenever a pull request is created.
DD. Create one CodeBuild project per platform, each with a webhook filter group on its folder's FILE_PATH, so that the projects run in parallel and only for their platform's changes.
Show the answer and explanation
Answer: D
A. Wrong: Separate projects run in parallel, but each one still builds all four platforms for every change. This misses the goal of building only the platforms that changed.
B. Wrong: The check runs, but a full build still starts for any change, so most of the work remains. The studio would also have to maintain the Lambda function and its comparison logic.
D. Right: Correct. CodeBuild webhook filter groups can match pull request events on file paths, so each platform's project starts only when its folder changes. Separate projects run in parallel, and nothing is added beyond CodeBuild itself. Learn more: Filter GitHub webhook events (console) (opens in a new tab)
Explanation
CodeBuild webhook filter groups can match pull request events on file paths, so each platform's project starts only when its own folder changes. Separate projects run in parallel, which shortens the wait, and no new service is needed. Building everything in every project, scripted skips and EC2 fleets each leave too much work or infrastructure in place.
Want more on Builds with CodeBuild and buildspec? The 5 full-length practice sets have 6 more Builds with CodeBuild and buildspec questions, 375 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets →