[英]Can't debug serverless app in Visual Studio Code
I'm trying to find out how can I use Visual Studio Code debugger to debug serverless lambda function. 我试图找出如何使用Visual Studio Code调试器来调试无服务器的lambda函数。 For testing purposes I have very simple
test
lambda function: 出于测试目的,我有非常简单的
test
lambda函数:
module.exports.handler = async (event) => {
debugger;
console.log(111, event);
};
Then, in launch.json
I created such a configuration: 然后,在
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
}
]
}
Now, I'm puting a breakpoint inside my lambda function and pressing F5 to start debugger. 现在,我在lambda函数中放置一个断点并按F5启动调试器。 I'm expecting then to go in code, put some watches and walk my code step-by-step.
我期待着进入代码,放一些手表,一步一步地走我的代码。 But nothing happens.
但没有任何反应。 No errors.
没有错误。 No console outputs, no code paused on breakpoints.
没有控制台输出,断点上没有代码暂停。 Nothing.
没有。 All I get is message in
debug console
: /home/set/.nvm/versions/node/v8.4.0/bin/node node_modules/.bin/sls invoke local --function test --data {foo:'bar'}
我得到的只是
debug console
消息: /home/set/.nvm/versions/node/v8.4.0/bin/node node_modules/.bin/sls invoke local --function test --data {foo:'bar'}
If I go then in terminal and run that line I got exactly what is expected 如果我去终端然后运行那条线路,我就得到了预期的结果
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}'
What am I doing wrong? 我究竟做错了什么? How can I debug serverless application in Visual Studio Code?
如何在Visual Studio代码中调试无服务器应用程序?
I suspect you just need to get rid of the "port": 9229
bit. 我怀疑你只需要摆脱
"port": 9229
位。
I've never specified a port for debugging Serverless functions locally, but adding it to any of my working configurations produces the symptoms you observe. 我从未在本地指定用于调试无服务器功能的端口,但将其添加到我的任何工作配置会产生您观察到的症状。
Incidentally, you might be able to take some of the other stuff out, as well. 顺便说一下,你也可以把其他一些东西拿走。 For reference, my Serverless debug configurations typically look like this for invoking locally:
作为参考,我的无服务器调试配置通常看起来像本地调用:
{
"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",
]
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.