AWS Lambda Python层结构正常却出现导入错误,该如何解决?
AWS Lambda自定义Python层导入失败问题
我在AWS Lambda中创建了一个自定义Python层,结构如下:
/python |_/m_utilities |_/functions |_/__init__.py |_/Defaults.py |_/Athena.py |_/parameterizer |_/classes |_/__init__.py |_/AthenaLite.py |_/BaseParameter.py |_/__init__.py |_/misc
parameterizer目录下的__init__.py包含以下语句:from parameterizer.classes.AthenaLite import athena_parameterizer as athena_lite
Lambda处理程序开头的导入代码:
from m_utilities.functions.Athena import <various functions> from m_utilities.parameterizer import athena_lite
该结构在本地运行完全正常,所有导入均无问题,但在测试Lambda时出现错误:
[ERROR] Runtime.ImportModuleError: Unable to import module 'parameterizer'
调试时,我修改Lambda处理程序检查文件夹结构(显示正常),并打印m_utilities包下的模块,代码如下:
try: from m_utilities.parameterizer import athena_lite except: import os.path, pkgutil, m_utilities pkgpath = os.path.dirname(m_utilities.__file__) # 注:原代码中`fp_utilities`应为笔误,修正为`m_utilities` print([name for _, name, _ in pkgutil.iter_modules([pkgpath])])
AWS返回的结果为:
['functions', 'messaging', 'parameterizer', 'misc']
可见parameterizer模块确实存在,请问是什么操作错误导致无法导入?
内容的提问来源于stack exchange,提问作者meowmeow
相关产品推荐
相关产品推荐

