I have a custom python layer in AWS Lambda with the structure:
/python
|_/m_utilities
|_/functions
|_/__init__.py
|_/Defaults.py
|_/Athena.py
|_/parameterizer
|_/classes
|_/__init__.py
|_/AthenaLite.py
|_/BaseParameter.py
|_/__init__.py
|_/misc
- The parameterizer init.py contains
from parameterizer.classes.AthenaLite import athena_parameterizer as athena_lite
The lambda handler starts with:
from m_utilities.functions.Athena import <various functions>
from m_utilities.parameterizer import athena_lite
This structure works as expected locally, I'm able to import everything with no issues. When I attempt to test the lambda however I get the error: [ERROR] Runtime.ImportModuleError: Unable to import module 'parameterizer'
When attempting to debug, one of the things I tried was editing the lambda handler to examine the folder structure (which looks correct) and printing off the modules within the m_utilities package to see if my 'parameterizer' module exists there.
This in the lambda handler:
try:
from m_utilities.parameterizer import athena_lite
except:
import os.path, pkgutil,m_utilities
pkgpath = os.path.dirname(fp_utilities.__file__)
print([name for _, name, _ in pkgutil.iter_modules([pkgpath])])
Returns in AWS:
['functions', 'messaging', 'parameterizer', 'misc']
The module appears to be there, so what am I doing incorrectly that it is unable to import it?
For some reason, I'm not sure why, this structure worked in AWS:
I moved the 'parameterizer' module into the top-level folder, and
from parameterizer import athena_lite
worked.