Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use pdfkit in AWS Lambda?

I'm using AWS Lambda to generate pdf file using a ninja2 template. I am trying to use pdfkit to convert my HTML into pdf. I realize pdfkit has an internal dependency - wkhtmltopdf which needs to be used as a binary or installed via a package manager. I am not sure how to make this work on AWS Lambda?

With my current template and python code using pdfkit, I am getting the following error -

{
  "errorMessage": "No wkhtmltopdf executable found: \"b''\"\nIf this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf",
  "errorType": "OSError",
.....
.....
}

Any ideas on how can I make pdfkit work on lambda?

Any suggestions for wkhtmltopdf replacements?

Thanks

like image 855
iCHAIT Avatar asked Jan 27 '26 19:01

iCHAIT


1 Answers

I've made a simple demo on using PDFKit using Serverless framework using layer. Checkout https://medium.com/@crespo.wang/create-pdf-using-pdfkit-on-serverless-aws-lambda-with-layer-721ca86724b2

like image 92
Crespo Wang Avatar answered Jan 29 '26 13:01

Crespo Wang