Giter Site home page Giter Site logo

brandonlim-hs / wkhtmltopdf-aws-lambda-layer Goto Github PK

View Code? Open in Web Editor NEW
71.0 4.0 21.0 67 KB

AWS Lambda Layer for wkhtmltopdf

License: MIT License

Shell 66.99% Dockerfile 13.03% JavaScript 3.79% Java 13.32% Python 2.86%
aws-lambda-layer wkhtmltopdf amazon-linux-2

wkhtmltopdf-aws-lambda-layer's Introduction

wkhtmltopdf as AWS Lambda Layer

wkhtmltopdf with dependencies published as AWS Lambda Layer.

Operating Systems

This layer supports both Amazon Linux and Amazon Linux 2.

Getting Started

Add this layer to Lambda function by providing the layer version ARN.

Version ARNs

Region ARN
ap-east-1 arn:aws:lambda:ap-east-1:347599033421:layer:wkhtmltopdf-0_12_6:1
ap-northeast-1 arn:aws:lambda:ap-northeast-1:347599033421:layer:wkhtmltopdf-0_12_6:1
ap-northeast-2 arn:aws:lambda:ap-northeast-2:347599033421:layer:wkhtmltopdf-0_12_6:1
ap-south-1 arn:aws:lambda:ap-south-1:347599033421:layer:wkhtmltopdf-0_12_6:1
ap-southeast-1 arn:aws:lambda:ap-southeast-1:347599033421:layer:wkhtmltopdf-0_12_6:1
ap-southeast-2 arn:aws:lambda:ap-southeast-2:347599033421:layer:wkhtmltopdf-0_12_6:1
ca-central-1 arn:aws:lambda:ca-central-1:347599033421:layer:wkhtmltopdf-0_12_6:1
eu-central-1 arn:aws:lambda:eu-central-1:347599033421:layer:wkhtmltopdf-0_12_6:1
eu-north-1 arn:aws:lambda:eu-north-1:347599033421:layer:wkhtmltopdf-0_12_6:1
eu-west-1 arn:aws:lambda:eu-west-1:347599033421:layer:wkhtmltopdf-0_12_6:1
eu-west-2 arn:aws:lambda:eu-west-2:347599033421:layer:wkhtmltopdf-0_12_6:1
eu-west-3 arn:aws:lambda:eu-west-3:347599033421:layer:wkhtmltopdf-0_12_6:1
sa-east-1 arn:aws:lambda:sa-east-1:347599033421:layer:wkhtmltopdf-0_12_6:1
us-east-1 arn:aws:lambda:us-east-1:347599033421:layer:wkhtmltopdf-0_12_6:1
us-east-2 arn:aws:lambda:us-east-2:347599033421:layer:wkhtmltopdf-0_12_6:1
us-west-1 arn:aws:lambda:us-west-1:347599033421:layer:wkhtmltopdf-0_12_6:1
us-west-2 arn:aws:lambda:us-west-2:347599033421:layer:wkhtmltopdf-0_12_6:1

See /arns directory for other wkhtmltopdf versions.

Usage

wkhtmltopdf binary will be extracted to the /opt/bin.

wkhtmltopdf can be executed directly as a command line binary, or via a wrapper.

Refer to /tests directory for example usage.

Build, Test, Publish

Refer to the following scripts to build and publish your own wkhtmltopdf layer.

  1. Run ./build.sh to build a new layer zip.
  2. Run ./test.sh to test the layer zip.
  3. Run ./publish.sh to publish the layer zip to regions specified in /config/regions.txt.

Fonts

See fonts-aws-lambda-layer to use fonts on AWS Lambda.

wkhtmltopdf-aws-lambda-layer's People

Contributors

brandonlim-hs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wkhtmltopdf-aws-lambda-layer's Issues

libjpeg.so.62: cannot open shared object file

This is fantastic. Thank you!

I'm running into one issue while replicating what's going on in the tests locally:

index.js

let { execSync } = require('child_process');

