0

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

1

1 Answer 1

1

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.

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

2 Comments

Thank you! This is working but now I have different issues, "errorMessage": "Unable to get page count. Is poppler installed and in PATH?", "errorType": "PDFInfoNotInstalledError"
You may want to make a new question for this new issue and post the full details. If my response answered your original post, you can click the checkmark option to accept it.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.