Read phased logs to find the failing stage
A CodeBuild run emits phased logs (DOWNLOAD_SOURCE, INSTALL, PRE_BUILD, BUILD, POST_BUILD, UPLOAD_ARTIFACTS). Start by scanning the phased output to see which phase stopped or reported errors. Example excerpt showing lifecycle messages up through the BUILD phase:
Example: ACCESS_DENIED during QUEUED phase — CloudWatch Logs permissions
A common failure is an ACCESS_DENIED error because the CodeBuild service role lacks CloudWatch Logs permissions. Example error from the phase details:- Confirm the CodeBuild project’s service role (the IAM role defined as the project’s service role).
- Inspect identity-based policies (both managed and inline) attached to that role.
- Add the required CloudWatch Logs permissions, scoped to the necessary resources.
Tip: scope the policy to the project log group ARN when practical, or use least-privilege patterns to limit permissions.
After granting the required logs permissions to the service role, CodeBuild should be able to create log streams and proceed beyond the QUEUED state.
Confirm a successful run
Once permissions and configuration are fixed, a successful build will show all phases as SUCCEEDED. Example condensed success output:Tail the full CloudWatch Logs stream
The CodeBuild console links directly to the CloudWatch Logs stream for each build. In CloudWatch Logs you can review earlier lifecycle events (agent startup, DOWNLOAD_SOURCE, provisioning details) and tail logs in real time:Use interactive debug builds when needed
CodeBuild debug builds and interactive sandbox sessions let you open a session inside the build environment to reproduce buildspec steps interactively, inspect filesystem contents, and run troubleshooting commands one-by-one.Debug builds require AWS Systems Manager (SSM) Session Manager permissions for the sandbox session. Ensure the service role has the necessary SSM permissions before starting an interactive debug session.
Common failure causes and where they surface
Troubleshooting checklist (best practice)
- Identify the failed phase in the CodeBuild console.
- Read the exact error message shown in the phase details.
- Open the CloudWatch Logs stream for the failed build to see full output and earlier lifecycle events.
- Check the build project’s service role and attached IAM policies for missing permissions.
- If needed, run a debug build to inspect the environment interactively and reproduce steps.
- Apply the fix, re-run the build, and confirm the previously failed phase now succeeds.
Tip: Most build failures are due to permissions, configuration, or dependency issues. Always start with the phase error text, then verify IAM permissions and the
buildspec.yml contents.