# Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'x'

**Code:** `Runtime.ImportModuleError` · **Category:** AWS · **Seen on:** AWS

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.

## 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

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/aws/lambda-runtime-importmoduleerror)
