d01772376c | ||
---|---|---|
.. | ||
README.md | ||
configure-launch.png | ||
debug-session.png |
README.md
Debugging AWS Lambda functions with SST
SST is a framework for building serverless applications. It allows you to test and debug your Lambda functions locally without having to redeploy your changes. It does this by streaming the Lambda function requests from AWS to your local client and running it locally. So for Node.js Lambda functions, you can set breakpoints locally and they'll reflect the event and context of the deployed Lambda function.
This guide will help you configure VS Code to support setting breakpoints and debugging your Lambda functions.
Getting started
Requirements
- The latest version of VS Code installed.
- A project initialized with the SST CLI.
Configure launch.json
file
-
Open your project folder in VS Code.
-
Click on the Debug icon in the Activity Bar to switch to the Debug view.
-
Under Run and Debug click on create a launch.json file.
-
In the Select environment input, select Node.js.
-
Replace the content of the generated
launch.json
file with the following configuration:{ "version": "0.2.0", "configurations": [ { "name": "Debug SST Start", "type": "node", "request": "launch", "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/sst", "runtimeArgs": ["start", "--increase-timeout"], "console": "integratedTerminal", "skipFiles": ["<node_internals>/**"] }, { "name": "Debug SST Tests", "type": "node", "request": "launch", "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/sst", "args": ["test", "--runInBand", "--no-cache", "--watchAll=false"], "cwd": "${workspaceRoot}", "protocol": "inspector", "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "env": { "CI": "true" }, "disableOptimisticBPs": true } ] }
This JSON file defines two configurations, one for the
sst start
command; to debug your Lambda functions. And another for thesst test
command; to debug your tests.
Debugging your Lambda functions
SST runs your Lambda functions locally and streams the requests back to AWS. So your functions can be debugged like any other Node.js application.
- Open a Lambda function inside the
src/
directory. - Put a breakpoint 🔴 anywhere in the function.
- Switch to the Debug view and select "Debug SST Start".
- Press
F5
or click on Start debugging. - Tadaa! 🎉 Your breakpoint should be hit, and now you have full access to the event and context of the deployed Lambda function.