aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Hello World, Unable to import module 'app': No module named 'app'

Open OSIVZ opened this issue 2 years ago • 5 comments

Dear folks,

I read through #1345 thread. It is closed. There is a reference to the fact that on Linux (WSL falls into the definition) , a code must be in /home/{user} and in my case it is, yet the issue persists. Running environment: Windows 11, WSL 1 SAM CLI, version 1.97.0 Docker desktop version 4.21.1 (114176

The code is located in /home/{user}/sam-app

command: sam local invoke HelloWorldFunction -e events/event.json --debug

2023-09-15 13:05:01,864 | Code /home/{user}/sam-app/.aws-sam/build/HelloWorldFunction is not a zip/jar file 2023-09-15 13:05:03,864 | Local image is up-to-date 2023-09-15 13:05:03,879 | Using local image: public.ecr.aws/lambda/python:3.10-rapid-x86_64.

2023-09-15 13:05:03,880 | Mounting /home/{user}/sam-app/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated, inside runtime container 2023-09-15 13:05:04,414 | Starting a timer for 3 seconds for function 'HelloWorldFunction' START RequestId: e2fbc965-09e9-4b65-a6f5-663807520578 Version: $LATEST Traceback (most recent call last): Unable to import module 'app': No module named 'app' END RequestId: e2fbc965-09e9-4b65-a6f5-663807520578 REPORT RequestId: e2fbc965-09e9-4b65-a6f5-663807520578 Init Duration: 0.28 ms Duration: 79.13 ms Billed Duration: 80 ms Memory Size: 128 MB Max Memory Used: 128 MB {"errorMessage": "Unable to import module 'app': No module named 'app'", "errorType": "Runtime.ImportModuleError", "requestId": "e2fbc965-09e9-4b65-a6f5-663807520578", "stackTrace": []}2023-09-15 13:05:05,953 | Cleaning all decompressed code dirs

Any suggestion? Thank you

OSIVZ avatar Sep 18 '23 01:09 OSIVZ

Smells of docker mount issues.

Are you able to mount volumes directly through the docker cli? There maybe folders/directories that you would need to share.

sriram-mv avatar Sep 18 '23 17:09 sriram-mv

@sriram-mv Thank you for the swift reply.

sam local invoke command triggers image build process, but volumes are not created. Docker UI lists two images. No volumes and also no containers. Should the volumes be created? Which folder/directory must be shared and with what? Please explain.

Thank you

OSIVZ avatar Sep 18 '23 18:09 OSIVZ

Also having the same problem while using Rancher Desktop 1.10.0

gpr-indevelopment avatar Oct 04 '23 00:10 gpr-indevelopment

Same issue in Rancher Desktop 1.12.2

ISimion avatar Jan 31 '24 21:01 ISimion

Me too! The same issue in Rancher Desktop!!!

achristofaro avatar May 06 '24 11:05 achristofaro