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?
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.
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.
The easiest option I have so far with VS Code is this:
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()
Change program entry of the launcher.json
file like this:
"program": "${workspaceFolder}/<your app dir>/debug.js"
You can now just put a breakpoint on this line (app.handler()
) and it works
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With