Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use wkhtmltopdf on AWS Lambda

Greeting,

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!

like image 684
Fabio Baldissera Avatar asked Feb 09 '17 20:02

Fabio Baldissera


People also ask

Is Botocore available in Lambda?

Because the boto3 module is already available in the AWS Lambda Python runtimes, don't bother including boto3 and its dependency botocore in your Lambda deployment zip file.

Can I use Python packages with AWS Lambda?

Lambda supports Python, which is a great option if you've got experience using it. However, one of the downsides to Lambda is that by default you won't be able to import your trusted packages, like Pandas. I'm going to show you the easiest way of importing any package you need for your Lambda function.

Can Lambda access local files?

You can configure a function to mount an Amazon Elastic File System (Amazon EFS) file system to a local directory. With Amazon EFS, your function code can access and modify shared resources safely and at high concurrency.

What languages can you use with AWS Lambda?

AWS Lambda natively supports Java, Go, PowerShell, Node. js, C#, Python, and Ruby code, and provides a Runtime API which allows you to use any additional programming languages to author your functions. Please read our documentation on using Node. js, Python, Java, Ruby, C#, Go, and PowerShell.


2 Answers

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

  • https://github.com/lubos/aws-lambda-wkhtmltopdf
  • https://github.com/dimiro1/lambda-wkhtmltopdf
  • https://github.com/jpaolin/aws-lambda-s3-wkhtmltopdf
like image 83
Björn Avatar answered Sep 17 '22 11:09

Björn


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';
like image 41
Fish Avatar answered Sep 18 '22 11:09

Fish