-
Notifications
You must be signed in to change notification settings - Fork 133
AWS Lambda layer zip #77
AWS Lambda layer zip #77
Conversation
I've tested the generated zip file as a layer for AWS Lambda. It works as expected, generates valid pdf files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the PR, @deniszatsepin! Just some minor changes required. Also, can you also add this to .azure-pipelines.yml
as well?
@ashkulz thanks for the review. Could you please explain, how the azure pipeline is executed (by whom?) and where to find the results of the pipeline? |
@deniszatsepin the Azure Pipelines is run manually by me. You can see the results here. |
How long does it take to package for the amazon lambda layer? |
@annshress it generally takes 40 minutes, but I'll have to make a special release for that. I'll be first checking it locally. |
Locally, I have a resulting zip archive in about 3 minutes. |
@deniszatsepin is that just the |
I am currently packaging this. And its taking 30 minutes approx and still going. E: Yep around 40 minutes. |
@deniszatsepin Any idea? Currently in the wkhtmltox layer, we have $ ls /opt/wkhtmltox/lib/
libbz2.so.1
libexpat.so.1
libfontconfig.so.1
libfreetype.so.6
libjpeg.so.62
libpng15.so.15
libuuid.so.1
libX11.so.6
libXau.so.6
libxcb.so.1
libXext.so.6
libXrender.so.1 |
@ashkulz @annshress Sorry for my misleading estimation. The whole process for amazonlinux2_lambda target takes 13 mins on my laptop. The packaging itself is about 20 secs. |
Do you run it in AWS Lambda environment or locally? |
I invoked it. Somehow the binary isnt discovering the |
.so dependencies
|
@annshress It will also work if you put it in the root of a Lambda function, so paths will look like that: |
@deniszatsepin Thank you for making packaging easier. |
So it was generated locally:
@annshress can you confirm if it works for you? |
@deniszatsepin is there a need to change the paths? I'd prefer if we did that automatically rather than having to document it. |
@ashkulz Yes, let me change the archiving part, so |
@ashkulz Yes it does. I yet need to check the output file though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with AWS Lambda, shouldn't it be in /var/task
or is the root folder more correct from a layer perspective? Maybe we can do a mv
in the script...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Starting a final build just to verify 👍
@deniszatsepin / @annshress: can you confirm it works for you properly? I tried to reproduce this in docker and it generated the file, but with a fontconfig error: $ docker run --rm -it -v$PWD/lambda:/lambda amazonlinux:2
bash-4.2# LD_LIBRARY_PATH=/lambda/lib /lambda/bin/wkhtmltopdf https://google.com/ /lambda/google.pdf
Fontconfig error: Cannot load default config file
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done Also, the output google.pdf didn't have any fonts in it 🤷♂️ |
@ashkulz try to use this command: $ docker run --rm -it -v$PWD/lambda:/opt amazonlinux:2
bash-4.2# LD_LIBRARY_PATH=/opt/lib FONTCONFIG_PATH=/opt/fonts /opt/bin/wkhtmltopdf https://google.com/ /opt/google.pdf
|
That's much better, thanks!
gives me google.pdf which still has some missing fonts. I guess that's because the Indic text requires additional fonts? May need to add that in the FAQ. |
Thanks for the contribution, @deniszatsepin! I'll start a build and update the downloads page by tomorrow. |
Many thanks for the collaboration guys! Ping me if something needs to be improved in lambda build. |
Hey @ashkulz, how is it going with the new release and downloads page update? May I probably help somehow? |
@deniszatsepin I'll do that today, didn't have access to the laptop which has the gpg keys and later on forgot about it 🙈 |
Yeah, it happens. I'm looking forward to starting using the new image in my companies project and plan to write an article about pdf generation with lambda and wkhtmltopdf. So, it would be awesome if it will be released. |
@deniszatsepin I've made the release in this repository. Would appreciate a PR for the downloads page, as I think the FAQ needs to be changed as well ... |
@ashkulz awesome news! Thank you! |
It's in the wkhtmltopdf repository, docs/downloads.md. |
@deniszatsepin if you don't have time, I'll just add the AWS Lambda zip to the downloads page, not sure what to do about the FAQ though. |
@ashkulz, sorry. I have time for that today. I'll do it. |
In accordance with a long discussion in wkhtmltopdf/wkhtmltopdf#4523 @ashkulz suggested automizing wkhtmltopdf image generation suitable for using in AWS Lambda environment.
Here I've introduced a new property for docker based build configuration, called
postcompile
, where it's possible to specify the shell script which will be executed inside the container at the end of the compilation process.It's also possible to specify
zip
as an output format, which is suitable for the AWS Lambda layers.In the end, the zip file will be generated. To be able to use it in the AWS Lambda environment, one should unpack it in an appropriate directory or directly use zip file as a lambda layer.
It's not tested on AWS Lambda yet. I'm going to do it tomorrow.
Comments, suggestions are warmly welcomed!