0

I'm was able to add my PyNaCl library as a layer into Lambda (Python 3.8) but for some reason when I try and test the code I get the error

"errorMessage": "Unable to import module 'lambda_function': No module named '_cffi_backend'", "errorType": "Runtime.ImportModuleError"

Now when I use PyCharm locally and install the PyNaCl library into the venv, I have no execution errors. Does Lambda require the file hierarchy to be different? I zipped up the library as /lib/python3.8/site-packages with the only library included being PyNaCl

2 Answers 2

3

There are 2 possible reasons to your problem:

  1. The lib folder structure is inaccurate. Try python/lib/python3.8/site-packages, then zip and upload again

  2. If (1) does not work, this is likely the library you used was compiled on a platform not compatible to Amazon Lambda. Amazon Lambda is based on Amazon Linux. A simple way is to create a docker image with the docker file provided by AWS(note your python version):

https://docs.aws.amazon.com/lambda/latest/dg/python-image.html

Then compile the PyNaCl libraries within the container, take out the compiled library files and do the upload again.

Sign up to request clarification or add additional context in comments.

Comments

0

Lambda requires that layer .zip archive directory structure starts with python dir. Usually what works is this:

mkdir python
pip install pynacl -t python

This should create correct structure. Zip and upload as a layer.

Alternatively you can build docker image with dependencies and use it in lambda: https://docs.aws.amazon.com/lambda/latest/dg/images-create.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.