找不到 Lambda wkhtmltopdf 命令

Lambda wkhtmltopdf Command not found

我想在 AWS Lambda 函数中将 html 转换为 pdf。有一个节点包正在使用 wkhtmltopdf。这是它的 link.

https://www.npmjs.com/package/wkhtmltopdf

但是当我 运行 我的代码时,出现以下错误。

Error: /bin/sh: wkhtmltopdf: command not found
at Socket.<anonymous> (/var/task/node_modules/wkhtmltopdf/index.js:79:17)
at Socket.g (events.js:180:16)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
at emitReadable (_stream_readable.js:423:5)
at readableAddChunk (_stream_readable.js:166:9)
at Socket.Readable.push (_stream_readable.js:128:10)
at Pipe.onread (net.js:529:21)

有没有在 lambda 函数中安装 "wkhtmltopdf" 命令的方法。

来自文档 (https://www.npmjs.com/package/wkhtmltopdf):

First, you need to install the wkhtmltopdf command line tool on your system.

这里是关于如何在 lambda 上安装文件的说明 https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/

Lambda’s built-in sandbox lets you safely run code written in any language, because Lambda doesn’t rely on the language runtime to provide isolation between functions. You get the same protections regardless of whether Lambda starts a process for you or whether you start it yourself, and regardless of the language in which it’s written. With that out of the way, let’s look at how easy it is:

Including your own executables is easy; just package them in the ZIP file you upload, and then reference them (including the relative path within the ZIP file you created) when you call them from Node.js or from other processes that you’ve previously started. Ensure that you include the following at the start of your function code:

我能够在 nodejs 中添加二进制文件。实际上我们的代码 运行 在 /var/task 并且它在 process.env[‘LAMBDA_TASK_ROOT’]

因此,如果我们将二进制文件放在 zip 文件夹的根目录下,那么我们可以将其包含在如下路径中。

process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'];