Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug aws lambda functions written in node js

We have been developing AWS Lambda functions in Node JS for a few months. Can we debug, i.e. step through the Node JS code as we can with .Net C# code in Visual Studio?

like image 822
Steve Avatar asked Jun 07 '17 04:06

Steve


People also ask

How do I debug AWS Lambda?

To run AWS SAM in debug mode, use commands sam local invoke or sam local start-api with the --debug-port or -d option. If you're using sam local start-api , the local API Gateway instance exposes all of your Lambda functions.

Does AWS Lambda support node JS?

AWS Lambda now supports Node. js 16 as both a managed runtime and a container base image. Developers creating serverless applications in Lambda with Node. js 16 can take advantage of new features such as support for Apple silicon for local development, the timers promises API, and enhanced performance.


2 Answers

The easiest option I have so far with VS Code is this:

  1. Create a new file, lets say call it debug.js and just call your lambda function from here, something like this: const app = require('./index') app.handler()

  2. Change program entry of the launcher.json file like this: "program": "${workspaceFolder}/<your app dir>/debug.js"

  3. You can now just put a breakpoint on this line (app.handler()) and it works

like image 100
Mohammad Haque Avatar answered Oct 25 '22 05:10

Mohammad Haque


Step through debugging is now possible with AWS Lambda with the Sigma IDE. Yes, you debug the function while its actually running within AWS - See the demo below https://serverless.asankha.com/2019/08/write-lambda-function-test-it-instantly.html

like image 44
Asankha Avatar answered Oct 25 '22 05:10

Asankha