🌐
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
For example, to enable ES module require support, set NODE_OPTIONS to --experimental-require-module. Lambda detects this override and removes the corresponding disable flag. Using experimental features can lead to instability and performance issues. These features might be changed or removed ...
Discussions

How to test AWS Lambda handler locally using NodeJS?
In the Lambda environment, some AWS code will call this handler with message. In your local environment, you have to call your handler by yourself. You could also have a look of this doc, it is a way to "simulate" Lambda in local environment. ... You can check out lambda-local. It's a little fancier than the accepted answer above. For example... More on stackoverflow.com
🌐 stackoverflow.com
Deploying a node js project on aws lambda?
Lambdas can only run for 15 minutes so using that as your frontend would be counter intuitive. I suggest looking into using S3 to serve your static frontend and use a serverles lambda function as your backend. See: https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/deploy-a-react-based-single-page-application-to-amazon-s3-and-cloudfront.html More on reddit.com
🌐 r/aws
8
0
January 24, 2023
You are Senior JS Backend at start up. What do you choose Bun vs Node.js?
Node.js, in my experience it's more mature than bun More on reddit.com
🌐 r/webdev
58
0
March 4, 2026
How I got Typescript Lambda Layers working with SAM template.
This is how I'm doing it: https://dan.salvagni.io/b/aws-sam-and-typescript-building-functions-and-layers/ I also have my layers as dev dependencies in a global package.json so vscode can pick them up while writing code: "devDependencies": { "commons": "file:./layers/commons", ... } More on reddit.com
🌐 r/aws
11
19
April 27, 2023
🌐
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
You can configure Node.js in Lambda to detect automatically whether a .js file should be treated as CommonJS or as an ES module by adding the —experimental-detect-module flag to the NODE_OPTIONS environment variable. For more information, see Experimental Node.js features. The following examples show function handlers written using both ES modules and CommonJS modules. The remaining examples on this page all use ES modules. ... const url = "https://aws.amazon.com/"; export const handler = async(event) => { try { const res = await fetch(url); console.info("status", res.status); return res.status; } catch (e) { console.error(e); return 500; } };
🌐
Medium
medium.com › @tombray › getting-started-with-aws-lambda-node-js-904bc0bfb83
Getting Started with AWS Lambda (Node JS) | by Tom Bray | Medium
January 10, 2016 - In this article I’ll walk you through creating a Lambda the easy way, using the AWS Console. At the end I provide links to gulp projects…
🌐
GitHub
github.com › snowplow › aws-lambda-nodejs-example-project
GitHub - snowplow-archive/aws-lambda-nodejs-example-project: An AWS Lambda function in Node.js reading events from Amazon Kinesis and writing event counts to DynamoDB
June 5, 2015 - An AWS Lambda function in Node.js reading events from Amazon Kinesis and writing event counts to DynamoDB - snowplow-archive/aws-lambda-nodejs-example-project
Starred by 102 users
Forked by 24 users
Languages   JavaScript 94.7% | Shell 5.3% | JavaScript 94.7% | Shell 5.3%
🌐
AWS
aws.amazon.com › blogs › compute › node-js-20-x-runtime-now-available-in-aws-lambda
Node.js 20.x runtime now available in AWS Lambda | Amazon Web Services
November 15, 2023 - You can now develop AWS Lambda functions using the Node.js 20 runtime. This Node.js version is in active LTS status and ready for general use. To use this new version, specify a runtime parameter value of nodejs20.x when creating or updating functions or by using the appropriate container base ...
🌐
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 - Getting started with Serverless on AWS Lambda is just a few commands away: # 1. Create a new Serverless project: $ serverless create --template aws-nodejs --path my-service # 2. Change into the newly created directory $ cd my-service # 3. Install ...
Find elsewhere
🌐
AWS
aws.amazon.com › blogs › compute › node-js-24-runtime-now-available-in-aws-lambda
Node.js 24 runtime now available in AWS Lambda | Amazon Web Services
November 25, 2025 - AWSTemplateFormatVersion: "2010-09-09" Transform: AWS::Serverless-2016-10-31 Resources: MyFunction: Type: AWS::Serverless::Function Properties: Handler: lambda_function.lambda_handler Runtime: nodejs24.x CodeUri: my_function/. Description: My Node.js Lambda Function
🌐
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 - # filename: serverless.yml service: ImageUploaderService # The `provider` block defines where your service will be deployed custom: bucket: getting-started-lambda-example provider: name: aws runtime: nodejs8.10 region: eu-west-1 stackName: imageUploader iamRoleStatements: - Effect: "Allow" Action: - "s3:PutObject" Resource: - "arn:aws:s3:::${self:custom.bucket}/*" # The `functions` block defines what code to deploy functions: UploadImage: handler: uploadImage.handler # The `events` block defines how to trigger the uploadImage.handler code events: - http: path: upload method: post cors: true environment: Bucket: ${self:custom.bucket} resources: Resources: StorageBucket: Type: "AWS::S3::Bucket" Properties: BucketName: ${self:custom.bucket}
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js › instrumenting node.js code in aws lambda
Instrumenting Node.js code in AWS Lambda - AWS Lambda
To avoid uploading runtime dependencies every time you update your function code, package the X-Ray SDK in a Lambda layer. The following example shows an AWS::Serverless::LayerVersion resource that stores the AWS X-Ray SDK for Node.js. Resources: function: Type: AWS::Serverless::Function Properties: CodeUri: function/. Tracing: Active Layers: - !Ref libs ... libs: Type: AWS::Serverless::LayerVersion Properties: LayerName: blank-nodejs-lib Description: Dependencies for the blank sample app.
🌐
AppSignal
blog.appsignal.com › 2022 › 03 › 23 › build-serverless-apis-with-nodejs-and-aws-lambda.html
Build Serverless APIs with Node.js and AWS Lambda | AppSignal Blog
August 9, 2023 - Resources: HelloWorldFunction: Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction Properties: CodeUri: hello-world/ Handler: app.lambdaHandler Runtime: nodejs18.x Architectures: - x86_64 Events: HelloWorld: Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api Properties: Path: /hello Method: get · These lines describe the name of your Lambda function (HelloWorldFunction), the runtime used to execute it (nodejs18.x), and the type of trigger for the function (Api).
🌐
GitHub
github.com › aws-samples › aws-lambda-demo-with-node-express
GitHub - aws-samples/aws-lambda-demo-with-node-express · GitHub
The purpose of this repository is to demonstrate how to deploy a simple web application built by Express - Node.js web application framework on AWS Lambda.
Starred by 21 users
Forked by 20 users
Languages   JavaScript 52.7% | HTML 47.3%
🌐
Medium
medium.com › hackernoon › getting-started-with-aws-lambda-and-node-js-4ce3259c6dfd
Getting Started with AWS Lambda and Node.js | by Adnan Rahić | HackerNoon.com | Medium
August 16, 2018 - You’ll land on the Lambda homepage with a big orange button prompting you to create a new function. Well, don’t keep it waiting any longer, press it. ... This will take you to the main function creation wizard. As this example will cover a basic function that will simulate a dice throw, let’s forget about the blueprints and just author one from scratch. Awesome!
🌐
Hevo
hevodata.com › home › learn › data strategy
NodeJS Lambda | The Complete Guide to Get Started 101
January 12, 2026 - You’ll need a NodeJS runtime first. Now you must install a NodeJS version that AWS Lambda supports. In this post, NodeJS 8.10 runtime is used. You’ll also want to make sure that your Local Environment is as similar as possible to the Production Environment.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js › deploy node.js lambda functions with .zip file archives
Deploy Node.js Lambda functions with .zip file archives - AWS Lambda
If your .zip file is located in a folder on your local build machine, use the --zip-file option to specify the file path, as shown in the following example command. aws lambda create-function --function-name myFunction \ --runtime nodejs24.x --handler index.handler \ --role arn:aws:iam::111122223333:role/service-role/my-lambda-role \ --zip-file fileb://myFunction.zip
Top answer
1 of 8
84

