[英]How to debug application made by AWS SAM in VSCode?
I made Go application by AWS SAM.我通过 AWS SAM 制作了 Go 应用程序。 Now I try to debug this sample application in VSCode, but It fails so I want to know how to correctly debug it.现在我尝试在 VSCode 中调试这个示例应用程序,但它失败了,所以我想知道如何正确调试它。
toggl-slack
├── Makefile
├── README.md
├── dlv
├── samconfig.toml
├── hello-world
│ ├── main.go
│ └── main_test.go
└── template.yaml
I put following command on console for debug.我将以下命令放在控制台上进行调试。
cd toggl-slack
go get -u github.com/go-delve/delve/cmd/dlv
GOARCH=amd64 GOOS=linux go build -o ./dlv github.com/go-delve/delve/cmd/dlv
GOARCH=amd64 GOOS=linux go build -gcflags='-N -l' -o hello-world/hello-world ./hello-world
sam local start-api -d 5986 --debugger-path . --debug-args="-delveAPI=2"
curl http://127.0.0.1:3000/hello
As result, debug does not work and console shows error message.结果,调试不起作用并且控制台显示错误消息。
Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2019-12-28 21:23:17 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
Invoking hello-world (go1.x)
Fetching lambci/lambda:go1.x Docker container image......
Mounting /Users/jpskgc/toggl-slack/hello-world as /var/task:ro,delegated inside runtime container
Could not create config directory: mkdir /home/sbx_user1051: permission denied.API server listening at: [::]:5986
2019-12-28T12:23:46Z info layer=debugger launching process with args: [/var/task/hello-world]
2019-12-28T12:23:47Z warning layer=debugger reading debug_info: could not find abstract origin (0x13ed31) of inlined call at 0xfab50
launch.json启动文件
{
"version": "0.2.0",
"configurations": [
{
"name": "Connect to Lambda container",
"type": "go",
"request": "launch",
"mode": "remote",
"remotePath": "",
"port": 5986,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": []
}
]
}
Other code is same as default sample application for AWS SAM.其他代码与 AWS SAM 的默认示例应用程序相同。
Full Source Code is here:完整源代码在这里:
https://github.com/jpskgc/toggl-slack/tree/0db02109685ce89f17ed64fdaadd5261e5f61512 https://github.com/jpskgc/toggl-slack/tree/0db02109685ce89f17ed64fdaadd5261e5f61512
The reading debug_info: could not find abstract origin
line tells us that the compile flags got scrambled and the debug info was not actually included. reading debug_info: could not find abstract origin
行告诉我们编译标志被打乱了,并且调试信息实际上并未包含在内。 What we need is:我们需要的是:
GOOS=linux GOARCH=amd64 go build -gcflags "all=-N -l" -o hello-world/hello-world ./hello-world
Second, VSCode should tell you this, but in launch.json
, "request": "launch",
is now "request": "attach",
for mode remote
giving:其次,VSCode 应该告诉你这一点,但在launch.json
, "request": "launch",
现在是"request": "attach",
对于模式remote
给予:
{
"version": "0.2.0",
"configurations": [
{
"name": "Connect to SAM local",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "",
"port": 5986,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": []
}
]
}
With the above changes you should be able to attach to the debug server using VSCode (or GoLand/Vim/CLI).通过上述更改,您应该能够使用 VSCode(或 GoLand/Vim/CLI)连接到调试服务器。
Finally, the Could not create config directory: mkdir /home/sbx_user1051: permission denied.
最后, Could not create config directory: mkdir /home/sbx_user1051: permission denied.
line is safe to ignore.行是可以安全忽略的。
I am contributing this on behalf of my employer, Amazon.我代表我的雇主亚马逊做出贡献。 My contribution is licensed under the MIT license.我的贡献是在 MIT 许可下获得许可的。 See here for a more detailed explanation.有关更详细的解释,请参见此处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.