CodeBuild Build Troubleshooter
Quick start
- Phase status drives the first probe.
batch-get-buildsreturnsphases[]withphaseType,phaseStatus, andcontexts[].message. The firstFAILEDphase is the entry point — not the overall build status. INSTALL failures differ entirely from BUILD or UPLOAD_ARTIFACTS. - BUILD_CONTAINER_UNABLE_TO_PULL_IMAGE is the highest-signal error string. It points at ECR auth (service role missing ECR permissions), image size (exceeds the 15 GB storage cap), or Docker Hub rate limiting. Probe ECR repo policy, image size, and service role permissions first.
- Docker-in-Docker builds require
privilegedMode: true. Without it,docker buildreturns "Cannot connect to the Docker daemon." This is the single most common CodeBuild Docker failure — a project environment config issue, not a buildspec issue. - VPC-attached CodeBuild follows standard VPC routing. A build in a private subnet without NAT cannot reach package registries (npm, PyPI, Maven). AWS services need VPC endpoints or NAT.
- Cache mode determines storage backend and permissions.
LOCAL_DOCKER_LAYERcaches on-host (requires privileged mode);S3cache stores in a bucket (requiress3:GetObject/s3:PutObject). Mixing them up produces "cache not helping" patterns.
Quick reference — phase-to-cause navigation table
| Failed phase / error string | Most likely ROOT_CAUSE | First probe |
|---|---|---|
QUEUED long, never IN_PROGRESS |
QUEUED_CONCURRENCY | batch-get-projects (concurrentBuildLimit), Service Quotas |
PROVISIONING → FAILED |
VPC_NO_EGRESS / VPC_SG_BLOCKING | vpcConfig, describe-subnets, describe-route-tables |
DOWNLOAD_SOURCE → FAILED |
SOURCE_CHECKOUT_AUTH | batch-get-builds (resolvedSourceVersion), source credential |
INSTALL → FAILED |
RUNTIME_VERSION / ENV_VAR_RESOLUTION | Phase contexts, buildspec phases.install |
PRE_BUILD → FAILED |
PHASE_COMMAND_FAIL / DOCKER_PRIVILEGED_MODE | Build logs, environment.privileged-mode |
BUILD → FAILED |
PHASE_COMMAND_FAIL / DOCKER_PRIVILEGED_MODE | Build logs for the BUILD phase |
POST_BUILD → FAILED |
PHASE_COMMAND_FAIL / ARTIFACT_S3_PERMISSION | Build logs, exportedEnvironmentVariables |
UPLOAD_ARTIFACTS → FAILED |
ARTIFACT_S3_PERMISSION / ARTIFACT_KMS | Service role IAM, artifacts.location, encryptionKey |
BUILD_CONTAINER_UNABLE_TO_PULL_IMAGE |
IMAGE_PULL_AUTH / IMAGE_PULL_SIZE | ECR repo policy, image size, service role ECR perms |
YAML_FILE_ERROR / Phase context status code |
BUILDSPEC_SYNTAX | validate-buildspec, buildspec YAML validation |
Build exceeds timeout, TIMED_OUT |
BUILD_TIMEOUT_CONFIG / BUILD_TIMEOUT_DOWNSTREAM | timeoutInMinutes, phase duration |
| Secrets Manager / SSM param unresolved | SECRET_ACCESS | Service role IAM for secretsmanager:GetSecretValue |
STRICT output contract
Every diagnosis MUST emit exactly one block in this format:
TARGET: <project-name / build-id>
VERDICT: ROOT_CAUSE_IDENTIFIED | INSUFFICIENT_DATA
REASON: <1-2 sentences naming the failed phase, the ROOT_CAUSE category,
and the failing probe that confirms it>
ROOT_CAUSE: <IMAGE_PULL_AUTH | IMAGE_PULL_SIZE | PHASE_COMMAND_FAIL |
BUILDSPEC_SYNTAX | ENV_VAR_RESOLUTION | ARTIFACT_S3_PERMISSION |
ARTIFACT_KMS | VPC_NO_EGRESS | VPC_SG_BLOCKING | RUNTIME_VERSION |
BUILD_TIMEOUT_CONFIG | BUILD_TIMEOUT_DOWNSTREAM |
SOURCE_CHECKOUT_AUTH | CACHE_S3_MISCONFIG | CACHE_LOCAL_MISCONFIG |
DOCKER_PRIVILEGED_MODE | SECRET_ACCESS | BADGE_GENERATION |
QUEUED_CONCURRENCY | BATCH_CONFIG | UNKNOWN>
EVIDENCE:
- Symptom: <observed error string or phase behaviour>
- Failing probe: <command and output that confirms the cause>
- Passing probes: <categories ruled out>
REMEDIATION:
1. <specific action with CLI command>
2. <verification command after the fix>
CONFIRM: Before executing any state-changing CLI, emit and await operator
approval: "CONFIRM: About to <action> on <project> in <region>. Proceed?
(yes/no)"
NEVER
FORBIDDEN output patterns
NEVER emit
VERDICT: ROOT_CAUSE_IDENTIFIEDwithout a failing probe in the EVIDENCE block. The phase statusFAILEDis a symptom, not a root cause. Readcontexts[].messageand run the diagnostic probe before naming the category.NEVER confuse the service role with the source credential in the REMEDIATION block. A
CannotPullContainerErrorfrom ECR is the service role; aDOWNLOAD_SOURCEfailure is the source credential. The fix steps MUST target the correct identity.NEVER recommend adding a NAT Gateway without first checking for VPC endpoints. ECR interface endpoints and the S3 gateway endpoint are cheaper and more secure. The NAT is required for external package registries only.
NEVER conflate
LOCAL_DOCKER_LAYERcache withS3cache in REMEDIATION.LOCAL_DOCKER_LAYERrequiresprivilegedMode: true;S3cache requires bucket IAM. Mixing them up produces a fix that does not resolve the issue.NEVER omit the
CONFIRMgate from a REMEDIATION block that contains state-changing commands (update-project,put-role-policy,start-build). The gate is mandatory before any write operation.NEVER emit a ROOT_CAUSE of
UNKNOWNwithVERDICT: ROOT_CAUSE_IDENTIFIED. If the root cause is unknown, the verdict MUST beINSUFFICIENT_DATAwith a list of missing information.
Diagnostic decision tree
Read batch-get-builds phases[] — find the FIRST FAILED phase.
├── DOWNLOAD_SOURCE → FAILED
│ ├── "authentication failed" (CodeCommit) → SOURCE_CHECKOUT_AUTH
│ ├── "Bad credentials" (GitHub) → SOURCE_CHECKOUT_AUTH
│ └── "Access Denied" (S3 source) → SOURCE_CHECKOUT_AUTH
├── contexts[].message contains BUILD_CONTAINER_UNABLE_TO_PULL_IMAGE
│ ├── simulate-principal-policy for ecr:* returns implicitDeny
│ │ → IMAGE_PULL_AUTH (service role lacks ECR read)
│ ├── image size approaching 15 GB
│ │ → IMAGE_PULL_SIZE
│ └── image from Docker Hub
│ → IMAGE_PULL_AUTH (Docker Hub rate limit)
├── INSTALL / PRE_BUILD / BUILD / POST_BUILD → FAILED
│ ├── logs show "Cannot connect to the Docker daemon"
│ │ → DOCKER_PRIVILEGED_MODE (enable privilegedMode: true)
│ ├── "runtime version not available"
│ │ → RUNTIME_VERSION
│ └── non-zero exit code on a buildspec command
│ → PHASE_COMMAND_FAIL
├── UPLOAD_ARTIFACTS → FAILED
│ ├── simulate-principal-policy for s3:PutObject returns implicitDeny
│ │ → ARTIFACT_S3_PERMISSION
│ └── KMS access denied on artifacts bucket
│ → ARTIFACT_KMS
├── phases[].phaseStatus: TIMED_OUT
│ ├── same phase consistently times out
│ │ → BUILD_TIMEOUT_CONFIG
│ └── different phase times out each build
│ → BUILD_TIMEOUT_DOWNSTREAM
└── YAML_FILE_ERROR
└── validate-buildspec fails
→ BUILDSPEC_SYNTAX
Pre-flight: gather-info gate
Gather-info probes (build details, project config, build logs, service-role policies, AWS Health): references/diagnostic-commands.md.
Build-state short-circuit
| Phase status | Effect |
|---|---|
All SUCCEEDED |
Build succeeded; verify the correct build ID if a failure is reported. |
First FAILED phase |
Entry point for diagnosis. Read contexts[].statusCode + message. |
TIMED_OUT |
CodeBuild killed at timeoutInMinutes. Distinguish config from downstream hang. |
STOPPED |
Manually stopped or batch failure. Check buildStoppedReason. |
QUEUED > 10 min |
Concurrency limit reached. Check concurrentBuildLimit + Service Quotas. |
If the input is malformed (missing project name, absent symptom), emit:
TARGET: <project-name or unknown>
VERDICT: INSUFFICIENT_DATA
REASON: Input is missing required context — at minimum a symptom
description and the project name or build ID.
ROOT_CAUSE: UNKNOWN
EVIDENCE:
- Missing: <list specific missing fields>
REMEDIATION: Re-prompt for: (1) project name or build ID, (2) the
observed symptom, (3) region for live diagnosis.
Process — Diagnostic decision tree
Find the first FAILED phase and jump to that section.
Step 1: DOWNLOAD_SOURCE failures
Symptom: phaseType: DOWNLOAD_SOURCE, phaseStatus: FAILED.
contexts[].message |
ROOT_CAUSE |
|---|---|
authentication failed (CodeCommit) |
SOURCE_CHECKOUT_AUTH — service role lacks codecommit:GitPull |
Bad credentials (GitHub) |
SOURCE_CHECKOUT_AUTH — token expired or revoked |
rate limit exceeded (GitHub) |
SOURCE_CHECKOUT_AUTH — use CodeStar connection |
Access Denied (S3 source) |
SOURCE_CHECKOUT_AUTH — service role lacks s3:GetObject |
Could not find commit / reference not found |
SOURCE_CHECKOUT_AUTH — branch or SHA does not exist |
Verdict: ROOT_CAUSE_IDENTIFIED, ROOT_CAUSE: SOURCE_CHECKOUT_AUTH.
Step 2: BUILD_CONTAINER_UNABLE_TO_PULL_IMAGE
Symptom: contexts[].message contains BUILD_CONTAINER_UNABLE_TO_PULL_IMAGE.
2a: ECR auth
aws iam simulate-principal-policy \
--policy-source-arn <service-role-arn> \
--action-names ecr:BatchGetImage ecr:GetDownloadUrlForLayer ecr:BatchCheckLayerAvailability \
--output json --profile <p>
implicitDeny → ROOT_CAUSE_IDENTIFIED, ROOT_CAUSE: IMAGE_PULL_AUTH.
For cross-account ECR images, also check the ECR repo policy:
aws ecr get-repository-policy --repository-name <repo> --output json
2b: Image size
aws ecr describe-images --repository-name <repo> --image-ids imageTag=<tag> \
--output json | jq '.imageDetails[].imageSizeInBytes'
Images approaching 15 GB uncompressed may fail to pull. ROOT_CAUSE_IDENTIFIED,
ROOT_CAUSE: IMAGE_PULL_SIZE.
2c: Docker Hub rate limit
Images from Docker Hub may hit anonymous rate limits. Store Docker Hub
credentials via Secrets Manager or a CodeBuild source credential.
ROOT_CAUSE_IDENTIFIED, ROOT_CAUSE: IMAGE_PULL_AUTH.
Step 3: INSTALL / PRE_BUILD / BUILD phase command failures
Symptom: phaseStatus: FAILED in a command-execution phase.
# Read phase contexts and durations
aws codebuild batch-get-builds --ids <build-id> --output json | \
jq '.builds[0].phases[] | select(.phaseStatus == "FAILED") | {phaseType, contexts, durationInSeconds}'
# Filter logs for errors
aws logs filter-log-events \
--log-group-name /aws/codebuild/<project-name> \
--log-stream-names <stream> \
--filter-pattern '"error" OR "Error" OR "failed" OR "Cannot connect"' \
--output json
3a: Docker daemon error
If logs show Cannot connect to the Docker daemon:
aws codebuild batch-get-projects --names <project-name> --output json | \
jq '.projects[0].environment.privilegedMode'
false or absent → ROOT_CAUSE_IDENTIFIED, ROOT_CAUSE: DOCKER_PRIVILEGED_MODE.
Fix: update-project --environment privilegedMode=true,....
3b: Runtime version error
If INSTALL fails with runtime version not available or a removed
runtime is referenced:
ROOT_CAUSE_IDENTIFIED, ROOT_CAUSE: RUNTIME_VERSION. Fix: update
buildspec phases.install.runtime-versions to a supported version.
3c: Generic command failure
A non-zero exit code from a buildspec command. ROOT_CAUSE_IDENTIFIED,
ROOT_CAUSE: PHASE_COMMAND_FAIL. The diagnosis should identify the exact
command and error from the logs.
Step 4: UPLOAD_ARTIFACTS failures
Symptom: phaseType: UPLOAD_ARTIFACTS, phaseStatus: FAILED.
4a: S3 permission
aws iam simulate-principal-policy \
--policy-source-arn <service-role-arn> \
--action-names s3:PutObject s3:GetObject s3:ListBucket \
--resource-arns <bucket-arn> <bucket-arn>/* \
--output json --profile <p>
implicitDeny → ROOT_CAUSE_IDENTIFIED, ROOT_CAUSE: ARTIFACT_S3_PERMISSION.
4b: KMS encryption
If the artifacts bucket uses a customer-managed KMS key and the role
lacks kms:Decrypt / kms:GenerateDataKey:
ROOT_CAUSE_IDENTIFIED, ROOT_CAUSE: ARTIFACT_KMS.
Step 5: VPC-attached build failures
aws codebuild batch-get-projects --names <project-name> --output json | \
jq '.projects[0].environment.vpcConfig'
5a: Route table
aws ec2 describe-route-tables \
--filters Name=association.subnet-id,Values=<subnet-1> <subnet-2> \
--output json | jq '.RouteTables[].Routes'
No NAT route for external egress → ROOT_CAUSE_IDENTIFIED,
ROOT_CAUSE: VPC_NO_EGRESS.
5b: Security group
aws ec2 describe-security-groups --group-ids <sg> --output json | \
jq '.SecurityGroups[].IpPermissionsEgress'
Locked-down SG without HTTPS (443) egress → ROOT_CAUSE_IDENTIFIED,
ROOT_CAUSE: VPC_SG_BLOCKING.
Step 6: Build timeout
Symptom: phases[].phaseStatus: TIMED_OUT.
aws codebuild batch-get-builds --ids <build-id> --output json | \
jq '.builds[0] | {timeoutInMinutes, phases: [.phases[] | {phaseType, phaseStatus, durationInSeconds}]}'
- Config timeout:
timeoutInMinutestoo low for typical duration; the timed-out phase is consistently the same. Fix: raise to 1-480 min.ROOT_CAUSE: BUILD_TIMEOUT_CONFIG. - Downstream hang: a command hangs on a network call; the phase that
times out varies. Fix: investigate the downstream dependency.
ROOT_CAUSE: BUILD_TIMEOUT_DOWNSTREAM.
Step 7: Cache configuration issues
Symptom: builds consistently slow; cache does not appear to work.
aws codebuild batch-get-projects --names <project-name> --output json | \
jq '.projects[0] | {cache: .cache, privilegedMode: .environment.privilegedMode}'
cache.type: S3but service role lackss3:GetObject/s3:PutObjectoncache.bucket/*: ROOT_CAUSE_IDENTIFIED,CACHE_S3_MISCONFIG. The cache is silently skipped — no error, just slower builds.cache.typeincludesLOCAL_DOCKER_LAYERbutprivilegedMode: false: ROOT_CAUSE_IDENTIFIED,CACHE_LOCAL_MISCONFIG. Local Docker layer cache requires privileged mode.
Step 8: Environment variable / secret resolution
Symptom: buildspec references a variable that is empty, or INSTALL fails with access-denied for Secrets Manager / SSM.
aws codebuild batch-get-projects --names <project-name> --output json | \
jq '.projects[0].environment.environmentVariables[] | {name, type, value}'
For type: SECRETS_MANAGER variables, verify:
aws iam simulate-principal-policy --policy-source-arn <service-role-arn> \
--action-names secretsmanager:GetSecretValue --resource-arns <secret-arn> \
--output json --profile <p>
For type: PARAMETER_STORE variables, verify ssm:GetParameter.
implicitDeny → ROOT_CAUSE_IDENTIFIED, ROOT_CAUSE: SECRET_ACCESS.
Step 9: Buildspec syntax errors
Symptom: contexts[].statusCode: YAML_FILE_ERROR.
aws codebuild validate-buildspec --cli-input-yaml file://buildspec.yml --output json
| Error pattern | ROOT_CAUSE |
|---|---|
| YAML parse error (indentation, tabs) | BUILDSPEC_SYNTAX |
runtime-versions references removed version |
BUILDSPEC_SYNTAX |
phases.build.commands not a list |
BUILDSPEC_SYNTAX |
artifacts.files glob matches nothing |
BUILDSPEC_SYNTAX |
| Unknown top-level key | BUILDSPEC_SYNTAX |
Step 10: Queued builds and batch config
10a: Queued concurrency
aws codebuild batch-get-projects --names <project-name> --output json | \
jq '.projects[0].concurrentBuildLimit'
aws service-quotas get-service-quota --service-code codebuild \
--quota-code L-1BFC63E6 --output json --profile <p>
Limit reached → ROOT_CAUSE_IDENTIFIED, QUEUED_CONCURRENCY.
10b: Batch build configuration
aws codebuild batch-get-projects --names <project-name> --output json | \
jq '.projects[0].batchConfiguration'
Batch issues: circular build-graph deps, missing buildspec, service role
lacking sub-build artifact permissions. ROOT_CAUSE_IDENTIFIED,
BATCH_CONFIG.
Step 11: Build badge failures
aws codebuild batch-get-projects --names <project-name> --output json | \
jq '.projects[0] | {badgeEnabled: .badgeEnabled, projectVisibility: .projectVisibility}'
badgeEnabled: false → enable: update-project --name <n> --badge-enabled badgeEnabled=true. ROOT_CAUSE_IDENTIFIED, BADGE_GENERATION.
Worked examples
Worked example — Docker privileged mode
TARGET: cb-prod-api / build-id: cb-prod-api:abc12345
VERDICT: ROOT_CAUSE_IDENTIFIED
REASON: The BUILD phase fails with "Cannot connect to the Docker daemon."
The project environment.privilegedMode is false. Docker-in-Docker builds
require privilegedMode: true (Step 3a).
ROOT_CAUSE: DOCKER_PRIVILEGED_MODE
EVIDENCE:
- Symptom: every build fails in BUILD at "docker build" with
"Cannot connect to the Docker daemon."
- Probe: aws codebuild batch-get-projects returns
environment.privilegedMode: false.
- Passing: buildspec is valid YAML; Dockerfile exists; ECR perms present.
REMEDIATION:
1. Enable privileged mode:
aws codebuild update-project --name cb-prod-api \
--environment privilegedMode=true,... --profile <p>
2. Verify by re-running the build.
CONFIRM: Before updating the project, emit and await:
"CONFIRM: About to enable privilegedMode on cb-prod-api. Proceed?
(yes/no)"
Further worked examples (cross-account ECR image-pull auth; INSUFFICIENT_DATA re-prompt): references/worked-examples.md.
Pre-flight safety checks
- MANDATORY CONFIRMATION GATE. Before any state-changing operation
(
update-project,put-role-policy,create-vpc-endpoint,start-build), emit and await operator approval. - Read-only first. Every probe is read-only (
batch-get-builds,batch-get-projects,get-log-events,simulate-principal-policy). - Updating a project (
update-project) is safe for config-only changes; in-flight builds continue with prior config. - Changing the service role affects all projects using it; verify no other projects share the role.
- Enabling privileged mode grants elevated access; only for Docker builds, not all projects.
- VPC config changes trigger new ENI creation; plan outside peaks.
- Bulk remediation: batch groups of at most 5 projects.
References (load on demand)
- Worked examples - full walkthroughs: cross-account ECR image-pull auth (BUILD_CONTAINER_UNABLE_TO_PULL_IMAGE), INSUFFICIENT_DATA re-prompt
- Error handling - ROOT_CAUSE-to-fix remediation table
- Diagnostic commands - pre-flight gather-info gate: the five read-only probes
- Advanced patterns - NEVER rules (expanded rationale), expert heuristic, configuration dependency graph, diagnostic mindset
- Build environment reference - images, runtimes, compute types
Domain
AWS CloudOps / CodeBuild CI-CD Build Automation, Build Environment Diagnostics, Service Role IAM, VPC Networking for Build Containers, ECR Image Distribution, and Secrets Integration.
AWS documentation
- CodeBuild User Guide — https://docs.aws.amazon.com/codebuild/latest/userguide/welcome.html
- Buildspec reference — https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html
- Build environment — https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref.html
- VPC support — https://docs.aws.amazon.com/codebuild/latest/userguide/use-vpc.html
- Docker builds — https://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html
- Caching — https://docs.aws.amazon.com/codebuild/latest/userguide/build-caching.html
- Batch builds — https://docs.aws.amazon.com/codebuild/latest/userguide/batch-build.html
- Service role — https://docs.aws.amazon.com/codebuild/latest/userguide/setting-up.html#setting-up-service-role
- Runtime versions — https://docs.aws.amazon.com/codebuild/latest/userguide/available-runtimes.html