HomeTutorsContact
AWS - Amazon Web Services
How to Create Lambda Container Images?
Anton Putra
February 24, 2021
1 min

  • First of all, we need to create a folder where we going to place all the files for the NodeJS app and Dockerfile. Let’s call it a hello-app.
  • Now, let’s initialize our NodeJS project and generate a package.json file. To do that, let’s change the directory to hello-app and run the following command:
  • Let’s create an app.js file and define our function.
  • We’re going to use the faker node nodule to generate random country, let’s install it using the npm package manager. Since it’s the first package that we will install, npm will generate package-lock.json file. Later on, in the Dockerfile we will use npm ci --only=production command, which will read the lock file, and install all the dependencies for the project.
  • We have two options to package our lambda function.
    • The first one is to create a zip archive with the source code and upload it to AWS.
    • The second is to build a docker image and push it to the ECR repository.

Let’s use the second option and build a docker image. We need to create a Dockerfile with the following content first:

Now, let’s build a docker image

  • We can list docker images by running the following command:
  • To create an AWS Lambda function from the docker image, we need to upload that image to the ECR repository. So, let’s create it.
  • To be able to push docker image you need to retrieve an authentication token and authenticate your Docker client to your registry. Use the AWS CLI:
  • After the build completes, tag your image so you can push the image to this repository:
  • Run the following command to push this image to your newly created AWS repository:
  • Finally, we can create a lambda function using the console. Let’s call it hello-app and select the docker image that we just uploaded.

  • To access the lambda function we can add API Gateway trigger.

  • Test it with curl


Tags

#AWS#NodeJS#Lambda

Anton Putra

DevOps Engineer

Big Data | DevOps engineer with hands-on experience in building large, scalable batch and real-time applications with Apache Spark, Hive, Flink on top of Kubernetes; designing and developing CI/CD pipelines.

Expertise

Kubernetes
Terraform
AWS
GCP

Social Media

youtubefacebooklinkedinwebsite

Related Posts

Test Lambda Container Images
How to Test Lambda Container Images?
February 28, 2021
1 min
© 2021, All Rights Reserved.

Quick Links

About UsContact Us

Social Media