DOP-C02 SDLC Automation Practice Question
Network Topology
Refer to the exhibit. A developer is using this buildspec.yml in AWS CodeBuild to build and push a Docker image to Amazon ECR. The build fails with the error: 'Error: No region specified'. Which change should the developer make to resolve this error?
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
✓
Set the AWS_DEFAULT_REGION environment variable in the CodeBuild project's environment configuration.
The error occurs because the $AWS_DEFAULT_REGION environment variable is not set in the CodeBuild project. The developer must explicitly set the AWS_DEFAULT_REGION environment variable in the CodeBuild project configuration.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Add a pre_build command to export AWS_DEFAULT_REGION using the AWS CLI.
Why it's wrong here
Adding a pre_build command to export AWS_DEFAULT_REGION via the AWS CLI is ineffective and creates a circular dependency: the CLI's regional endpoints typically require AWS_DEFAULT_REGION to be set before the call, so the command cannot determine the region without already knowing it. Moreover, environment variables exported in one buildspec phase do not persist to later phases because CodeBuild executes each phase in a separate shell process, so the export would not help in the build phase anyway.
- ✓
Set the AWS_DEFAULT_REGION environment variable in the CodeBuild project's environment configuration.
Why this is correct
Setting AWS_DEFAULT_REGION in the CodeBuild project's environment configuration is the correct fix because CodeBuild injects all project-level environment variables into every phase of the build, making the value available to the AWS CLI, SDKs, and all build commands without any buildspec changes. This approach is explicit, portable, and aligns with AWS best practices for configuring tooling at the project level rather than relying on phase-scoped shell exports.
- ✗
Replace $AWS_DEFAULT_REGION with a hardcoded region like us-east-1.
Why it's wrong here
Hardcoding a region such as us-east-1 in the buildspec violates portability and would silently break builds when the project is run in a different region, because the CLI would target the wrong regional endpoint and create mismatched artifacts. It also hides the root cause—the missing environment variable—while doing nothing to teach or enforce proper configuration, and it requires manual edits for every region change.
- ✗
Use the AWS_REGION environment variable instead of AWS_DEFAULT_REGION in the buildspec.
Why it's wrong here
Although AWS_REGION is automatically set by CodeBuild, the buildspec likely uses $AWS_DEFAULT_REGION, which is not set. Changing to AWS_REGION would require modifying the buildspec, while setting AWS_DEFAULT_REGION in the project environment (option B) directly resolves the issue.
Visual reference
Go deeper
Related to this question
About these practice questions
This DOP-C02 question is part of Courseiva's 1,013-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 →
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.