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

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

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

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

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?

I am facing a similar issue but my sam project structure is also proper. I have the same directory structure for another project and it’s working fine. But I don’t know why I have issues with my other project. Following is the error, please help: {"errorMessage": "Unable to import module 'app': No module named '<code_directory_name>'", "errorType": "Runtime.ImportModuleError", "requestId": "29d68e8f-fd24-4d56-85c8-84861f9b89cd", "stackTrace": []}%

@michaelschem @abrooksv @josh-padnick @rmzelnick

Our feature is #483