I have tried to debug serverless application developed using serverless framework in VS code. I have followed this article.
But when I trying to debug the code I'm getting an error from VS code as below.
Cannot launch program 'g:\Projects\Serverless1\node_modules.bin\sls'; setting the 'outDir or outFiles' attribute might help.
sls command file already exists in the folder and following are the launch.json file settings
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"protocol": "inspector",
"name": "run hello function",
"program": "${workspaceRoot}\\node_modules\\.bin\\sls",
"args": [
"invoke",
"local",
"-f",
"hello",
"--data",
"{}"
]
}
]
Please help me to fix this issue.
Running AWS SAM locally in debug mode 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 SAM Local is a CLI tool that allows you to locally test and debug your AWS Lambda functions defined by AWS Serverless Application Model (SAM) templates.
I attempted to follow the same article, and experienced the same error. Adding outFiles
didn't help, although it did change my error message to:
Cannot launch program 'd:\<path>\node_modules\.bin\sls' because corresponding JavaScript cannot be found.
I can't explain why VSCode has a problem with the executable in node_modules/.bin
, but if I point at node_modules/serverless/bin
instead, things work as expected:
"program": "${workspaceFolder}\\node_modules\\serverless\\bin\\serverless",
Here is my full working configuration, where my test event JSON exists in sample-event.json
in the project root:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Lambda",
"program": "${workspaceFolder}/node_modules/serverless/bin/serverless",
"args": [
"invoke",
"local",
"-f",
"<function-name>",
"--data",
"{}" // You can use this argument to pass data to the function to help with the debug
]
}
]
}
Using Serverless ^1.26.1, Node 8.9.4 LTS, VSCode 1.20.1
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