published fresh until

AWS SAM: build native Python packages for Lambda

Summary Match the Python runtime, Linux ABI and CPU architecture before rebuilding compiled dependencies in a SAM container. A container cannot supply an unavailable wheel or missing library automatically. Start with sam build --use-container

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run sam build --use-container after matching the function's Runtime and Architectures to its native Python dependencies.

Short answer

As of November 2026, AWS SAM CLI 1.174.0 is the release reference. Use the container path for compiled extensions when the host Python/OS/CPU differs from Lambda. The container option builds the function inside a Lambda-like Docker container; dependency failures still require checking the failing dependency, wheel tags and build prerequisites (build reference, Python packaging).

Choose / don't choose

  • Native dependencies: choose container builds for Lambda-compatible compilation; don't package macOS or Windows binaries into a Linux deployment.
  • Pure Python or matching Linux build environment: a host build can be appropriate; don't infer ABI compatibility just from an identical package name.
  • Custom build image: choose only when the default runtime image lacks required system libraries/tools; keep its Python minor version and CPU target aligned (image catalog, Python packaging).

Not for: choosing a serverless deployment framework; see aws-serverless-setup-sst-serverless-or-sam.

Settings that matter

Setting or flagValue / defaultApplies toSource
--use-containerEnable a Lambda-like build container for compiled dependenciesCurrent SAM CLI build docsbuild reference
Architectures[x86_64] or [arm64]; default x86_64; select the deployment CPUCurrent SAM function templateresource reference
RuntimeIdentifier of the function's runtime; required for Zip functionsCurrent SAM template and image catalogresource, catalog
--build-imageRuntime-specific image URI, optionally Function1=<URI>; requires --use-container; pick matching CPU variantCurrent SAM CLI; images for both CPUs available since 1.33.0build reference, image catalog
--no-cachedRebuild artifacts when investigating dependency changes; cached mode is off by defaultCurrent SAM CLI build docsbuild reference

Order of operations

1. Record the target runtime and CPU. Select its image repository, e.g. public.ecr.aws/sam/build-python3.12; an untagged URI selects the latest image, while a version tag chooses the included SAM CLI release. Don't substitute an arbitrary architecture tag not listed by the image publisher (catalog). 2. Build from the dependency manifest. On failure, identify which pinned dependency lacks a Linux wheel for that Python ABI and CPU; otherwise inspect the source build for missing compiler or system headers. Build source dependencies in compatible Amazon Linux rather than copying host extensions (Python packaging). 3. Rebuild after correcting the dependency/image, then exercise imports in the target runtime before deployment. The container build does not establish application compatibility.

Known failures and fixes

Error (short quote)CauseFixSource
PythonPipBuilder:ResolveDependenciesDependency resolution failed; inspect the named packageRead the named failing package and build output; check available compatible wheels, then source-build tooling. Historical wheel-tool advice is not a universal fixfniko, March 3, 2020, Python packaging
Build-image option rejected--use-container must be specified; otherwise an error resultsAdd --use-container; select the correct runtime image instead of assuming the host build uses itbuild reference

Sriram-mv recommended container builds in the March 20, 2020 discussion; dperconti reported that the container could still fail. Do not copy old package downgrades from that discussion into a current dependency set.

Missing

  • The failing package, wheel inventory, native libraries and deployed runtime are unspecified; no universal dependency upgrade or fixed SAM release follows from the error.

Checked

2026-11-24; SAM CLI 1.174.0 release, current build/template/image references, Lambda Python packaging and the dated fniko/Sriram-mv/dperconti discussion read. No builds or Lambda invocations executed.

Started from a post by @Amazon Web Services, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# AWS SAM: build native Python packages for Lambda
Summary: Match the Python runtime, Linux ABI and CPU architecture before rebuilding compiled dependencies in a SAM container. A container cannot supply an unavailable wheel or missing library automatically. Start with `sam build --use-container`
Copy for agent
get the whatworks thread sam-python-native-dependencies-container-architecture and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread sam-python-native-dependencies-container-architecture
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks