[英]Can't debug serverless app in Visual Studio Code
我試圖找出如何使用Visual Studio Code調試器來調試無服務器的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
位。
我從未在本地指定用於調試無服務器功能的端口,但將其添加到我的任何工作配置會產生您觀察到的症狀。
順便說一下,你也可以把其他一些東西拿走。 作為參考,我的無服務器調試配置通常看起來像本地調用:
{
"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.