I am trying to build a container image for a Node.js Lambda function. My base image is like this:
FROM public.ecr.aws/lambda/nodejs:20
COPY index.js ${LAMBDA_TASK_ROOT}
CMD [ "index.handler" ]
However, my Node.js function also uses pdf2htmlEX package. One way to install it is with apt-get. Running apt-get in the above dockerfile will return an error "command not found". Understandable, because apt-get is not available in the Node.js image from AWS.
Maybe that's not be the way to do it. Ultimately, how do I get a Node.js Lambda function to execute a Linux package (pdf2htmlEX in this case)?
Update 1: After testing out various options and combinations, I created an alternative base image in order to install pdf2htmlEX, node.js and npm :
ARG FUNCTION_DIR="/function"
FROM ubuntu:18.04
ARG FUNCTION_DIR
ENV NODE_VERSION=16.13.0
RUN apt-get update
COPY ./pdf2htmlEX.deb /tmp
# Install pdf2htmlEX and node.js and related packages
RUN apt-get install -y /tmp/pdf2htmlEX.deb curl cmake autoconf libtool
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN mkdir -p ${FUNCTION_DIR}
COPY index.js package.json ${FUNCTION_DIR}
WORKDIR ${FUNCTION_DIR}
RUN npm install aws-lambda-ric
CMD [ "index.handler" ]
The build failed when installing aws-lambda-ric, the runtime interface client required when using an alternative base image. The error log is too long to post here, so maybe it's not the right config.
Update 2: Another attempt using node-20:buster:
ARG FUNCTION_DIR="/function"
FROM node:20-buster as build-image
# Include global arg in this stage of the build
ARG FUNCTION_DIR
COPY ./pdf2htmlEX.deb /tmp
# Install build dependencies
RUN apt-get update && \
apt-get install -y \
/tmp/pdf2htmlEX.deb
Got another type of error:
The following packages have unmet dependencies:
pdf2htmlex : Depends: libjpeg-turbo8 but it is not installable
Unable to correct problems, you have held broken packages.



