我正在尝试了解如何使用 Visual Studio Code 调试器来调试无服务器 lambda 函数.出于测试目的,我有非常简单的 test lambda 函数:
I'm trying to find out how can I use Visual Studio Code debugger to debug serverless lambda function. For testing purposes I have very simple test lambda function:
module.exports.handler = async (event) => { debugger; console.log(111, event); };然后,在 launch.json 中我创建了这样一个配置:
Then, in launch.json I created such a configuration:
{ "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 启动调试器.我期待然后进入代码,放一些手表并逐步执行我的代码.但什么也没有发生.没有错误.没有控制台输出,没有代码在断点处暂停.没有什么.我得到的只是调试控制台中的消息:/home/set/.nvm/versions/node/v8.4.0/bin/node node_modules/.bin/sls invoke local --function test--data {foo:'bar'}
Now, I'm puting a breakpoint inside my lambda function and pressing F5 to start debugger. 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'}
如果我进入终端并运行该行,我得到的正是预期的
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}'我做错了什么?如何在 Visual Studio Code 中调试无服务器应用程序?
What am I doing wrong? How can I debug serverless application in Visual Studio Code?
推荐答案我怀疑你只需要去掉 "port": 9229 位.
I suspect you just need to get rid of the "port": 9229 bit.
我从未指定用于在本地调试 Serverless 功能的端口,但是将其添加到我的任何工作配置中会产生您观察到的症状.
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", ] },更多推荐
无法在 Visual Studio Code 中调试无服务器应用程序
发布评论