An AWS Lambda function using the Node.js 22.x runtime should look something like this:

File: index.mjs (original version)
export const handler = async (event, context) => { (1)
  const response = {
    statusCode: 200,
    body: JSON.stringify({
      message: "Hello, World!"
    })
  };
  return response; (2)
};
1 The handler function has two parameters:
  • event: This parameter is an object that is used to pass in event data to the handler. It contains, among others, the information detailed in the following table:

    Table 1. Contents of Event
    Keys Associated Value
    event.version

    A string with the current version of this event object. Should be '2.0' at the time of this writing.

    event.rawPath

    A string with the request path (for example /some_resource).

    event.queryStringParameters

    An object with the query string parameters (only if it actually has any).

    event.headers

    An object with the request headers.

    event.body

    A string with the request body (only if it actually has one).

    event.requestContext.domainName

    A string with the domain name of the server where the AWS Lambda function is hosted.

    event.requestContext.http.method

    A string with the request HTTP method (GET or POST, for example).

    event.requestContext.http.protocol

    A string with the HTTP version used by the request (HTTP/1.1, for example).

  • context: This parameter provides runtime information to your handler. Its type is LambdaContext.

2 The handler should return an object from which the HTTP response will be constructed.
Table 2. Object Keys for HTTP Response
Key Description
statusCode

An integer number with the HTTP response status code.

body

A string with the response body. Typically, the result of calling JSON.stringify method to produce JSON output.

headers

This is an optional key, but if provided it should refer to an object with additional response headers.