9

I am using VS Code for development of AWS Lambda functions, I started using the serverless framework and the serverless offline library but, I am unable to use VS Code's debug mode to locally debug the code.

I am referring many sites, Following is one of them: https://medium.com/@OneMuppet_/debugging-lambada-functions-locally-in-vscode-with-actual-break-points-deee6235f590

My project structure is as follows:

enter image description here

Package.json:

enter image description here

launch.json:

enter image description here

I get the following error when I start debug:

enter image description here

Can someone please guide, with the correct configuration?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dev1ce
  • 5,390
  • 17
  • 90
  • 150

3 Answers3

10

in the package.json add debug script:

"scripts": {
.......
    "debug": "node --inspect node_modules/serverless/bin/serverless offline -s dev",
.........
}

VS code lunch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "name": "Serverless",
      "runtimeExecutable": "npm",
      "runtimeArgs": [
        "run",
        "debug"
      ],
      "port": 9229
    }
  ]
}

Then start debugging from VS code

mfe
  • 1,158
  • 10
  • 15
  • 1
    Why on vscode output panel I wont get the same logging msgs as I would on a normal terminal session? – koalaok Nov 17 '21 at 13:31
4

The warning you are seeing is a deprecation warning; the legacy debugger (--debug) has been deprecated since Node 7.7.0. The correct way to attach a node debugger to serverless offline is by using --inspect:

node --inspect $(npm bin)/sls offline start
Daniel Cottone
  • 4,257
  • 24
  • 39
0

If you have a valid sample event in JSON format AND you are OK with debugging one function at a time, then here is a configuration that has worked great for me. It enables breakpoints and step-through debuggin exactly as you'd expect:

    {
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "name": "sls invoke local: myFunction",
      "runtimeExecutable": "sls",
      "runtimeArgs": [
        "invoke",
        "local",
        "-f",
        "loadOptions",
        "-p",
        "activities/myFunction/myFunction-event.json"
      ],
    },
Mike Duffy
  • 21
  • 4