This is what I did:

index.js

exports.handler = async (event) => {
    console.log('hello world');

    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!')
    };

    return response;
};

package.json

// using require
"scripts": {
  "locally": "node -e \"console.log(require('./index').handler(require('./event.json')));\""
}

// or the following for ESM using import
"scripts": {
  "locally": "node --input-type=module -e \"import {handler} from './index.mjs'; console.log(await handler(JSON.parse(fs.readFileSync('./event.json'))));\""
}

event.json

{
  "Records": [
    {
      "eventVersion": "2.0",
      "eventSource": "aws:s3",
      "awsRegion": "eu-central-1",
      "eventTime": "1970-01-01T00:00:00.000Z",
      "eventName": "ObjectCreated:Put",
      "userIdentity": {
        "principalId": "AIDAJDPLRKLG7UEXAMPLE"
      },
      "requestParameters": {
        "sourceIPAddress": "127.0.0.1"
      },
      "responseElements": {
        "x-amz-request-id": "C3D13FE58DE4C810",
        "x-amz-id-2": "FMyUVURIY8/IgAtTv8xRjskZQpcIZ9KG4V5Wp6S7S/JRWeUWerMUE5JgHvANOjpD"
      },
      "s3": {
        "s3SchemaVersion": "1.0",
        "configurationId": "testConfigRule",
        "bucket": {
          "name": "my-bucket",
          "ownerIdentity": {
            "principalId": "A3NL1KOZZKExample"
          },
          "arn": "arn:aws:s3:::my-bucket"
        },
        "object": {
          "key": "HelloWorld.jpg",
          "size": 1024,
          "eTag": "d41d8cd98f00b204e9800998ecf8427e",
          "versionId": "096fKKXTRTtl3on89fVO.nfljtsv6qko"
        }
      }
    }
  ]
}

