19

I'm using a AWS Lambda function to merge PDF files stored on S3. In addition to that, I need now to create a PDF file (from HTML and CSS). I was trying to use wkhtmltopdf, but it seems that I would have to install it using apt-get install (which I don`t think I have access on AWS Lambda).

Any ideas on how can I do it?

Any suggestions for wkhtmltopdf replacements?

Thanks!

Fabio Baldissera
  • 583
  • 1
  • 4
  • 15

5 Answers5

15

There are multiple projects on GitHub claiming to run wkhtmltopdf on Lambda. Here are a few.

Björn
  • 3,098
  • 2
  • 26
  • 40
  • All of these third-party projects have been archived or have not seen updates for years. Meanwhile, the `wkhtmltopdf`projects has releases specifically for use as AWS Lamba _Layers_. See my answer below: https://stackoverflow.com/a/66199918 – pixelistik Feb 25 '21 at 09:02
10

Include the wkhtmltopdf binary and making sure it has execution permission(chmod 755). Add the binary path to your language runtime. e.g. with nodejs

process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'] + '/bin/linux';
Fish
  • 449
  • 5
  • 10
8

There is a specific download of wkhtmltopdf for use with AWS Lambda.

It is meant to be used as a separately uploaded Layer.

pixelistik
  • 7,541
  • 3
  • 32
  • 42
6

Upload the binary inside a folder of your project for example in a folder "binary /" so that at the time of lambda execution you can call it by reference

1

Important caveat: If you want to use wkhtmltopdf successfully on AWS Lambda, you will need to use v0.12.4.

It turns out that newer versions have some issues with dynamic libraries. If you drill into it, you'll find some .so files missing.

Source: Richard Keller

haz
  • 1,549
  • 15
  • 20