[英]AWS lambda function does not find the main app when running a local sam invoke command. How do I make sam invoke find the app.py application?
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:我的 lambda 函数结构是:
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.当我运行导入 app.py 的test_handler.py时,pytests 通过。 It seems to me that sam invoke does not find the main app function when the project is ran as a programme.
在我看来,当项目作为程序运行时,sam invoke 没有找到主要的应用程序功能。
Any thoughts on how I can get the sam local invoke to recognise the app in app.py?关于如何让 sam local invoke 识别 app.py 中的应用程序的任何想法?
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!在 docker 文件中添加一个 '''COPY app.py ./''' 解决了这个问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.