A tedious because Lambda's Python 3.8 runtime does not include all of the typical build tools to generate Weasyprint's dependencies.
Also included here are steps to generate fonts, because Lambda doesn't have any and while it is interesting to look at a fully formatted document where all of the characters are .notdef glyphs, it's more productive to be able to read your pretty new PDF file.
The files in this gist are "flat" because gist does not allow us to show directories, so note the following dir structure:
serverless.yml
layers/
fonts/
setup.sh
README.md
weasyprint_deps/
setup.sh
Dockerfile
README.md
While it is not generally good practice to track binary files in git, I'm doing it anyway because they're small and stable. You will rarely if ever want to regenerate them and you'll save a lot of time to just track them and let them run through your CICD pipeline. Use LFS.
The following will create your zipball files:
cd layers/fonts/ && ./setup.sh \
cd ../weasyprint_deps/ && ./setup.sh
The zipballs are referenced directly in your serverless.yml
to be used as layers on your Lambda function.
weasyprint needs to be v52.5 and below due to
https://stackoverflow.com/questions/68720486/how-to-fix-function-symbol-pango-context-set-round-glyph-positions-error