Create Lambda Layer in Dockerfile

0

Hi, just wondering, during docker build, if I install node packages in the folder /opt/nodejs and copy the folder node_modules/ plus files package.* to the final image like the following:

FROM public.ecr.aws/lambda/nodejs:16 as builder
WORKDIR /opt/nodejs
RUN npm install pkg1 pkg2 pkg3

FROM public.ecr.aws/lambda/nodejs:16
COPY --from=builder /opt/nodejs /opt/nodejs
COPY . ${LAMBDA_TASK_ROOT}

would this be a valid way to create a lambda layer? Thanks!

已提问 2 年前960 查看次数
2 回答
0
已接受的回答

Lambda container images does not support layers. Layers are only a way to add dependencies, so all you have to do is include those dependencies in your docker image. Layers use the /opt. When you use docker, you don't have to use /opt and you can deploy your dependencies in the regular location.

I don't think you need to use FROM twice. Just use the second, npm install, and copy the application files.

profile pictureAWS
专家
Uri
已回答 2 年前
profile picture
专家
已审核 1 个月前
0

I don't know in JS, but in Python what I would do is use the docker image provided by lambda to install my packages into a specific folder. Zip that, store it in S3, job done. So yes, I suppose a multi-stages build works as well. But again, I am not familiar with the specific inner workings of NPM to achieve that.

profile picture
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则