SAM Doctor

ERROR REFERENCE

Lambda package exceeds a per-function size limit

The function's code artifact is over a hard Lambda limit — the zipped upload, or the unzipped contents. The deploy fails at CreateFunction/UpdateFunctionCode, after the build already succeeded, which is what makes it feel sudden.

WHAT IT MEANS

What this error means

This is a per-function limit, not the account-wide storage quota — that one says Code storage limit exceeded and has a different fix.

FIX

How to fix it

  1. Measure the artifact before blaming AWS:
    ls -lh .aws-sam/build/*/
    unzip -l .aws-sam/build/MyFunction/../artifact.zip | sort -k1 -n | tail -20
    The largest entries are almost always dependencies, not your code.
  2. Trim what ships. Move dev/test dependencies out of the runtime requirements, exclude data files the handler never reads, and check for accidentally vendored toolchains.
  3. Share heavy dependencies through a layer when several functions carry the same libraries — remembering layers still count toward the unzipped total.
  4. Switch the function to a container image when it is genuinely large: image-based functions get a 10 GB limit.

AUTOMATE THE TRIAGE

Diagnose this automatically

SAM Doctor recognizes both size phrasings (high confidence) and keeps the regional storage quota separate. Runs locally; no AWS access, no log upload.

python -m pip install sam-doctor
sam-doctor diagnose deployment.log --format markdown

RELATED