Skip to content
Latchkey

AWS SAM "Build Failed" - Fix sam build Errors in CI

sam build compiles each function’s dependencies before packaging, and one function’s build step failed. The error is in the per-function build - a missing runtime, container, or a bad dependency install.

What this error means

sam build stops with Build Failed and a per-function reason: a missing language runtime, no Docker for --use-container, or a pip/npm install error inside the build. Deploy never runs because the artifacts were not produced.

sam output
Build Failed
Error: NodejsNpmBuilder:NpmInstall - NPM Failed: npm ERR! code ENOENT
npm ERR! Could not read package.json

Common causes

Missing runtime or container for the build

SAM builds with the function’s runtime, or in a Lambda-like container when --use-container is set. If that runtime is absent (no Node/Python) or Docker is unavailable, the build fails.

Dependency manifest or install error

A missing or malformed package.json/requirements.txt, or a dependency that fails to install, makes the per-function builder exit non-zero.

How to fix it

Build in a container for parity

Use --use-container so the build runs in the Lambda runtime image regardless of what the runner has installed (requires Docker on the runner).

Terminal
sam build --use-container --cached

Fix the function’s build inputs

  1. Confirm the manifest (package.json, requirements.txt) exists at the function’s CodeUri.
  2. Install or pin the matching runtime in CI (e.g. actions/setup-node for a Node function).
  3. Reproduce locally with the same command to read the full builder error.

How to prevent it

  • Use --use-container in CI so builds match the Lambda runtime exactly.
  • Set up the function runtime explicitly in the workflow.
  • Cache the SAM build cache keyed on the dependency manifest.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →