lambda function Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'cerberus'

191 views Asked by At

I am trying to use Cerberus in AWS lambda but running into the below error when trying to execute the code. I created a custom layer and pointed it to zip file in S3 downloaded from here. Runtime env for lambda and layer is python3.11. Any ideas on how to fix this and use Cerberus in lambda?

[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'cerberus'

from cerberus import Validator
...
v = Validator(schema)
...

Zip file structure:

enter image description here

1

There are 1 answers

0
user0000 On BEST ANSWER

I fixed this by installing the library to a target folder and zipping the contents.

pip install Cerberus -t <myfolder>
cd <myfolder>
zip -r cerberus-1_3_5.zip .