简体   繁体   English

如何在基础 AWS Lambda Node.js Dockerfile 图像中安装依赖项

[英]How to install dependencies in base AWS Lambda Node.js Dockerfile image

I am writing an AWS Lambda function using Node.js which is deployed via a container image.我正在使用通过容器映像部署的 Node.js 编写 AWS Lambda function。

I have used the base Node.js Dockerfile image for Lambda provided at the link below to configure my image.我已经使用下面链接提供的 Node.js Dockerfile 图像来配置我的图像。 This works well.这很好用。 My image is deployed and my Lambda function is running.我的映像已部署,我的 Lambda function 正在运行。

https://docs.aws.amazon.com/lambda/latest/dg/images-create.html#images-create-from-base https://docs.aws.amazon.com/lambda/latest/dg/images-create.html#images-create-from-base

Here is the Dockerfile:这是 Dockerfile:

FROM public.ecr.aws/lambda/nodejs:14

COPY index.js package.json cad/  ${LAMBDA_TASK_ROOT}

# Here I would like to install libgl1-mesa-dev, libx11-dev and libglu1-mesa-de

RUN npm install

CMD ["index.handler"]

However, I now need to install additional dependencies on the image.但是,我现在需要在图像上安装额外的依赖项。 Specifically I need OpenGL to use PDFTron to convert CAD files to PDF, according to the PDFTron documentation here .具体来说,根据此处的 PDFTron 文档,我需要 OpenGL 才能使用 PDFTron 将 CAD 文件转换为 PDF。 So I require libgl1-mesa-dev , libx11-dev and libglu1-mesa-de .所以我需要libgl1-mesa-devlibx11-devlibglu1-mesa-de

The information on the AWS documentation above states:上述 AWS 文档中的信息指出:

Install any dependencies under the ${LAMBDA_TASK_ROOT} directory alongside the function handler to ensure that the Lambda runtime can locate them when the function is invoked.在 ${LAMBDA_TASK_ROOT} 目录下与 function 处理程序一起安装任何依赖项,以确保 Lambda 运行时可以在调用 function 时找到它们。

If this was an ubuntu or alpine image I could install using apt-get or apk add .如果这是 ubuntu 或 alpine 图像,我可以使用apt-getapk add安装。 But neither is available on this base AWS Lambda Node image since this isn't an ubuntu or alpine image.但是在这个基础 AWS Lambda 节点图像上都不可用,因为这不是 ubuntu 或高山图像。

So my question is, how do I install libgl1-mesa-dev , libx11-dev and libglu1-mesa-de on this image so that the Lambda runtime can locate them when the function is invoked?所以我的问题是,如何在此图像上安装libgl1-mesa-devlibx11-devlibglu1-mesa-de ,以便 Lambda 运行时可以在调用 function 时找到它们?

I think the equivalent for ubuntu, on Amazon Linux 2 (lambda is using it) would be:我认为 ubuntu 在 Amazon Linux 2 上的等效项(lambda 正在使用它)将是:

FROM public.ecr.aws/lambda/nodejs:14

COPY index.js package.json cad/  ${LAMBDA_TASK_ROOT}

RUN yum install -y libgl1-mesa-devel libx11-devel  mesa-libGL-devel

RUN npm install

CMD ["index.handler"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM