aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

Bug: Debug Portal not working with sam local start-api dlv and VSCODE #4218

Open andrewbohm opened 2 years ago

andrewbohm commented 2 years ago

Description:

Debug port is not opening up when running sam local command below. only port 5001 is exposed

Steps to reproduce:

  1. sam build
  2. sam local start-api -p 5001-d 8099 --debugger-path={CORRECT PATH TO dlv} --debug-args="-delveAPI=2"

Observed result:

sam local start-api -p 5001-d 8099 --debugger-path={CORRECT PATH TO dlv} --debug-args="-delveAPI=2" OUTPUT:

Mounting LambdaFunctionName at http://127.0.0.1:5001/animal [POST]
Mounting LambdaFunctionName2 at http://127.0.0.1:5001/name [POST]
Mounting LambdaFunctionName3 at http://127.0.0.1:5001/address [POST]
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
2022-09-09 14:56:46  * Running on http://127.0.0.1:5001/ (Press CTRL+C to quit)

launch.json:

{
        "name": "Debug with sam",
        "type": "go",
        "request": "attach",
        "mode": "remote",
        "port": 8991,
        "host": "localhost"
},

Expected result:

To show debug section in output and show debug port opened. When running Debug With SAM in VSCODE I would expect it to attach correctly and not state the following: Failed to continue: "Error: connect ECONNREFUSED 127.0.0.1:8991"

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Windows WSLv2 Linux Ubuntu
  2. sam --version: 1.56.1
  3. AWS region: N/A - local run

Add --debug flag to command you are running

mndeveci commented 2 years ago

Thanks for reporting this issue.

I've tried using AWS Toolkit's shortcut (which displays on top of the API definition) to start the debugging session. I was able to attach debugger and start debugging.

Can you try with that approach and see if it is working?

andrewbohm commented 2 years ago

@mndeveci Thanks for responding. I do not see AWS toolkit shortcut you are stating. I did try try the "AWS: Add Debug Configuration" with no avail.
See screenshot: Screenshot 2022-09-15 093056

mndeveci commented 2 years ago

There is one before the Events property, which says AWS: Add API Debug Configuration, can you try that one and see if it is going to stop at breaking point?

andrewbohm commented 2 years ago

No luck.
Same results with both Add Debug configuration settings.

{
  "version": "0.2.0",
  "configurations": [
    {
        "type": "aws-sam",
        "request": "direct-invoke",
        "name": "common-services:GetQrCodeFunction",
        "invokeTarget": {
            "target": "template",
            "templatePath": "${workspaceFolder}/template.yaml",
            "logicalId": "GetQrCodeFunction"
        },
        "lambda": {
            "payload": {},
            "environmentVariables": {}
        }
    },
    {
        "type": "aws-sam",
        "request": "direct-invoke",
        "name": "API common-services:GetQrCodeFunction",
        "invokeTarget": {
            "target": "api",
            "templatePath": "${workspaceFolder}/template.yaml",
            "logicalId": "GetQrCodeFunction"
        },
        "api": {
            "path": "/generate-qrcode",
            "httpMethod": "post",
            "payload": {
                "json": {}
            }
        }
    }
] 
}

Debug console

2022-09-15T21:30:22Z info layer=debugger created breakpoint: &api.Breakpoint{ID:1, Name:"", Addr:0x8a8ead, Addrs:[]uint64{0x8a8ead}, File:"/home/abohm/Code/pacific-uniform/common-services/common-services/get-qrcode/main.go", Line:31, FunctionName:"main.handler", Cond:"", HitCond:"", HitCondPerG:false, Tracepoint:false, TraceReturn:false, Goroutine:false, Stacktrace:0, Variables:[]string(nil), LoadArgs:(*api.LoadConfig)(0xc000e48000), LoadLocals:(*api.LoadConfig)(0xc000e48030), WatchExpr:"", WatchType:0x0, VerboseDescr:[]string(nil), HitCount:map[string]uint64{}, TotalHitCount:0x0, Disabled:false, UserData:interface {}(nil)}
2022-09-15T21:30:22Z debug layer=debugger continuing
/var/task/get-qrcode: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by /var/task/get-qrcode)
2022-09-15T21:30:22Z debug layer=debugger continuing
2022-09-15T21:30:22Z debug layer=debugger detaching
2022/09/15 21:30:22 <nil>
15 Sep 2022 21:30:22,631 [ERROR] (rapid) Init failed InvokeID= error=Runtime exited with error: exit status 1
Socket connection to remote was closed
API server listening at: [::]:5867
2022-09-15T21:30:22Z warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
2022-09-15T21:30:22Z info layer=debugger launching process with args: [/var/task/get-qrcode]
orizerah commented 1 year ago

Are there any news on this issue? I'm experiencing the same thing on my laptop...