Visual Studio代码调试器未连接到SAM本地 [英] Visual Studio Code Debugger Not Connecting to SAM Local

查看:91
本文介绍了Visual Studio代码调试器未连接到SAM本地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据AWS文档,我正在这样启动SAM本地:

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

$ sam local start-api -d 5858

在launch.json中有以下内容

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"
        }
    ]
}

但是当我启动Visual Studio调试器时,它说无法连接到运行时,请确保运行时处于旧式"调试模式"

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

似乎很多人在Node.js 6和Visual Studio Code中都遇到了这个问题,但是我似乎找不到答案...我正在使用Visual Studio Code的1.18.1版本.

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

我尝试将"protocol":"Legacy"添加到launch.json配置中.我也尝试过使用--debug-port而不是-d.我使用的是Windows10.不确定该问题是否特定于Windows.

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.

推荐答案

通过终端或Visual Studio Code的终端运行sam local时,设置断点并选择 launch.json 在调试下拉列表中,如文档所示.

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

然后,启动sam local start-api.然后,当您在API上命中一个端点时,应该看到终端状态,例如:

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调用index.handler(nodejs6.10)

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

2018/01/12 07:17:29将/Users/24g/1725_ecpo_lambda安装为/var/task:ro在运行时容器调试器中侦听[::]:8000

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.

我正在使用Visual Studio代码的1.19.1版本.

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"
      }
   ]
}

这篇关于Visual Studio代码调试器未连接到SAM本地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