无法在 Visual Studio 代码中调试无服务器应用程序
Can't debug serverless app in Visual Studio Code
我正在尝试了解如何使用 Visual Studio 代码调试器来调试无服务器 lambda 函数。出于测试目的,我有非常简单的 test
lambda 函数:
module.exports.handler = async (event) => {
debugger;
console.log(111, event);
};
然后,在launch.json
我创建了这样一个配置:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeVersion": "8.4.0",
"runtimeExecutable": "node",
"program": "${workspaceFolder}/node_modules/.bin/sls",
"cwd": "${workspaceRoot}",
"args": [
"invoke",
"local",
"--function",
"test",
"--data",
"{foo:'bar'}"
],
"port": 9229
}
]
}
现在,我在 lambda 函数中放置了一个断点,然后按 F5 启动调试器。我期待着进入代码,放上一些手表并逐步执行我的代码。但是没有任何反应。没有错误。没有控制台输出,没有代码在断点处暂停。没有什么。我得到的只是 debug console
中的消息:/home/set/.nvm/versions/node/v8.4.0/bin/node node_modules/.bin/sls invoke local --function test --data {foo:'bar'}
如果我去终端然后运行那一行我得到了预期的结果
set@set-home ~/www/blahblah/ens $ /home/set/.nvm/versions/node/v8.4.0/bin/node node_modules/.bin/sls invoke local --function test --data {foo:'bar'}
Serverless: INVOKING INVOKE
111 '{foo:bar}'
我做错了什么?如何在 Visual Studio 代码中调试无服务器应用程序?
我怀疑您只需要删除 "port": 9229
位。
我从未指定用于调试的端口 Serverless 在本地运行,但将其添加到我的任何工作配置中都会产生您观察到的症状。
顺便说一下,您也可以取出其他一些东西。作为参考,我的 Serverless 调试配置在本地调用时通常如下所示:
{
"type": "node",
"request": "launch",
"name": "Debug sls local",
"program": "${workspaceFolder}/node_modules/serverless/bin/serverless",
"args": [
"invoke", "local", "--function", "processFirehose", "--path", "sample-event.json",
"--stage",
"nonprod",
]
},
我正在尝试了解如何使用 Visual Studio 代码调试器来调试无服务器 lambda 函数。出于测试目的,我有非常简单的 test
lambda 函数:
module.exports.handler = async (event) => {
debugger;
console.log(111, event);
};
然后,在launch.json
我创建了这样一个配置:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeVersion": "8.4.0",
"runtimeExecutable": "node",
"program": "${workspaceFolder}/node_modules/.bin/sls",
"cwd": "${workspaceRoot}",
"args": [
"invoke",
"local",
"--function",
"test",
"--data",
"{foo:'bar'}"
],
"port": 9229
}
]
}
现在,我在 lambda 函数中放置了一个断点,然后按 F5 启动调试器。我期待着进入代码,放上一些手表并逐步执行我的代码。但是没有任何反应。没有错误。没有控制台输出,没有代码在断点处暂停。没有什么。我得到的只是 debug console
中的消息:/home/set/.nvm/versions/node/v8.4.0/bin/node node_modules/.bin/sls invoke local --function test --data {foo:'bar'}
如果我去终端然后运行那一行我得到了预期的结果
set@set-home ~/www/blahblah/ens $ /home/set/.nvm/versions/node/v8.4.0/bin/node node_modules/.bin/sls invoke local --function test --data {foo:'bar'}
Serverless: INVOKING INVOKE
111 '{foo:bar}'
我做错了什么?如何在 Visual Studio 代码中调试无服务器应用程序?
我怀疑您只需要删除 "port": 9229
位。
我从未指定用于调试的端口 Serverless 在本地运行,但将其添加到我的任何工作配置中都会产生您观察到的症状。
顺便说一下,您也可以取出其他一些东西。作为参考,我的 Serverless 调试配置在本地调用时通常如下所示:
{
"type": "node",
"request": "launch",
"name": "Debug sls local",
"program": "${workspaceFolder}/node_modules/serverless/bin/serverless",
"args": [
"invoke", "local", "--function", "processFirehose", "--path", "sample-event.json",
"--stage",
"nonprod",
]
},