Visual Studio Code Debugger Not Connecting to SAM Local

Viewed 4992

Per the AWS documentation, I am starting SAM local like this:

$ sam local start-api -d 5858

I have the following in my launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to SAM Local",
            "type": "node",
            "request": "attach",
            "address": "localhost",
            "port": 5858,
            "localRoot": "${workspaceRoot}",
            "remoteRoot": "/var/task"
        }
    ]
}

But when I launch the visual studio debugger it says"cannot connect to runtime make sure that runtime is in 'legacy' debug mode"

It looks as though many people have this issue with Node.js 6 and Visual Studio Code but I can't seem to find an answer... I'm using version 1.18.1 of Visual Studio Code

I have tried adding "protocol": "Legacy" to launch.json config. I've also tried using --debug-port instead of -d. I'm on Windows 10. Not sure if the issue is windows-specific.

2 Answers

When running sam local either through a terminal or visual studio code's terminal, set your break points and select the name of your launch.json in the debug drop down as shown in the documentation.

https://github.com/awslabs/aws-sam-local#debugging-applications

After that, launch sam local start-api. Then when you hit an endpoint on the API you should see the terminal state something like:

2018/01/12 07:17:29 Invoking index.handler (nodejs6.10)

2018/01/12 07:17:29 Mounting /Users/24g/1725_ecpo_lambda as /var/task:ro inside runtime container Debugger listening on [::]:8000

Once you see that the debugger is listening. Click the play button on the the debugger. I've noticed that this doesn't usually pick up on its own, unless there is an exception I believe.

I'm using version 1.19.1 of visual studio code.

Have you tried using a different port? This is currently my configuration:

{
  "version": "0.2.0",
     "configurations": [
      {
        "name": "Attach to SAM Local",
        "type": "node",
        "request": "attach",
        "address": "localhost",
        "port": 8000,
        "localRoot": "${workspaceRoot}",
        "remoteRoot": "/var/task"
      }
   ]
}
Related