Reputation: 31
I have been working on Lambda to convert pdf to png and using the pdf2image library to create a layer for my Lambda. I tried in many different ways but seems it doesn't work for me.
"errorMessage": "Unable to import module 'lambda_function': No module named 'pdf2image'", "errorType": "Runtime.ImportModuleError"
I would appreciate your help!
Thanks
Upvotes: 0
Views: 1666
Reputation: 9402
So you want to include the "pdf2image" library for your lambdas to reference. To make a layer, you would need to create a directory structure that contains that code, then zip the entire directory. It may be as follows:
/python
/pdf2image
__init__.py
pdf2image.py
...
When zipped, the zip file must have the "python" folder and inside of that you put your code. If you do this and also install your common code as a package, you can import it in your local code and in your lambdas using the same import.
What I do is use pip install to install to a certain file location--the location that I then zip into a layer. For example, if I wanted to make a layer for the pdf2image library I might do
pip install --target=c:\myLayers\python pdf2image
That will install the library files into the location I specified, which makes it easy to know what to zip up (just create a zip that includes the "python" directory).
Then of course be sure you reference the layer (by specific version) in your lambda.
Upvotes: 1