容器化AWS Lambda中使用pdfkit和wkhtmltopdf生成PDF失败的问题求助
容器化AWS Lambda中使用pdfkit和wkhtmltopdf生成PDF失败的问题求助
各位好,我目前在做容器化的AWS Lambda服务,需要把一批HTML页面转换成PDF文件,于是选用了pdfkit搭配wkhtmltopdf来实现,但一直遇到执行失败的问题,报错内容如下:
No wkhtmltopdf executable found: "./wkhtmltopdf"
If this file exists please check that this process can read it or you can pass path to it manually in method call, check README. Otherwise please install wkhtmltopdf
以下是我的相关代码和配置:
Lambda 代码
import pdfkit as pdf # 注:原代码函数定义不完整,补全Lambda标准handler格式 def lambda_handler(event, context): config = pdf.configuration(wkhtmltopdf='./wkhtmltopdf') pdf.from_file( filelist_new, output_filename, options={ 'margin-top': '0.2in', 'margin-right': '0.2in', 'margin-bottom': '0.4in', 'margin-left': '0.2in', 'orientation': 'Landscape', 'page-size': 'A4', 'encoding': 'UTF-8', 'footer-line': '', 'footer-spacing': 1, 'footer-font-name': 'Times,serif', 'footer-font-size': '10' }, configuration=config, )
Dockerfile 配置
FROM umihico/aws-lambda-selenium-python:latest RUN pip install pdfkit RUN pip install boto3 RUN pip install wkhtmltopdf --target "./" COPY lambda_function.py ./ CMD [ "lambda_function.lambda_handler" ]
我还特意运行了Docker容器试图定位wkhtmltopdf的位置,但还是没能解决找不到可执行文件的问题。有没有朋友能帮忙分析下问题出在哪,或者给点解决思路呀?
备注:内容来源于stack exchange,提问作者ameesha gupta
相关产品推荐
相关产品推荐

