AWS Lambda (Python 3.12 / AL2023)

Runtime.ImportModuleError: Unable to import module: invalid ELF header (_rust.abi3.so)

Runtime.ImportModuleError: Unable to import module: invalid ELF header (_rust.abi3.so)

What it means

A compiled Python wheel (commonly cryptography, pydantic_core, or orjson) was packaged on macOS, Windows, or the wrong CPU architecture instead of Amazon Linux 2023 Linux.

Why it happens

Upgrading from `python3.9`/`python3.10` (AL2) to `python3.12`/`python3.13` (AL2023) often coincides with rebuilding deployment ZIPs or switching to Graviton2 (`arm64`). Running `pip install -t package/` on a developer laptop bundles Mach-O (`.so` compiled for macOS) or `x86_64` ELF binaries that fail at Lambda cold start with `invalid ELF header`.

How to fix it

  1. Build deployment packages or Lambda layers inside the official AL2023 container image: `docker run --rm --platform linux/amd64 -v "$PWD":/work public.ecr.aws/lambda/python:3.12 pip install -r /work/requirements.txt -t /work/python` (use `linux/arm64` for Graviton functions).
  2. Alternatively pass explicit pip wheel flags: `--platform manylinux2014_x86_64 --implementation cp --python-version 3.12 --only-binary=:all:` (or `manylinux2014_aarch64` for `arm64`).
  3. Pin `cryptography>=41.0.5` and `pydantic>=2.5` so prebuilt `cp312` manylinux wheels resolve without compiling Rust from source.
  4. Inspect `.so` files in the built ZIP with `file python/**/*.so` before deploying to confirm `ELF 64-bit LSB shared object` matches your Lambda `Architectures` setting.

Related deadline: Lambda Python 3.10 create/update restrictions — 2027-07-29.

Scan & codemod every occurrence locally ($79)

Fixing one function by hand rarely clears the whole stack. Download the $79 Offline Migration & Audit Toolkit to run air-gapped repo/IaC audits, Python 3.12/3.13 & AWS SDK v3 codemods, AL2023 native wheel Dockerfiles, and canary rollback templates with zero source upload (US buyers only · 30-day full refund policy).

Buy $79 Offline Toolkit (Instant Download) →  Full specs & sample

Check configured patterns in your project

The free EOLkits scanner processes files in your browser and flags selected related patterns in supported IaC and dependency files. File names and contents are not uploaded; bounded aggregate file and finding counts may be sent. It is not a complete source or AWS-account scan.

Prefer a 10-second check? Paste your config into the free AWS EOL checker. Pasted input is not uploaded; bounded first-party usage events may be sent.

Primary source: https://docs.aws.amazon.com/lambda/latest/dg/python-package.html

Inspect the $299 report sample and availability →