exports.handler = async (event, context, callback) => {
  execSync("ldd /opt/bin/wkhtmltopdf", { encoding: "utf8", stdio: "inherit" });
  execSync("wkhtmltopdf -V", { encoding: "utf8", stdio: "inherit" });

  callback(null, {'foo': 'bar'});
};
$ sam build myFunction
...Build Succeeded...
$ sam local invoke -e event.json myFunction
Invoking index.handler (nodejs12.x)
arn:aws:lambda:us-east-1:347599033421:layer:wkhtmltopdf:1 is already cached. Skipping download
Requested to skip pulling images ...

Mounting /Users/stevenspiel/mobile/wkhtmltopdf-lambda/.aws-sam/build/myFunction as /var/task:ro,delegated inside runtime container
START RequestId: c361ad4f-866a-1450-c1dc-6a3e0f8318fe Version: $LATEST
	linux-vdso.so.1 (0x00007fff643f0000)
	libjpeg.so.62 => not found
	libpng15.so.15 => not found
	libXrender.so.1 => not found
	libfontconfig.so.1 => not found
	libfreetype.so.6 => not found
	libXext.so.6 => not found
	libX11.so.6 => not found
	libssl.so.10 => /lib64/libssl.so.10 (0x00007f7dc8912000)
	libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f7dc84bd000)
	libz.so.1 => /lib64/libz.so.1 (0x00007f7dc82a8000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f7dc80a4000)
	librt.so.1 => /lib64/librt.so.1 (0x00007f7dc7e9c000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f7dc7c7e000)
	libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f7dc78fc000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f7dc75bc000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f7dc73a6000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f7dc6ffb000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f7dc8b81000)
	libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f7dc6daf000)
	libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f7dc6acb000)
	libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f7dc68c7000)
	libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f7dc6696000)
	libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f7dc6487000)
	libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f7dc6283000)
	libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f7dc606d000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f7dc5e46000)
	libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f7dc5be2000)
wkhtmltopdf: error while loading shared libraries: libjpeg.so.62: cannot open shared object file: No such file or directory
2020-05-08T10:18:33.445Z	c361ad4f-866a-1450-c1dc-6a3e0f8318fe	ERROR	Invoke Error 	{"errorType":"Error","errorMessage":"Command failed: wkhtmltopdf -V","status":127,"signal":null,"output":[null,null,null],"pid":31,"stdout":null,"stderr":null,"stack":["Error: Command failed: wkhtmltopdf -V","    at checkExecSyncError (child_process.js:630:11)","    at execSync (child_process.js:666:15)","    at Runtime.exports.handler (/var/task/index.js:21:3)","    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"]}

It appears to be finding most of the libraries, but a few are missing. Do you know what might be the issue?

Problem with fonts

I was trying nodejs12.x runtime, I didn't succeed.

wkhtmltopdf does not emit any error the pdf is generated.

But you don't see characters just squares.
I was investigating and it seems that the fonts are missing.

You can try the function here

echo "<html><body>Test</body></html>" | http --download POST https://kt7b9gdixh.execute-api.us-east-1.amazonaws.com/dev/converter

GLIBC_2.25 not found

Installed the eu-west-2 layer for a Larvel Vapor project for use with snappy, but getting this error:
message: "The exit status code '1' says something went wrong:↵stderr: "/opt/bin/wkhtmltopdf: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by /opt/lib/libuuid.so.1)↵"↵stdout: ""↵command: /opt/bin/wkhtmltopdf --lowquality --encoding 'utf-8' --footer-font-size '8' --footer-left 'Please acknowledge receipt of this claim immediately. If this is not confirmed within 30 days it will be treated as conceded.' --footer-right 'Page [page] of [topage]' '/tmp/knp_snappy5f5909c3905599.69498844.html' '/tmp/knp_snappy5f5909c3905ab8.36615393.pdf'."

I assume it's because Amazon Linux 2 doesn't include all the necessary packages by default, but the main page states these layers are compatible with AL2?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.