DOP-C02 SDLC Automation Practice Question
A team uses AWS CodeBuild to build a Node.js application. The buildspec.yml file is at the root of the repository. The build fails with 'Error: Cannot find module 'aws-sdk''. Which TWO actions could resolve the issue? (Choose TWO.)
⚠ Common exam trap
Test-takers frequently assume CodeBuild automatically runs 'npm install' or that the 'aws-sdk' is always available in the build environment, when in fact both the dependency declaration and explicit install phase are required.
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
✓
Ensure 'aws-sdk' is listed in the 'dependencies' section of package.json.
The 'aws-sdk' module must be declared in the 'dependencies' section of package.json for npm to install it during the build. Without this declaration, npm install will not download the module, causing the 'Cannot find module' error at runtime. Option D is correct because CodeBuild does not automatically run npm install; you must explicitly include an 'install' phase in buildspec.yml to execute 'npm install' and populate node_modules.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Ensure 'aws-sdk' is listed in the 'dependencies' section of package.json.
Why this is correct
The 'aws-sdk' package is a runtime dependency, and CodeBuild's npm install phase installs only the modules declared in package.json. If it is missing from the 'dependencies' section, npm will not fetch it, so your Node.js code cannot require it regardless of the environment. Adding it there ensures it is installed with the default dependency installation step, and pinning a version avoids unexpected updates.
- ✗
Specify a different Node.js runtime version in the buildspec.
Why it's wrong here
Changing the Node.js runtime version in the buildspec only alters the interpreter version used for build commands, not the availability of npm packages. Unless your code explicitly depends on APIs or behaviors specific to a different Node major version, this will not fix a missing module. Runtime configuration affects how the application executes, not whether third-party packages are present in node_modules.
- ✗
Add a 'pre_build' phase that runs 'npm test'.
Why it's wrong here
Running 'npm test' in the 'pre_build' phase executes any test scripts defined in package.json, but it does not resolve dependency installation. Tests require the dependencies to already be present, so without an install step or the modules declared, they will fail the same way. Adding tests can verify code behavior, yet it is not a substitute for installing the 'aws-sdk' package.
- ✓
Add a 'install' phase that runs 'npm install'.
Why this is correct
CodeBuild does not automatically install dependencies unless you explicitly invoke npm install, typically in the 'install' phase. Adding an 'install' phase that runs 'npm install' will download all packages listed in package.json, including 'aws-sdk'. However, this only works if the SDK is also declared under 'dependencies'; if omitted, npm install will skip it and the module will still be absent.
- ✗
Add a 'build' phase command to compile the code.
Why it's wrong here
A 'build' phase command that compiles code—such as running a bundler or TypeScript compiler—does not handle package resolution or installation. Compilation may transpile or bundle source files, but importing 'aws-sdk' will still fail unless the package exists in node_modules. The build phase occurs after install, so it cannot remedy a missing dependency; the fix must happen during dependency installation.
Visual reference
Go deeper
Related to this question
About these practice questions
One of 1,298 original DOP-C02 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
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.