Debuging a serverless application in visual Studio Code

Like quite a few people I tried out the debugging example here.

and got the same error that was described here.

but the accepted answer does not work for me, I think it is because I have a gap in my understanding as I don’t normally develop in node.

To confirm the debugging example works fine when I create the example on AWS or run it locally in the console

but if I run from visual studio code I get the following error

The error makes perfect sense as there is no folder for \node_modules\serverless\bin\serverless within the project. but I am now stuck. My question is

"In the stack overflow question above have the developers pulled serverless into the project so that \node_modules\serverless\bin\serverless now contains a copy of what is stored in AppData\Roaming\npm\node_modules\serverless\bin (which is where the console runs serverless from) "?

or are they doing something else? could someone point me in the right direction?



Did you run an npm install in the project folder?

1 Like

No I hadn’t spotted that command so I tried it but it still wouldn’t run. But you pointed me in the right direction, I did some searching on npm install which lead me back to some of the serverless hello world examples

I saw that I had initially installed serverless globally by running

npm install serverless -g

so I took a punt and tried

npm install serverless

in the project directory to see what would happen. This appeared to do the trick as I now have the node_modules sub directory installed below the project, I changed the launch.json program value back to the value in the accepted answer on stack overflow tried again and it debugged straight into it.

So I now have the hello world example up and running which is great, thanks for the suggestion !

I am using mac and the setting below work fine for me, you have to manually pass the name of the function you are debugging

    "version": "0.2.0",
    "configurations": [
            "type": "node",
            "request": "launch",
            "name": "Launch Serverless Offline",
            "program": "${workspaceRoot}/node_modules/.bin/sls",
            "args": [
                "{ body : {\"username\" : \"admin\", \"password\" : \"apasswordhaha\"} }"

Hi All,

Has anyone done the same for golang lambda functions ?. Using the same approach, I can launch the golang function however as the type is “node”, the function is not being stopped at the breakpoint. Changing this to “go” (and using delve) doesn’t work as the program is no longer a “go” program.

Any help or hints appreciated.