Skip to content
Latchkey

AWS Lambda "Unable to import module 'handler': No module named" (Python) in CI

The Python Lambda runtime failed to import your handler module during init because a package it imports is not in the deployment package. Lambda does not install requirements for you, so anything not vendored is missing.

What this error means

An invoke returns "Unable to import module 'lambda_function': No module named 'requests'" (or your own package). The failure is in the init phase, before the handler runs.

lambda
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function':
No module named 'requests'

Common causes

Dependencies were not installed into the package

The zip has your code but not the site-packages for third-party imports, because pip install -t . (or a layer) was never run against the artifact.

Wrong wheel platform

A package with native code was installed for the CI host OS/arch, not for the Lambda runtime, so the compiled module is not importable there.

How to fix it

Vendor dependencies into the package

  1. Install requirements into the package directory.
  2. Zip the code together with the installed packages.
  3. Re-deploy and invoke.
Terminal
pip install -r requirements.txt -t package/
cp lambda_function.py package/
(cd package && zip -r ../function.zip .)

Build native deps for the Lambda platform

Install manylinux wheels matching the function architecture so native modules load.

Terminal
pip install \
  --platform manylinux2014_x86_64 --only-binary=:all: \
  --target package/ -r requirements.txt

How to prevent it

  • Install and vendor dependencies into every Python Lambda artifact.
  • Target the correct manylinux platform for native packages.
  • Add a CI invoke smoke test that catches import errors early.

Related guides

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