0
votes

The command which fails is:

/usr/local/bin/sam local invoke HelloWorldFunction --template /home/peter/Dropbox2/Dropbox/clothes_recco/production/bodyestimate/.aws-sam/build/template.yaml --event "/tmp/[Local] BodyEstimate-event109.json" 

and it outputs an error:

{"errorMessage": "Unable to import module 'app': No module named 'bodyestimate'", "errorType": "Runtime.ImportModuleError", "requestId": "3b3bb307-9647-4171-99a6-24dae52b3b55", "stackTrace": []}END 

My lambda function structure is:

bodyestimate/
   bodyestimate/
       template.yaml
       packaged.yaml
       app.py
       requirements.txt
       __init__.py
       Dockerfile
   test/
      unit/ 
         test_handler.py

The pytests pass when I run the test_handler.py which imports the app.py. It seems to me that sam invoke does not find the main app function when the project is ran as a programme.

Any thoughts on how I can get the sam local invoke to recognise the app in app.py?

My template.yaml file is below: enter image description here

enter image description here

1
Welcome to Stack Overflow. Please take the tour, read How do I ask a good question? as well as How to create a Minimal, Reproducible Example and then update your question. - Ermiya Eskandary
Is it the same error if you try with the template in the bodyestimate (/home/peter/Dropbox2/Dropbox/clothes_recco/production/bodyestimate/template.yaml) ? - Ghamgui Khaled

1 Answers

0
votes

The problem was to do with the app file not being copied into the container.

Adding a '''COPY app.py ./''' into the docker file solved the problem!