The context parameter can be omitted. But if you need it, it has to be the second parameter.

So both of these are fine:

exports.handler = async (event, context) => {};

and without context:

exports.handler = async (event) => {};

You can read more about NodeJS handlers and context in the official AWS documentation:

  1. AWS Lambda function handler in Node.js
  2. AWS Lambda context object in Node.js
Answer from Jens on Stack Overflow
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js › using the lambda context object to retrieve node.js function information
Using the Lambda context object to retrieve Node.js function information - AWS Lambda
When Lambda runs your function, it passes a context object to the handler . This object provides methods and properties that provide information about the invocation, function, and execution environment.
🌐
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
The handler accepts the following arguments: event: Contains the input data passed to your function. context: Contains information about the invocation, function, and execution environment. For more information, see Using the Lambda context object to retrieve Node.js function information.
Discussions

Where is the context parameter in the current Node.js AWS Lambda function template? - Stack Overflow
I was looking at a tutorial on writing a Lambda function in AWS using Node.js version 8. The template code shown in the tutorial when a new function is created looks like exports.handler = async (e... More on stackoverflow.com
🌐 stackoverflow.com
javascript - What are event and context in function call in AWS Lambda? - Stack Overflow
When Lambda runs your function, it passes a context object to the handler. This object provides methods and properties that provide information about the invocation, function, and execution environment. Event (and the args) are described here. To put it more simply, think of event as an input to a regular function. Context is an extra input supplied by AWS ... More on stackoverflow.com
🌐 stackoverflow.com
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?
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. More on reddit.com
🌐 r/aws
82
56
February 8, 2020
node.js - Access to aws-lambda context when running nodejs + expressjs - Stack Overflow
I'm, just starting out with AWS-Lambda, AWS-API Gateway and ExpressJs. I'm having trouble finding how the AWS-Lambda "context" is available in my "ExpressJs" application. I'm using: AWS-Lambda AWS... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with typescript › using the lambda context object to retrieve typescript function information
Using the Lambda context object to retrieve TypeScript function information - AWS Lambda
For more information, see Type definitions for Lambda. import { Context } from 'aws-lambda'; export const lambdaHandler = async (event: string, context: Context): Promise<string> => { console.log('Remaining time: ', context.getRemainingTimeInMillis()); console.log('Function name: ', context.functionName); return context.logStreamName; };
Top answer
1 of 3
30

Event represents the event or trigger that caused the invocation of the lambda. For example, if your lambda is triggered by an upload to S3 this will contain information about the object being uploaded for example:

    {
      "Records": [
        {
          "eventVersion": "2.0",
          "eventTime": "1970-01-01T00:00:00.000Z",
          "requestParameters": {
            "sourceIPAddress": "127.0.0.1"
          },
          "s3": {
            "configurationId": "testConfigRule",
            "object": {
              "eTag": "0123456789abcdef0123456789abcdef",
              "sequencer": "0A1B2C3D4E5F678901",
              "key": "HappyFace.jpg",
              "size": 1024
            },
            "bucket": {
              "arn": bucketarn,
              "name": "sourcebucket",
              "ownerIdentity": {
                "principalId": "EXAMPLE"
              }
            },
            "s3SchemaVersion": "1.0"
          },
          "responseElements": {
            "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH",
            "x-amz-request-id": "EXAMPLE123456789"
          },
          "awsRegion": "us-east-1",
          "eventName": "ObjectCreated:Put",
          "userIdentity": {
            "principalId": "EXAMPLE"
          },
          "eventSource": "aws:s3"
        }
      ]
    }

Here is detailed information about events, with an example.

Context Provides information about the invocation, function, and execution environment of your lambda. So you can use this to check the memory allocation or to retrieve the number of milliseconds left before the execution times out. Here is detailed documentation about context, with an example.

2 of 3
3

From the docs

When Lambda runs your function, it passes a context object to the handler. This object provides methods and properties that provide information about the invocation, function, and execution environment.

Event (and the args) are described here.

To put it more simply, think of event as an input to a regular function. Context is an extra input supplied by AWS to give you a variety of meta context and such.

🌐
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
You can run JavaScript code with Node.js in AWS Lambda. Lambda provides runtimes for Node.js that run your code to process events. Your code runs in an environment that includes the AWS SDK for JavaScript, with credentials from an AWS Identity and Access Management (IAM) role that you manage.
🌐
AWS
docs.aws.amazon.com › aws sdk for javascript › developer guide for sdk version 3 › sdk for javascript (v3) code examples › lambda examples using sdk for javascript (v3)
Lambda examples using SDK for JavaScript (v3) - AWS SDK for JavaScript
Consuming a Kinesis event with Lambda using JavaScript. // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 exports.handler = async (event, context) => { for (const record of event.Records) { try { console.log(`Processed Kinesis Event - EventID: ${record.eventID}`); const recordData = await getRecordDataAsync(record.kinesis); console.log(`Record Data: ${recordData}`); // TODO: Do interesting work based on the new data } catch (err) { console.error(`An error occurred ${err}`); throw err; } } console.log(`Successfully processed ${event.Records.length} records.`); }; async function getRecordDataAsync(payload) { var data = Buffer.from(payload.data, "base64").toString("utf-8"); await Promise.resolve(1); //Placeholder for actual async work return data; }
Find elsewhere
🌐
Sentry
docs.sentry.io › platforms › javascript › guides › aws-lambda › enriching-events › context
Context | Sentry for AWS Lambda
Context is a way to add additional metadata to events. While you cannot filter by contexts in the Sentry UI, context information is displayed in the event details.
🌐
AWS
aws.amazon.com › blogs › compute › getting-nodejs-and-lambda-to-play-nicely
Everything Depends on Context or, The Fine Art of nodejs Coding in AWS Lambda | Amazon Web Services
May 23, 2022 - Tim Wagner, AWS Lambda General Manager Quick, what’s wrong with the Lambda code sketch below? exports.handler = function(event, context) { anyAsyncCall(args, function(err, result) { if (err) console.log('problem'); else /* do something with result */; }); context.succeed(); }; If you said the placement of context.succeed, you’re correct – it belongs inside the callback.
🌐
GeeksforGeeks
geeksforgeeks.org › devops › aws-lambda-function-handler-in-nodejs
AWS Lambda Function Handler in Node.js - GeeksforGeeks
July 23, 2025 - Context: This parameter contains information about the invocation, function, and execution environment. It includes methods and properties to give details regarding the remaining execution time of the function, AWS request ID, log group, and stream.
🌐
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.
🌐
Reddit
reddit.com › r/aws › what fields/properties do 'event' and 'context' have in a python lambda invoked by api gateway?
r/aws on Reddit: What fields/properties do 'event' and 'context' have in a Python Lambda invoked by API Gateway?
September 23, 2022 -

I am writing a Python Lambda that will be invoked via HTTP. A web service will make an HTTP call to an API Gateway resource that I define, which will then invoke the Lambda. My Lambda handler will look like:

def lambda_handler(event, context):
    // do stuff down here
    return responseObject

I am trying to find documentation on event and context so I know how to do things like:

  • extract query string parameters from requests

  • extract path parameters from requests

  • inspect the request entity

  • etc.

Surprising I can find no official AWS documentation on what fields/properties these two objects have on them when they are invoked from an API Gateway resource action. I found this article which was sort of helpful but nothing official from AWS. Can anyone point me in the right direction?

🌐
GitHub
github.com › actions-on-google › actions-on-google-nodejs › issues › 265
How to set context in AWS Lambda handler? · Issue #265 · actions-on-google/actions-on-google-nodejs
December 11, 2018 - My code works fine with this code: const {dialogflow} = require('actions-on-google'); const app = dialogflow(); // bunch of app.intent() exports.handler = app; Now I want to set context.callbackWaitsForEmptyEventLoop in AWS Lambda handle...
Author   luomanke
🌐
Pegasus One
pegasusone.com › home › how to use aws lambda function in node.js
How to Use AWS Lambda Function in Node.js - Pegasus One
February 6, 2026 - You use an AWS Lambda function in Node.js by writing your function handler in JavaScript or TypeScript, configuring the runtime environment in AWS, and deploying your code using the AWS Console, CLI, or CI/CD tools, allowing you to run serverless ...
🌐
Frontend Masters
frontendmasters.com › courses › serverless-aws › node-lambda-context
Node Lambda Context - Serverless with AWS Lambda | Frontend Masters
An event loop, you can think of it like, JavaScript is constantly going from top to bottom to run synchronous operations. When it comes across on the asynchronous, it puts it in a table to be processed later at the bottom of this synchronous test, and it continues on that process until there is nothing registered, right, so that's an event loop and it keeps doing that. [00:00:58] By default, the Lambda is going to continue to be open until there's nothing left on that asynch table basically.
🌐
npm
npmjs.com › package › aws-lambda-mock-context
aws-lambda-mock-context - npm
AWS region. ... Account number. ... Name of the function. ... Version of the function. ... Memory limit. ... Alias of the function. ... Timeout of the lambda function in seconds.
      » npm install aws-lambda-mock-context
    
Published   Aug 04, 2018
Version   3.2.1
Author   Sam Verschueren
🌐
Stackify
stackify.com › aws-lambda-with-node-js-a-complete-getting-started-guide
AWS Lambda with Node.js: A Complete Getting Started Guide - Stackify
May 1, 2023 - The first thing to note is that ... that are capable of invoking Lambda functions here. Use the context argument to pass the runtime parameter to the Lambda function....
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with typescript
Building Lambda functions with TypeScript - AWS Lambda
To add the Lambda type definitions to your function, install @types/aws-lambda as a development dependency: ... import { Context, S3Event, APIGatewayProxyEvent } from 'aws-lambda'; export const handler = async (event: S3Event, context: Context) => { // Function code };
🌐
AWS
docs.aws.amazon.com › AWSJavaScriptSDK › latest › AWS › Lambda.html
Class: AWS.Lambda — AWS SDK for JavaScript
We recommend that you migrate to AWS SDK for JavaScript v3. For additional details and information on how to migrate, please refer to the announcement. ... Constructs a service interface object. Each API operation is exposed as a function on service. ... Lambda is a compute service that lets ...