Unable to import module 'main': No module named 'boto3'
Fixes Unable to import module 'main': No module named 'boto3' Use when Lambda invocation fails with Unable to import module ... No module named 'boto3' (or requests, etc.) Not for: the error names your own handler file (that is a packaging path problem, not boto3)
How to fix Unable to import module 'main': No module named 'boto3'
Lambda's Python runtime does not put boto3 on your function's import path the way local dev does. Package boto3 with your deployment zip (pip install boto3 -t .) or attach a Lambda layer containing boto3. Also double-check the handler string is file.function format.
The exact error
Unable to import module 'main': No module named 'boto3'Fix it
- Bundle it:
pip install boto3 -t ./package, copy your handler in, zip the package dir, upload.
Expected: boto3 inside the zip
- Or publish a layer:
mkdir python && pip install boto3 -t python/then zip the python dir and attach the layer.
Expected: function imports boto3 from the layer
- Verify the handler setting is
main.lambda_handler(file.function).
Expected: Runtime.ImportModuleError gone
When this applies
Lambda invocation fails with Unable to import module ... No module named 'boto3' (or requests, etc.)
When this does NOT apply
the error names your own handler file (that is a packaging path problem, not boto3)
Versions
AWS Lambda Python runtimes
Why it happens
Lambda only guarantees the runtime plus stdlib; third-party deps must ship in the zip or a layer.
Edge cases
Watch the 250MB unzipped deployment limit when bundling heavy deps.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.