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!

gefragt vor 2 Jahren960 Aufrufe
2 Antworten
0
Akzeptierte Antwort

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
EXPERTE
Uri
beantwortet vor 2 Jahren
profile picture
EXPERTE
überprüft vor einem Monat
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
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen