question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to import module 'app': No module named 'requests' - Hello World example

See original GitHub issue

Describe the bug Trying to invoke the AWS Sam Helloworld example using the plugin fails.

/Users/theoribeiro/anaconda3/bin/sam local invoke --template "/private/var/folders/sr/dx8vj9sd4gqcm35m8ygw7wsm0000gp/T/[Local] app.lambda_handler-template3196.yaml" --event "/private/var/folders/sr/dx8vj9sd4gqcm35m8ygw7wsm0000gp/T/[Local] app.lambda_handler-event1667.json" --debug-port 49597 --debugger-path /Applications/PyCharm.app/Contents/helpers/pydev --debug-args "-u /tmp/lambci_debug_files/pydevd.py --multiprocess --port 49597 --file" 2019-01-15 16:22:07 Found credentials in environment variables. 2019-01-15 16:22:08 Invoking app.lambda_handler (python3.6) 2019-01-15 16:22:08 Decompressing /var/folders/sr/dx8vj9sd4gqcm35m8ygw7wsm0000gp/T/6421406990658360484.zip

Fetching lambci/lambda:python3.6 Docker container image...... 2019-01-15 16:22:09 Mounting /private/var/folders/sr/dx8vj9sd4gqcm35m8ygw7wsm0000gp/T/tmpbj35fu9a as /var/task:ro inside runtime container Connected to pydev debugger (build 183.5153.39) START RequestId: c195948c-81dc-44de-a3d6-c9f6ddcca32c Version: $LATEST

Unable to import module 'app': No module named 'requests' END RequestId: c195948c-81dc-44de-a3d6-c9f6ddcca32c {"errorMessage": "Unable to import module 'app'"} REPORT RequestId: c195948c-81dc-44de-a3d6-c9f6ddcca32c Duration: 15 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 27 MB

If I unzip the package file in the temp folder I can see that indeed the requests package was not installed correctly in the package.

To reproduce

  1. Start a new AWS SAM Project
  2. Click on Lambda icon next to function handler
  3. Click on Run or Debug
  4. Error shows up in Console

Expected behavior Function should be invoked after compiling the requirements correctly.

Your Environment

  • OS: Mac OS X - Mojave
  • JetBrains’ Product: PyCharm Professional
  • JetBrains’ Product Version: 2018.3
  • Toolkit Version: v1.1
  • SAM CLI Version: 0.10.0
  • JVM/Python Version: Anaconda 3.6

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
josh-padnickcommented, Jul 9, 2019

I think the issue here is that the error message is wrong. I found I was able to resolve this when I removed the following from my Python Lambda function:

import requests
3reactions
ajbufortcommented, Feb 23, 2019

Note that I am getting the same type of error on Windows 10, and I HAVE installed the required package, boto3, for my sample function:

image

image

So what’s the workaround for someone in my position?

Read more comments on GitHub >

github_iconTop Results From Across the Web

aws lambda Unable to import module 'lambda_function'
requests library doesn't come by default in lambda. It looks like you are trying to import it in your function / library somewhere....
Read more >
[Fixed] ModuleNotFoundError: No module named 'requests'
This is supposed to import the Pandas library into your (virtual) environment. However, it only throws the following ImportError: No module named requests...
Read more >
No module named 'requests' in Python
The Python "ModuleNotFoundError: No module named 'requests'" occurs when we forget to install the requests module before importing it or ...
Read more >
No module named requests on the AWS Python Lambda ...
For that I am using request function, but I am getting this below error. Unable to import module 'lambda_function': No module named requests....
Read more >
ModuleNotFoundError: no module named Python Error ...
you are importing a module using the wrong path. How to fix the ModuleNotFoundError in Python. As I mentioned in the previous section,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found