Daniel Kaplan
Daniel Kaplan

Reputation: 67440

How do I install fontconfig on AWS lambda?

This is a continuation of How do you install phantomjs on AWS lambda? I've figured out how to get phantomjs running on an aws lambda, but when I use it to generate pdfs (using the html-pdf nodejs library), the content is missing text. If I create a docker container that's using FROM node:10.16.0-jessie on it, the pdfs render fine. If I create a docker container using FROM amazonlinux:2.0.20190508 (which I think is similar to the AWS lambda container), the text is missing on my PDFs.

I've fixed this problem in amazonlinux:2.0.20190508 by running yum install fontconfig. But, I don't know how to do the equivalent of a yum install fontconfig inside a real lambda. If you look at the link above, you'll see that an answer there attempts to provide that information, but for whatever reason, it still doesn't work correctly. I believe the reason is there's still a missing step on how to get the fontconfig install properly extracted from the amazonlinux:2.0.20190508 container.

In summary, here is my question: After I run yum install fontconfig in amazonlinux:2.0.20190508, how do I extract it from the container and package it up so that an AWS Lambda can use it?

By the way, I'm sure there are other answers that seem to be answering this question, but the AWS lambda built-in dependencies change so frequently, none of those answers work anymore.

Upvotes: 2

Views: 3692

Answers (1)

Dmitriy Konovalov
Dmitriy Konovalov

Reputation: 21

In my case, I did this:

  1. Create a Docker file with content:
    FROM amazonlinux:2.0.20190508
    RUN yum -y install fontconfig freetype

and build it as example:latest

  1. Run docker and mount folder:
docker run -v D:\dockerFiles:/mnt --rm -it example:latest
  1. Found libraries inside docker by path /lib64

libbz2.so.1 libexpat.so.1 libfontconfig.so.1 libfreetype.so.6 libpng15.so.15

  1. Copy it to /mnt/lib. Take lib from D:\dockerFiles and zip folder lib.
  2. Create aws lambda layer and add to lambda.

Upvotes: 2

Related Questions