I have been using html-pdf (phantomjs) for creating PDF on AWS Lambda with NodeJS 8.0 and it was working fine. Since AWS Lambda has stopped support on NodeJS 8.0 we have updated our NodeJS version to the latest 12.x and we are now getting the following error when we run out PDF Lambda function:
{"errorType":"Error","errorMessage":"write EPIPE","code":"EPIPE","errno":"EPIPE","syscall":"write","stack":["Error: write EPIPE"," at afterWriteDispatched (internal/stream_base_commons.js:154:25)"," at writeGeneric (internal/stream_base_commons.js:145:3)"," at Socket._writeGeneric (net.js:784:11)"," at Socket._write (net.js:796:8)"," at doWrite (_stream_writable.js:403:12)"," at writeOrBuffer (_stream_writable.js:387:5)"," at Socket.Writable.write (_stream_writable.js:318:11)"," at PDF.PdfExec [as exec] (/var/task/node_modules/html-pdf/lib/pdf.js:141:15)"," at PDF.PdfToBuffer [as toBuffer] (/var/task/node_modules/html-pdf/lib/pdf.js:44:8)"," at /var/task/index.js:121:38"]}
phantomPath: './phantomjs_lambda/phantomjs'
process.env.FONTCONFIG_PATH='/var/task/fonts'
I tried to check similar issues in StackOverflow. I have pointed the phantomjs path correctly, also have the fontconfig in place. We are now stuck as we are unable to update the Lambda function. Any help will be highly appreciated.
Update: Changed the path to phantomjs binary:
phantomPath: './node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs'
After changing the path to phantomjs binary, the error has changed to:
{"errorType":"Error","errorMessage":"write EPIPE","code":"EPIPE","errno":"EPIPE","syscall":"write","stack":["Error: write EPIPE"," at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:92:16)"]}
I recently face this issue as well, when i have update Node version of lambda to 14.x. After following below steps i can able to resolved my issue.
I passed phantomPath : "./node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs"
at pdf.create(html,tempParamms)
.so
files and paste them in your project root.fonts
in your project root..so
files and paste all files in newly created fonts
directory.fonts/fonts.conf
.FONTCONFIG_PATH
with value = /var/task/fonts
fonts/fonts.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/var/task/fonts/</dir>
<cachedir>/tmp/fonts-cache/</cachedir>
<config></config>
<match target="font">
<edit mode="assign" name="rgba">
<const>rgb</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hinting">
<bool>true</bool>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hintstyle">
<const>hintslight</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
</match>
<match target="font">
<edit mode="assign" name="lcdfilter">
<const>lcddefault</const>
</edit>
</match>
</fontconfig>
Ref : Link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With