Stephen Stilwell
Stephen Stilwell

Reputation: 588

Do I need to include Python PDF Toolkit or pypdftk as a Lambda Layer?

Lambda Layer Docs for Reference: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html

The project was written in Python 2.7, which is appears AWS Lambda has deprecated. So I've attempted to update the code to the latest release Py 3.9 and most of my errors are resolved.

Due to very poor documentation & lack of comments, I've been stuck trying to figure out which parts of this codebase go to which AWS services.

For example: this project had 3 different init.py files & one of them is even empty. The code apparently was working before I received it.

I've no idea which pieces of this project go to which services. Some of them are obvious. Certainly the Lambda.py is supposed to go to a lambda function.

In short the project does this: Get JSON from Webhook, perform calculation & alter JSON, convert to PDF, email PDF to customer, store PDF in S3 bucket.

The project uses a library called pypdftk or Python PDK Toolkit. Hopefully this is compatible with Py 3.9, because apparently Py 2.7 is deprecated on AWS Lambda.

It appears this project was run almost entirely as a Lambda Function, using Lambda.py as an entry point, and importing the rest the .py code files into that entry point.

Will I need to include this Python PDF Toolkit as a Lambda Layer? To my knowledge, all libraries not included in the Standard Python 3.9 library must be added as a Lambda Layer.

Additionally, is this python pdf toolkit only compatible with Python 2.7? 2.7 is no longer supported by AWS Lambda, so I have updated the code to be compatible with Py 3.9

EDIT: enter image description here

These are the project files & directories.
Do I upload the entire project zipped into Lambda?
Does a portion of this need to be uploaded to a Lambda Layer?
Will I need to set-up & configure an EC2? S3? SES?

Upvotes: 0

Views: 419

Answers (1)

kgiannakakis
kgiannakakis

Reputation: 104198

I am assuming that you need https://github.com/revolunet/pypdftk, which should be compatible with Python 3.9. This is a wrapper for the pdftk binary, which must be installed separately in your environment. Lambda functions execute in a container with Amazon Linux. The recommended way to use a native binary with Lambda is to create a layer. There are some projects in Github that generate the layer:

Both of them are old, so use with caution.

Upvotes: 1

Related Questions