serverless / serverless-azure-functions

Serverless Azure Functions Plugin – Add Azure Functions support to the Serverless Framework
MIT License
266 stars 162 forks source link

Debug Severless Offline #406

Closed Rapol closed 4 years ago

Rapol commented 4 years ago

Is it possible to debug node functions when running serverless offline? I have been able to do this with the serverless offline plugin for AWS with these VS code settings:

{
    "version":"0.2.0",
    "configurations":[
       {
          "type":"node",
          "request":"launch",
          "name":"Debug Serverless",
          "cwd":"${workspaceFolder}",
          "runtimeExecutable":"npm",
          "runtimeArgs":[
             "run",
             "debug"
          ],
          "outFiles":[
             "${workspaceFolder}/handler.js"
          ],
          "port":9229,
          "sourceMaps":true
       }
    ]
 }

And npm script

node --inspect ./node_modules/serverless/bin/serverless offline

Digging into the azure-functions-core-tools I found this:

https://github.com/Azure/azure-functions-core-tools/wiki/Enable-Debugging-for-language-workers

I tried modifying this plugin to pass the language-worker parameter but to no avail.

tbarlow12 commented 4 years ago

Hi @Rapol. The easiest way that we have found is just to run sls offline and then attach the debugger to the existing process. Here's the launch.json file:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach by Process ID",
      "processId": "${command:PickProcess}"
    }
  ]
}

Set a breakpoint, start offline and then start debugging. VS Code will ask you to pick a process. Choose the process. It's usually the first one that comes up in the list, but it's the one that has azure-functions-core-tools/bin/worker in the title.

Going to close this issue for now, feel free to re-open if you have a question specifically related to the plugin itself.