aws / aws/aws-sam-cli

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

Open
#5,941 8 comments 0 reactions 0 assignees View on GitHub
area/docker
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

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

Contributor guide

Open the contributing guide

Research direction

Reproduce the reported command, `sam local invoke HelloWorldFunction -e events/event.json --debug`, in the stated WSL and Docker environment. Inspect `/home/{user}/sam-app/.aws-sam/build/HelloWorldFunction` and the debug output to determine why the `app` module is not available; done means the HelloWorld function imports and invokes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, python
Domain
cli, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.