Can I use wkhtmltopdf on AWS Lambda
Asked Answered
A

5

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!

Ariosto answered 9/2, 2017 at 20:39 Comment(0)
C
15

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

Crossbench answered 29/3, 2017 at 5:18 Comment(1)
All of these third-party projects have been archived or have not seen updates for years. Meanwhile, the wkhtmltopdfprojects has releases specifically for use as AWS Lamba Layers. See my answer below: stackoverflow.com/a/66199918Affected
S
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';
Sequoia answered 21/2, 2018 at 0:12 Comment(4)
How to generate binaryVaucluse
@dominic-torreto you can find the binary from wkhtmltopdf.org/downloads.html#stableSequoia
yeah. got it from /user/local/bin.Vaucluse
why not just use a layer?Gooseherd
A
10

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

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

Affected answered 14/2, 2021 at 20:42 Comment(0)
E
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

Extrinsic answered 9/2, 2017 at 21:17 Comment(0)
D
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

Dyaus answered 25/6, 2020 at 1:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.