Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.4K
Views
AWS lambda html-pdf phantomjs "Error: escribir EPIPE" en NodeJS 12.x

He estado usando html-pdf (phantomjs) para crear PDF en AWS Lambda con NodeJS 8.0 y funcionó bien. Dado que AWS Lambda dejó de ser compatible con NodeJS 8.0, hemos actualizado nuestra versión de NodeJS a la última 12.x y ahora recibimos el siguiente error cuando nos quedamos sin la función PDF Lambda:

{"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'

Traté de verificar problemas similares en StackOverflow. He señalado la ruta phantomjs correctamente, también tengo el fontconfig en su lugar. Ahora estamos atascados porque no podemos actualizar la función Lambda. Cualquier ayuda será muy apreciada.

Actualización: cambió la ruta al binario phantomjs:

phantomPath: './node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs'

Después de cambiar la ruta al binario phantomjs, el error cambió a:

 {"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)"]}
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Recientemente también enfrenté este problema, cuando actualicé la versión Node de lambda a 14.x. Después de seguir los pasos a continuación, puedo resolver mi problema.

Pasé phantomPath : "./node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs" en pdf.create(html,tempParamms)

  • obtenga todos los archivos de este Repo:https://github.com/naeemshaikh27/phantom-lambda-fontconfig-pack
  • Copie todos los archivos .so y péguelos en la raíz de su proyecto.
  • Cree un directorio llamado fonts en la raíz de su proyecto.
  • Copie todos los archivos excepto los archivos .so y pegue todos los archivos en el directorio de fonts recién creado.
  • Reemplace el código a continuación del archivo fonts/fonts.conf .
  • Agregue la variable de entorno Lambda FONTCONFIG_PATH con valor = /var/task/fonts
  • Cargue el código en Lambda.

fuentes/fuentes.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>

Referencia: Enlace

over 4 years ago · Santiago Trujillo Report

0

Está recibiendo este error porque AWS extrae utilidades básicas en el entorno del nodo 10.x al 12.x (por ejemplo, ImageMagick).

La solución es incluir la funcionalidad que falta usted mismo o usar capas lambda. Aquí hay información sobre capas lambda con ImageMagic https://github.com/serverlesspub/imagemagick-aws-lambda-2

Para leer más sobre este problema, sugiero consultar el foro de AWS aquí: https://forums.aws.amazon.com/thread.jspa?threadID=305691

over 4 years ago · Santiago Trujillo Report

0

html-pdf usa un paquete npm phantomjs-preconstruido

phantomjs-preconstruido instalará automáticamente phantomjs según su sistema operativo/arquitectura

Es importante que node_modules no se copie en la imagen de la ventana acoplable, sino que se instale en la imagen de la ventana acoplable.

Creé una imagen acoplable personalizada para Azure, para AWS necesitaría hacer lo mismohttps://docs.aws.amazon.com/lambda/latest/dg/images-create.html

Siguiendo este hilo, también necesitará instalar un par de dependencias https://gist.github.com/julionc/7476620

Asegúrese de tener node_modules/ en su archivo .dockerignore

 node_modules/

Archivo Docker para funciones azules (Debería crear un archivo docker simular para AWS lambdas)

 FROM mcr.microsoft.com/azure-functions/node:3.0-node12-appservice RUN apt-get update RUN apt-get install build-essential chrpath libssl-dev libxft-dev -y RUN apt-get install libfreetype6 libfreetype6-dev -y RUN apt-get install libfontconfig1 libfontconfig1-dev -y ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ AzureFunctionsJobHost__Logging__Console__IsEnabled=true \ OPENSSL_CONF=/etc/ssl/ COPY . /home/site/wwwroot RUN cd /home/site/wwwroot && \ npm install

Agregar OPENSS_CONF=/etc/ssl/ es esencial ya que phantomjs generará otro error

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!