That’s not really unique to Node. The majority of languages and web app platforms have concurrency mechanisms that will process multiple requests simultaneously. That is certainly a drawback of Lambda if you’re looking at raw CPU cycle efficiency and your application spends a lot of time waiting on synchronous downstream calls, but in most cases that doesn’t really matter. In practice, there are a lot of apps that can either use really fast data stores like Dynamo or use asynchronous processing models that minimize the amount of idle CPU time for a given request. Also, even with some inefficiencies when looking at high concurrency time periods, sometimes the ability for Lambda to immediately scale down during troughs in your load pattern makes up for it when looking at the global efficiency of the system (especially when you consider other operational overhead like patching servers.) Bottom line, people use Node with Lambda because they like the language and are familiar with it. Using the same language for the front end browser code and the backend is nice for teams that build full stack web apps. Answer from VegaWinnfield on reddit.com
🌐
Reddit
reddit.com › r/aws › why would i use node.js in lambda? node main feature is handling concurrent many requests. if each request to lambda will spawn a new node instance, whats the point?
r/aws on Reddit: Why would I use Node.js in Lambda? Node main feature is handling concurrent many requests. If each request to lambda will spawn a new Node instance, whats the point?
February 8, 2020 -

Maybe I'm missing something here, from an architectural point of view, I can't wrap my head on using node inside a lambda. Let's say I receive 3 requests, a single node instance would be able to handle this with ease, but if I use lambda, 3 lambdas with Node inside would be spawned, each would be idle while waiting for the callback.

Edit: Many very good answers. I will for sure discuss this with the team next week. Very happy with this community. Thanks and please keep them coming!

Top answer
1 of 27
29
That’s not really unique to Node. The majority of languages and web app platforms have concurrency mechanisms that will process multiple requests simultaneously. That is certainly a drawback of Lambda if you’re looking at raw CPU cycle efficiency and your application spends a lot of time waiting on synchronous downstream calls, but in most cases that doesn’t really matter. In practice, there are a lot of apps that can either use really fast data stores like Dynamo or use asynchronous processing models that minimize the amount of idle CPU time for a given request. Also, even with some inefficiencies when looking at high concurrency time periods, sometimes the ability for Lambda to immediately scale down during troughs in your load pattern makes up for it when looking at the global efficiency of the system (especially when you consider other operational overhead like patching servers.) Bottom line, people use Node with Lambda because they like the language and are familiar with it. Using the same language for the front end browser code and the backend is nice for teams that build full stack web apps.
2 of 27
12
> if I use lambda, 3 lambdas with Node inside would be spawned, each would be idle while waiting for the callback This is true of any other language, though. You could have three instances of a program written in Assembly waiting for data to return. > I can't wrap my head on using node inside a lambda The reasons to adopt Node over other platforms are varied, and not necessarily technical arguments. Node has fast startup times compared with .Net or Java. AWS themselves recommend Node in use-cases where cold-start latency matters; eg. web handlers. Most business applications are IO-bound. It doesn't matter which language you pick if you're sat waiting for data to return over the network. Javascript is easy to hire for - it's a lingua franca that most engineers have some skill with Modern front-end frameworks often support server-side rendering, which makes a single language attractive across the entire stack. As a result of the above, JS is the default option for Lambda, which means the best tooling and libraries are written for JS, compounding the advantages and mind-share. Architecture isn't really about making the best technical choice, it's about making the right _business_ decision in a technical context so that your choices support one another.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js
Building Lambda functions with Node.js - AWS Lambda
It relays any logs that your function outputs during invocation. If your function returns an error, Lambda formats the error and returns it to the invoker. ... All supported Lambda Node.js runtimes include a specific minor version of the AWS SDK for JavaScript v3, not the latest version
Discussions