Shell

npm run locally

Output

> node -e "console.log(require('./index').handler({}));"

hello world
Promise { { statusCode: 200, body: '"Hello from Lambda!"' } }
2 of 8
52

You need to call your handler function from another file lets say testHandler.js in order to run via NodeJs.

This will be done like this

//import your handler file or main file of Lambda
let handler = require('./handler');

//Call your exports function with required params
//In AWS lambda these are event, content, and callback
//event and content are JSON object and callback is a function
//In my example i'm using empty JSON
handler.handlerEvent( {}, //event
    {}, //content
    function(data,ss) {  //callback function with two arguments 
        console.log(data);
    });

Now you can use node testHandler.js to test your handler function.

EDIT: Sample Event and content data as requested

Event:

{
    "resource": "/API/PATH",
    "path": "/API/PATH",
    "httpMethod": "POST",
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
        "cache-control": "no-cache",
        "CloudFront-Forwarded-Proto": "https",
        "CloudFront-Is-Desktop-Viewer": "true",
        "CloudFront-Is-Mobile-Viewer": "false",
        "CloudFront-Is-SmartTV-Viewer": "false",
        "CloudFront-Is-Tablet-Viewer": "false",
        "CloudFront-Viewer-Country": "IN",
        "content-type": "application/json",
        "Host": "url.us-east-1.amazonaws.com",
        "origin": "chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop",
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
        "Via": "2.0 XXXXXXXXXXXXXX.cloudfront.net (CloudFront)",
        "X-Amz-Cf-Id": "XXXXXXXXXX51YYoOl75RKjAWEhCyna-fuQqEBjSL96TMkFX4H0xaZQ==",
        "X-Amzn-Trace-Id": "Root=1-XXX03c23-25XXXXXX948c8fba065caab5",
        "x-api-key": "SECUREKEY",
        "X-Forwarded-For": "XX.XX.XXX.XXX, XX.XXX.XX.XXX",
        "X-Forwarded-Port": "443",
        "X-Forwarded-Proto": "https"
    },
    "multiValueHeaders": {
        "Accept": [ "*/*" ],
        "Accept-Encoding": [ "gzip, deflate, br" ],
        "Accept-Language": [ "en-GB,en-US;q=0.9,en;q=0.8" ],
        "cache-control": [ "no-cache" ],
        "CloudFront-Forwarded-Proto": [ "https" ],
        "CloudFront-Is-Desktop-Viewer": [ "true" ],
        "CloudFront-Is-Mobile-Viewer": [ "false" ],
        "CloudFront-Is-SmartTV-Viewer": [ "false" ],
        "CloudFront-Is-Tablet-Viewer": [ "false" ],
        "CloudFront-Viewer-Country": [ "IN" ],
        "content-type": [ "application/json" ],
        "Host": [ "apiurl.us-east-1.amazonaws.com" ],
        "origin": [ "chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop" ],
        "User-Agent": [ "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" ],
        "Via": [ "2.0 XXXXXXXXXXXXXX.cloudfront.net (CloudFront)" ],
        "X-Amz-Cf-Id": [ "XXXXXXXXXhCyna-fuQqEBjSL96TMkFX4H0xaZQ==" ],
        "X-Amzn-Trace-Id": [ "Root=1-XXXXXXX67339948c8fba065caab5" ],
        "x-api-key": [ "SECUREAPIKEYPROVIDEDBYAWS" ],
        "X-Forwarded-For": [ "xx.xx.xx.xxx, xx.xxx.xx.xxx" ],
        "X-Forwarded-Port": [ "443" ],
        "X-Forwarded-Proto": [ "https" ]
    },
    "queryStringParameters": null,
    "multiValueQueryStringParameters": null,
    "pathParameters": null,
    "stageVariables": null,
    "requestContext": {
        "resourceId": "xxxxx",
        "resourcePath": "/api/endpoint",
        "httpMethod": "POST",
        "extendedRequestId": "xxXXxxXXw=",
        "requestTime": "29/Nov/2018:19:21:07 +0000",
        "path": "/env/api/endpoint",
        "accountId": "XXXXXX",
        "protocol": "HTTP/1.1",
        "stage": "env",
        "domainPrefix": "xxxxx",
        "requestTimeEpoch": 1543519267874,
        "requestId": "xxxxxxx-XXXX-xxxx-86a8-xxxxxa",
        "identity": {
            "cognitoIdentityPoolId": null,
            "cognitoIdentityId": null,
            "apiKey": "SECUREAPIKEYPROVIDEDBYAWS",
            "cognitoAuthenticationType": null,
            "userArn": null,
            "apiKeyId": "xxXXXXxxxxxx",
            "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
            "accountId": null,
            "caller": null,
            "sourceIp": "xx.xxx.xxx.xxx",
            "accessKey": null,
            "cognitoAuthenticationProvider": null,
            "user": null
        },
        "domainName": "url.us-east-1.amazonaws.com",
        "apiId": "xxxxx"
    },
    "body": "{\n    \"city\": \"Test 1 City\",\n    \"state\": \"NY\",\n    \"zipCode\": \"11549\"\n}",
    "isBase64Encoded": false
}

