DOP-C02 Configuration Management and IaC Practice Question
A DevOps engineer is troubleshooting an AWS CodeDeploy deployment that fails during the 'BeforeInstall' lifecycle event. The deployment group uses an in-place deployment to an Auto Scaling group. The engineer reviews the logs on the instance and sees that the 'BeforeInstall' script exits with code 1. The script is a shell script that compiles application code. What is the most likely cause of the failure?
⚠ Common exam trap
The trap here is that candidates may overthink the cause (e.g., missing dependencies or file permissions) when the question explicitly states the script exits with code 1, which is the direct and most likely cause of failure in CodeDeploy's lifecycle event execution model.
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
✓
The script exited with a non-zero exit code
In AWS CodeDeploy, lifecycle event scripts must exit with a status code of 0 to indicate success. Any non-zero exit code, including 1, is interpreted as a failure, causing the deployment to abort. Since the 'BeforeInstall' script exits with code 1, the deployment fails regardless of the script's intent or content.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
The script exited with a non-zero exit code
Why this is correct
CodeDeploy treats any non-zero exit code from a lifecycle event script as a definitive failure, regardless of the underlying cause. When the agent executes a script, it captures the process exit status; if it is not 0, the deployment immediately stops, marks the overall deployment as Failed, and runs any configured OnFailure hooks. This is the direct trigger for the failure, even if the script printed an error message before exiting.
- ✗
The script is not included in the 'files' section of the appspec.yml
Why it's wrong here
The script's location relative to the 'files' section is irrelevant to execution. In appspec.yml, the 'files' section lists source files to be copied onto the instance, while lifecycle scripts must be declared under the 'hooks' section, which maps each event (e.g., AfterInstall, ApplicationStart) to a run script. If a script is omitted from the 'hooks' section, it would not be executed at all, but that would not generate a non-zero exit error; it would simply not run.
- ✗
The script requires dependencies that are not installed on the instance
Why it's wrong here
Missing dependencies can cause a script to fail, but the deployment failure is caused by the script returning a non-zero exit code, not by the absence of the dependency itself. CodeDeploy does not inspect why a script failed; it only observes the exit status. Moreover, missing dependencies typically produce errors like 'command not found' or 'module not found' at runtime—these still result in a non-zero exit, but the immediate signal CodeDeploy reacts to is the exit code, not the dependency issue.
- ✗
The script is not owned by the root user
Why it's wrong here
File ownership does not impact whether a script can be executed; only the file's permission bits and the executing user's access rights matter. In CodeDeploy, the 'runas' attribute in the hooks section specifies the user under which the script runs, and as long as that user has execute permission (or the file is world-executable), the script runs regardless of whether the file is owned by root. An ownership mismatch would only matter if the 'runas' user lacked read/execute permission on the script, which is a permissions issue, not an ownership issue.
Go deeper
Related to this question
About these practice questions
Courseiva writes every DOP-C02 question from scratch — 1,298 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.