Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'x'
Lambda couldn’t load your handler file or one of its dependencies — the package is missing from the deployment zip/layer or the handler path is wrong.
Seen on:
AWS
Meaning
Lambda only has what you upload plus the runtime. pip/npm dependencies must be inside the zip (or a layer) at the right path, compiled for Amazon Linux and the function’s architecture. Node ESM/CommonJS mismatches produce the same error type.
Common causes
- Dependencies not included in the zip/layer
- Handler file not at the zip root (nested folder)
- Native packages built on macOS/Windows or for the wrong architecture (arm64 vs x86_64)
- Node: ESM import in a CommonJS handler (or vice versa)
⚡ Quick fix
- Install dependencies into the package directory and zip from inside it
- Check the handler setting matches file.function
- Build native deps for Amazon Linux (Docker/sam build --use-container)
Detailed fix by platform
Python
- python
pip install -r requirements.txt -t package/ cp lambda_function.py package/ cd package && zip -r ../function.zip .
AWS CLI
sam build --use-container && sam deploy
How to diagnose
- Zip — unzip -l function.zip | head (file at root?)
- Handler — Configuration → Runtime settings
- Arch — Function architecture vs wheels
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in AWS
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026