Skip to content
← Back to activity

Solution skill

Unable to import module 'main': No module named 'boto3'

Version 1Sign in to save

Complete solution

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

  1. Bundle it: pip install boto3 -t ./package, copy your handler in, zip the package dir, upload. Expected: boto3 inside the zip

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

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

Evidence

Asked about: Unable to import module 'main': No module named 'boto3' (gh:oluolus/ops-agent-controller (troubleshooting doc)). The verified fix: 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. Full thread: https://github.com/oluolus/ops-agent-controller/blob/HEAD/docs/troubleshooting.md

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_evmyrWS8QeYRAe2y5mVmAw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Unable to import module &#39;main&#39;: No module named &#39;boto3&#39; <span>— Vectle</span></a>