lambci / docker-lambda

Docker images and test runners that replicate the live AWS Lambda environment
MIT License
5.83k stars 431 forks source link

"Unable to import module 'app': No module named 'app'" #301

Closed nidhinnyc closed 4 years ago

nidhinnyc commented 4 years ago

When I try to run lambda using the below command it gives the error unable to import the module. If I get inside the container and check the /var/task folder I can see the files in the folder.

command docker run --rm -v /Users/nidhinsurendran/Dev/pythonsamaws:/var/task:ro,delegated lambci/lambda:python3.8 app.lambda_handler

Error {"errorType":"Runtime.ImportModuleError","errorMessage":"Unable to import module 'app': No module named 'app'"}

Template and folder image

Has anyone encountered this issue?

mhart commented 4 years ago

It doesn't look like you're mounting your hello_world directory at /var/task.

Lambda looks for the modules at the top-level.

So try:

docker run --rm -v \
  /Users/nidhinsurendran/Dev/pythonsamaws/hello_world:/var/task:ro,delegated \
  lambci/lambda:python3.8 \
  app.lambda_handler
nidhinnyc commented 4 years ago

@mhart , thanks a lot that worked.