Runtime.ImportModuleError ☁️ AWS

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

  1. Install dependencies into the package directory and zip from inside it
  2. Check the handler setting matches file.function
  3. Build native deps for Amazon Linux (Docker/sam build --use-container)

Detailed fix by platform

Python

  1. python
    pip install -r requirements.txt -t package/
    cp lambda_function.py package/
    cd package && zip -r ../function.zip .

AWS CLI

  1. sam build --use-container && sam deploy

How to diagnose

  1. Zip — unzip -l function.zip | head (file at root?)
  2. Handler — Configuration → Runtime settings
  3. 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:

🧠 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.