Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 6, 2022 12:41 am GMT

Run a node app into AWS lambda

I create this post because I didn't found any information on this when I need it, or the information was disperse around the web, so I hope this post help someone. This is going to be straight and I'm assuming that you already have a private repository in AWS.

Steps

  • Create your code and ensure that a handler exist.
  • Setup & upload your Dockerfile with the right params.
  • Configuring AWS.
  • Close the rest of your browser tabs.

If you are reading this before you write any code make sure to check the repository of AWS and confirm the node version (Some of the node versions are not verify, you can find the supported versions here).

Once you have your nodeJS code you need to make sure that inside your main file exist a handler function this is a requisite for lambda functions no matter the programming language.

export.handler = async (even) => { ... some awesome logic}

After you have all your logic we are going to create a container with docker. Your Dockerfile should be similar to this:

FROM public.ecr.aws/bitnami/node:14.20.0COPY . .RUN npm install --omit=devENV MODE="production"CMD node -e 'require("./index").handler()' MODE=${MODE}

In this case we're using node:14.20 as image (notice the repository), we install all the packages ignoring devs and in the CMD we call the function handler.

Then build the container.
docker build <name>:<tag> .

Push the files to your AWS private repository.

Lambda is going to run this every time that is being invoke. Now you need to create a repository inside AWS

After you push your files go into lambda and select create a lambda container function, once there just pick the container from you repository, set the right permissions. Once finish the process try to invoke the test, you can set an API Gateway layer so your function can be call from an endpoint.

Some other helpful resources:


Original Link: https://dev.to/dashpy/run-a-node-app-into-aws-lambda-1g07

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To