问题描述
我具有以下文件夹结构
src
-- functions
-- Test
-- __init__.py
-- app.py
-- create_data.py
-- template.yaml
在app.py
里面,我知道:
from .create_data import create_data
....
def handler(event,context):
return create_data(item=event)
...
在我的template.yaml中,我有:
TestFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/functions/Test
Handler: app.handler
....
所以,我的想法是让一个app.py
处理请求并使用另一个.py
(在这种情况下为create_data.py
)来处理请求并保存到数据库中
但是,当我尝试运行该函数(在本地或在API Gateway上)时,收到错误消息:
{"errorType":"Runtime.ImportModuleError","errorMessage":"Unable to import module 'app': attempted relative import with no kNown parent package"}
如果我删除了create_data
的导入,它将起作用。
该如何解决?我的意思是,我不想总是将我的所有代码都放在app.py
中,我想拆分成文件
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)