Can and should I use express.js in lambda?
Hello guys, I'm currently planning a new project that will use lambda functions and Node.js as its runtime environment. I have previously developed multiple lambdas using Node.js as my runtime bu... More on repost.aws
🌐 repost.aws
1
0
June 3, 2024
AWS Lambda: Python vs Nodejs
Having done quite a bit of lambda development over the last several years, it really does come down to the personal preference of you and/or your team. Pick the language you feel most comfortable with, that you want to support as a team going forward for X number of years. Both Python and Nodejs are quite popular languages for lambda development. More on reddit.com
🌐 r/aws
15
16
February 19, 2021
Are there any performance/functionality differences for AWS Lambda functions written in node.js/Java - Stack Overflow
I am planning to use AWS Lambda for the backend of an app. I am more comfortable with Java compared to node.js but I see Lambda functions in node.js are more popular than Java. Are there any perfor... More on stackoverflow.com
🌐 stackoverflow.com
Go Lambda vs Node.js Lambda vs Python Lambda
Generally Lambda is so cheap to run (even at scale) that you wouldn’t really care about the margin speed difference until you had so many customers that an entire team could be assigned to optimize and refactor. Speed of initial delivery is more important here - move fast w the language you’re most proficient in! That said, if you still believe it’s really important now, there have been a ton of comparisons already that should be easy to find w your favorite search engine. Finally, if it really really really matters to you, what are your findings for a prototype? There are a lot of dependencies based on what your code will do that can’t be predicted as easily as “what is fastest”. More on reddit.com
🌐 r/serverless
8
2
August 27, 2022
🌐
Brainly
brainly.com › computers and technology › high school › for which of the following reasons is node.js preferred for lambda functions? a. event-driven b. single-threaded c. simple d. no buffering
[FREE] For which of the following reasons is Node.js preferred for lambda functions? A. Event-driven B. - brainly.com
Node.js is preferred for lambda functions for several reasons. Firstly, it is an event-driven platform which means that it can handle multiple requests simultaneously without causing any delays or blocking the thread.
🌐
Quora
quora.com › Why-is-Node-js-preferred-over-net-to-make-Lambda-serverless-computing-functionality-in-Amazon-AWS-services
Why is Node.js preferred over .net to make Lambda serverless computing functionality in Amazon AWS services? - Quora
Answer (1 of 3): What do you mean by “preferred”? .net is a supported runtime in AWS Lambda. There’s no indication that Amazon pushes the node.js runtime over the .net runtime. In terms of community support… it’s not a serverless problem. It’s a .net problem: (trend).
🌐
Better Dev .blog
betterdev.blog › aws-lambda-runtime-nodejs-python
AWS Lambda - Node.js vs. Python for serverless | Better Dev
March 15, 2023 - TL;DR Node.js wins over Python, producing smaller Lambda functions that are faster to build and deploy and providing better monorepo support.
🌐
Quora
quora.com › Whats-the-advantage-of-running-Node-js-with-AWS-Lambda-instead-of-more-traditional-services
What's the advantage of running Node.js with AWS Lambda instead of more traditional services? - Quora
Answer (1 of 3): AWS Lambda is a service in the category Functions-as-a-Service (FaaS), a type of serverless execution environment. With FaaS, you get all the benefits of Platform-as-a-Service (PaaS): * Virtual servers * No OS administration * No runtime administration Basically, you publish...
🌐
Quora
quora.com › What-are-the-differences-between-writing-Node-js-code-for-AWS-Lambda-and-in-standalone-apps
What are the differences between writing Node.js code for AWS Lambda and in standalone apps? - Quora
Answer (1 of 3): The biggest difference, I would argue, is that Lambda functions are best kept focused on a single task, whereas in a standalone app, your codebase is likely to be multipurpose and much larger.
Find elsewhere
🌐
Medium
medium.com › intrinsic-blog › basic-node-js-lambda-function-concepts-c0d1e00d4528
Basic Node.js Lambda Function Concepts | by Thomas Hunter II | intrinsic | Medium
May 29, 2018 - In this second part of our series we’re going to go over a bunch of basic concepts, such as how Node.js itself normally runs, how Node.js runs inside of Lambda, and finally we’ll look at the different methods for invoking Lambda functions and the pros and cons of each.
🌐
Hevo
hevodata.com › home › learn › data strategy
NodeJS Lambda | The Complete Guide to Get Started 101
January 12, 2026 - Lambda functions are useful because they allow you to run code without provisioning or managing servers, automatically scaling to handle varying loads, and only charging for the compute time used, making them cost-effective for event-driven ...
🌐
RisingStack
blog.risingstack.com › home › hírek, események › getting started with aws lambda & node.js
Getting Started with AWS Lambda & Node.js - RisingStack Engineering
May 29, 2024 - Node.js is free of locks, so there's no chance to dead-lock any process. Developer. Since the launch of AWS Lambda back in 2014, serverless (or FaaS – Function as a Service) computing became more and more popular.
🌐
Businesscompassllc
businesscompassllc.com › home
Seamlessly Upgrading AWS Lambda Functions to Node.js 18 or 20: A Step-by-Step Guide - Business Compass LLC®
August 30, 2024 - Upgrading your Lambda functions to Node.js 18 or 20 offers multiple benefits, including enhanced security, improved performance, and access to the latest JavaScript features. Node.js 18 introduces long-term support (LTS) with better security ...
🌐
w3tutorials
w3tutorials.net › blog › aws-lamda-nodejs
AWS Lambda with Node.js: A Comprehensive Guide — w3tutorials.net
Asynchronous Programming: Node.js ... for serverless functions. It can handle multiple requests concurrently without blocking the event loop, improving the performance of your Lambda functions....
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js › define lambda function handler in node.js
Define Lambda function handler in Node.js - AWS Lambda
After a successful invocation, ... (ES modules). Lambda recommends using ES modules as it supports top-level await, which enables asynchronous tasks to be completed during execution environment initialization....
🌐
Lumigo
lumigo.io › guides › aws lambda 101 › aws lambda nodejs: building functions
AWS Lambda NodeJS: Building Functions - Lumigo
November 30, 2022 - Keying off the popularity of NodeJS, AWS wisely launched AWS Lambda functions with a runtime powered by NodeJS, allowing developers to easily make the transition from server-side coding in NodeJS to serverless development in AWS Lambda.
Top answer
1 of 3
30

