Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot debug serverless application in Visual Studio Code

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.

like image 870
Wella Avatar asked Aug 01 '17 11:08

Wella


People also ask

How do I run lambda in debug mode?

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.

Which AWS service can be used to run test and debug Lambda function code?

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.


1 Answers

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

like image 114
Mike Patrick Avatar answered Sep 24 '22 12:09

Mike Patrick