The intent of this issue is to bring a community effort to get a documented way to get WeasyPrint working on an AWS Lambda environment.
There has been other issues and solutions related to this before but none were conclusive or adaptable
Key points :
Hopefully we can finally get this issue sorted, generating a PDF in AWS Lambda is a common scenario and it allow for a very cheap and fast hosting/deployment structure.
Also, once sorted out we can share with the community the ARN of a WeasyPrint Lambda Layer that anyone can use (sharing a lambda layer is free and incurs no additional charges)
I'll share what I have so far :
I'm trying to get a base idea using serverless-framework with serverless-python-requirements plugin, it automatically sets up a docker resembling aws lambda, then installs and packages all python packages from a requirements.txt
It also allows for extra packages to be included, for example I tried the following configuration setup, since installing just weasyprint makes it output cannot load library 'pango-1.0' :
Dockerfile
FROM lambci/lambda:build-python3.7
# Install your dependencies
RUN yum -y install pango
serverless.yml (just the plugin config part)
custom:
pythonRequirements:
dockerFile: Dockerfile
dockerizePip: true
layer: true
dockerExtraFiles:
- /usr/lib64/libpango-1.0.so.0
- /usr/lib64/libpango-1.0.so.0.2800.1
plugins:
- serverless-python-requirements
This in the end packages weasyprint along with libpango-1.0.so0 and libpango-1.0.so.0.2800.1 in the same folder.
Although this is a nice start, the same error still persists, I'm not sure where to go from here.
The intent of this issue is to bring a community effort to get a documented way to get WeasyPrint working on an AWS Lambda environment.
:heart:
This in the end packages weasyprint along with
libpango-1.0.so0andlibpango-1.0.so.0.2800.1in the same folder.
Reading #401 and talking to the people involved in this issue could be useful.
More info! It seems that when using layers, lambda looks for so libs in the /lib/ folder of the layer, so it won't work if it is in the same folder as weasyprint (is need to be in /python/ in a layer)
Docs for this here : https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path
I'll see if this is enough and hopefully try to drop the serverless-framework as requirement.
Also it only works with python3.6 lambda runtime, with python3.7 it doesn't find pango
I was able to deploy weasyprint using python3.6 runtime and layers. I used these two files here to achieve it: https://drive.google.com/drive/folders/1xEonJiIEGYuwdRPO4mayZbHAgQQq_epj?usp=sharing
I was able to deploy weasyprint using python3.6 runtime and layers. I used these two files here to achieve it
Thanks for sharing!
Could anybody write a short documentation about that? :heart:
Could anybody write a short documentation about that?
Oh, it's basically what's done in #952.
Thanks so much for this info, this is exactly what I needed. It would be helpful if @nelsonsar or someone who's generate these zipfiles would post the script or process used to re-generate them, so they can be iterated over?
@robbymeals I'm working on a repository to create the zip files using lambci. I'm struggling with time though, sorry for the delay 馃槄
I created a repository that creates the zip files for a lambda layer. (Used the same approach as @nelsonsar using lambci)
I created a repository that creates the zip files for a lambda layer. (Used the same approach as @nelsonsar using lambci)
I'm executing this command without error:
docker build -t weasyprint .
But I'm not getting the zip file in the weasyprint_lambda folder.
Please help
Most helpful comment
I created a repository that creates the zip files for a lambda layer. (Used the same approach as @nelsonsar using lambci)
https://github.com/seanfdnn/weasyprint_lambda/