The answer to your question depends upon your current and future needs. I think you should always plan ahead and make sure that the current infrastructure that you will implement can be upgradable for future needs.

You should ask yourself those questions:

  • In the future do I want to have some websocket connection?
  • Do I need any proxy in my request routing?
  • How big will become my application over time?
  • Which AWS Service will I expect to use in the future

Scalability

Using Express.js in a lambda is not a good idea for many reasons:

  1. You will pay more for the execution of your Lambda because it will take more time to run and maybe more memory
  2. Latency is higher
  3. Doing a small modification means redeploying all your application code on 1 lambda so only 1 point of failure.
  4. Normally overtime your application's code base will grow as you add more features. The maintenance of that monolithic repo will be a pain in the ass and you will deploy less than you want because of the bugs you might encounter.

Cost effectiveness

Express.js on Lambda is more expensive because you need to proxy any method into your lambda using a API Gateway REST API rather then using API Gateway HTTP API

HTTP APIs are up to 71% cheaper compared to REST APIs

Latency

Lambda isn't magically executing your code without server even tho they market it like it is. When an event occur, AWS will launch a docker container, wait for it to fully load all your dependencies and then run your handler.

With a normal Node.js server on AWS EC2 or AWS ECS it's a one time cost because your server is always running and all your dependencies are already loaded but not on your lambda.

As AWS says:

This approach [Express.js and proxy all requests to your lambda] is generally unnecessary, and it’s often better to take advantage of the native routing functionality available in API Gateway. In many cases, there is no need for the web framework in the Lambda function, which increases the size of the deployment package. API Gateway is also capable of validating parameters, reducing the need for checking parameters with custom code. It can also provide protection against unauthorized access, and a range of other features more suited to be handled at the service level.

Best practices for organizing larger serverless applications

How to convert Express framework into plan Lambda

To simplify your life, I would suggest you to use SAM CLI. It's very simple to get started with it.

Install SAM CLI

If you're following the MVC pattern for your Express app. You only need to take your service files where your core logic live.

The folder structure I like to use for the lambda is the following

Suppose it's a small calendar app

──src-ts
    ├───handlers
    │       getEvent.ts
    │
    ├───tests
    │   │   getEvent.tests.ts
    │   │
    │   └───utils
    │           utils.ts
    │
    └───utils
            utils.ts
            validation.ts

It's important that your handler returns 3 thing

  1. Headers (JSON)
  2. statusCode (number)
  3. Body (stringified)

You also need a template.yml file to describe the infrastructure that your lambda need

AWSTemplateFormatVersion: 2010-09-09
Description: Describe the lambda goal

Transform:
    - AWS::Serverless-2016-10-31


Resources:
    # API Gateway
    LambdaAPI:
        Type: AWS::Serverless::Api
        Properties:
            StageName: StageName
            Cors:
                AllowMethods: "'POST, GET, OPTIONS'"
                AllowHeaders: "'*'"
                AllowOrigin: "'*'"


    # IAM Role
    LambdaRole:
        Type: AWS::IAM::Role
        Properties:
            AssumeRolePolicyDocument:
                Version: 2012-10-17
                Statement:
                    - Action:
                          - 'sts:AssumeRole'
                      Effect: Allow
                      Principal:
                          Service:
                              - lambda.amazonaws.com
            ManagedPolicyArns:
                - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
                - arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess
                - arn:aws:iam::aws:policy/AmazonAPIGatewayInvokeFullAccess

    GetEvent:
        Type: AWS::Serverless::Function
        Properties:
            Runtime: nodejs12.x
            Timeout: 180
            FunctionName: youLambdaName
            Handler: src/handlers/getEvent.handler
            Role: !GetAtt LambdaRole.Arn
            Events:
                Get:
                    Type: Api
                    Properties:
                        RestApiId: !Ref LambdaAPI
                        Path: /events/{eventid}
                        Method: GET

Note I used typescript and but when compiled it's creating an src folder

Some resource to help you more in depth:

  • https://aws.amazon.com/blogs/compute/going-serverless-migrating-an-express-application-to-amazon-api-gateway-and-aws-lambda/
  • https://dev.to/brightdevs/how-to-convert-an-express-app-to-aws-lambda--44gc
  • https://medium.com/hackernoon/how-to-deploy-a-node-js-application-to-aws-lambda-using-serverless-ae7e7ebe0996
  • https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html

To Conclude

The upside of using lambdas without Express are:

  • better scalability
  • cost optimization
  • lower latency
  • higher availability because you have multiple lambda for each business logic instead of one that run it all

The downside of using lambdas without Express are:

  • You need to modify your existing code
  • Init time of your lambda needs to be part of your thinking when developing your logic
  • You need to learn SAM yaml template and read the AWS doc when you wanna add more functionality to your API infrastructure.

Take advantage of the AWS infrastructure, don't try to go against it. All AWS Services are working together in a seamless and low latency way. You should remove Express from your infrastructure if you wanna go "Serverless".

2 of 3
3

If it's a bit hefty to be function as you said, you may think in creating a docker image for your app and run it using Fargate ECS which is considered a serverless option.