Skip to main content
This guide shows a practical, repeatable approach to troubleshoot a failing pipeline run in AWS CodeBuild: identify the failing phase, read its error details, inspect logs, verify IAM and configuration, then apply a fix and re-run. The examples below mirror real CodeBuild phased logs and common errors you’ll encounter.

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:
In the CodeBuild console you can click a failed run to inspect the phase summary and error message associated with the failed phase. This helps you quickly narrow the root cause.
A screenshot of the AWS CodeBuild console for the "devops-020-430-failure" project showing its configuration and a build history list with recent runs marked "Failed." Action buttons like Edit, Clone, Debug build, and Start build are visible across the top.

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:
Steps to resolve this permissions issue:
  1. Confirm the CodeBuild project’s service role (the IAM role defined as the project’s service role).
  2. Inspect identity-based policies (both managed and inline) attached to that role.
  3. Add the required CloudWatch Logs permissions, scoped to the necessary resources.
Recommended CloudWatch Logs actions for CodeBuild: 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)

  1. Identify the failed phase in the CodeBuild console.
  2. Read the exact error message shown in the phase details.
  3. Open the CloudWatch Logs stream for the failed build to see full output and earlier lifecycle events.
  4. Check the build project’s service role and attached IAM policies for missing permissions.
  5. If needed, run a debug build to inspect the environment interactively and reproduce steps.
  6. 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.
A screenshot of the AWS CodeBuild console for a build project showing the build status as "Succeeded." The page displays build metadata (ARN, start/end times, build number) and a table of build phases, each marked as succeeded.
That covers a concise, repeatable approach to troubleshooting failed CodeBuild (and similar pipeline) runs: identify the failed phase, inspect the phase error and CloudWatch logs, verify IAM and project configuration, and use interactive debug sessions when necessary. That’s it for this particular domain as far as demo 0.2.0.4.3.0.

Watch Video

Practice Lab