Content:

{
    "callbackWaitsForEmptyEventLoop": true,
    "logGroupName": "/aws/lambda/lambda-name",
    "logStreamName": "2018/11/29/[$LATEST]xxxxxxxxxxxb",
    "functionName": "lambda-name",
    "memoryLimitInMB": "1024",
    "functionVersion": "$LATEST",
    "invokeid": "xxxxx-xxx-11e8-xxx-xxxxxxxf9",
    "awsRequestId": "xxxxxx-xxxxx-11e8-xxxx-xxxxxxxxx",
    "invokedFunctionArn": "arn:aws:lambda:us-east-1:xxxxxxxx:function:lambda-name"
}
🌐
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 three-part-series we’ll look at getting a Node.js application which performs image resizing running on AWS Lambda. We’ll look at how Node.js applications work, then we’ll configure our AWS account and get the AWS CLI utility working. We’ll Create a Lambda Function within AWS and configure an Application Gateway which is required to route HTTP requests to our Lambda Function.
🌐
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 - How do you use an AWS Lambda function in Node.js? You use an AWS Lambda function in Node.js by writing your function handler in JavaScript or TypeScript, wp_title()
🌐
GitHub
github.com › hayanisaid › AWS-Lambda-nodejs-example
GitHub - hayanisaid/AWS-Lambda-nodejs-example
Serverless: Creating Stack... Serverless: Checking Stack create progress... ........ Serverless: Stack create finished... Serverless: Uploading CloudFormation file to S3... Serverless: Uploading artifacts...
Forked by 8 users
Languages   JavaScript 100.0% | JavaScript 100.0%