运行本地sam调用命令时,AWS lambda函数找不到主应用程序。如何使sam调用查找app.py应用程序?

2024-05-03 15:13:58 发布

您现在位置:Python中文网/ 问答频道 /正文

失败的命令是:

/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" 

并输出一个错误:

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

我的lambda函数结构是:

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

当我运行导入app.py的test\u handler.py时,pytests通过。 在我看来,当项目作为程序运行时,saminvoke没有找到主应用程序函数

关于如何让sam本地调用在app.py中识别应用程序,有什么想法吗

My template.yaml文件如下: enter image description here

enter image description here