Open Newbie012 opened 3 years ago
As of early 2022, AWS Lambda can now run custom containers which means no more messing with layers!
Here's our working Dockerfile
that is deployed in Lambda to help us fill PDFs. The build image is lifted from the aws-lambda-irc upgraded to node-14:
FROM node:14-buster-slim as build-image
# Include global arg in this stage of the build
ARG FUNCTION_DIR=/app
# Install aws-lambda-cpp build dependencies
RUN apt-get update && \
apt-get install -y \
g++ \
make \
cmake \
unzip \
libcurl4-openssl-dev \
tar \
gzip \
autoconf \
automake \
libtool \
libkrb5-dev \
python3 \
yarn \
pkg-config \
libpoppler-qt5-dev \
libcairo2-dev
# Copy function code
RUN mkdir -p ${FUNCTION_DIR}
COPY . ${FUNCTION_DIR}
WORKDIR ${FUNCTION_DIR}
# If the dependency is not in package.json uncomment the following line
RUN npm install aws-lambda-ric
RUN yarn
# Grab a fresh slim copy of the image to reduce the final size
FROM node:14-buster-slim
# Include global arg in this stage of the build
ARG FUNCTION_DIR=/app
# Need some native functions so node modules work
RUN apt-get update && \
apt-get install -y \
pkg-config \
libpoppler-qt5-dev \
libcairo2-dev
# Set working directory to function root directory
WORKDIR ${FUNCTION_DIR}
# Copy in the built dependencies
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
# ENTRYPOINT ["/usr/local/bin/npx", "aws-lambda-ric"]
# CMD ["app.handler"]
I tried to deploy a lambda function that uses this package. I was aware that I needed to install
libcairo2-dev libpoppler-qt5-dev
, but AFAIK, it's impossible to do so in AWS Lambda (correct me if I'm wrong). So of course, when I tested the function, I got the following error:which comes from: https://github.com/tpisto/pdf-fill-form/blob/a3996cdce2508060b221fcd60e9a1ee51d47d162/lib/pdf-fill-form.js#L70
I created a new layer with
lib/libQt5Gui.so.5
inside, and then I got an error thatlibQt5Core.so.5
is missing and so on.I eventually created this docker file:
But every time I got a different missing shared file. The layer has eventually grown up to 70MB and that's pretty much where I gave up (Yes, I manually deployed the layer 38 times. Yes, I know it's sad).
I know that this issue might be out of the scope of this package, but this issue might help other people (hopefully) that are trying to use this package in AWS Lambda.