aws / aws-toolkit-vscode

Amazon Q, CodeCatalyst, Local Lambda debug, SAM/CFN syntax, ECS Terminal, AWS resources
https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.amazon-q-vscode
Apache License 2.0
1.49k stars 417 forks source link

Unable to debug Go lambda locally: ECONNREFUSED #3984

Open TBruines opened 11 months ago

TBruines commented 11 months ago

System details (run the AWS: About Toolkit command)

Question

Hi!

I'm trying to debug a Go lambda function locally, and am able to invoke it via the CLI but would like to step-through-debug. My vscode launch.json to achieve this looks as follows:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Invoke post-confirmation-handler",
            "type": "aws-sam",
            "request": "direct-invoke",
            "sam": {
                "localArguments": ["--debug"]
            },
            "invokeTarget": {
                "target": "code",
                "projectRoot": "${workspaceFolder}/src/lambda/gs-1-cb-post-confirmation-handler",
                "lambdaHandler": "gs-1-cb-post-confirmation-handler"
            },
            "lambda": {
                "runtime": "go1.x",
                "payload": {
                    "path": "${workspaceFolder}/src/lambda/gs-1-cb-post-confirmation-handler/test/signupConfirmEvt.json"
                },
                "environmentVariables": {
                    "LOOKUP_TABLE_NAME": "LookupTable"
                }
            }
        }
    ],
}

My project is a cdk project and roughly looks like this:

src
--- appsync
--- lambda
-------gs-1-post-confirmation-handler
-----------go.mod
-----------go.sum
-----------main.go
-----------test
...
cdk.json

However, when running from the vscode debug panel I get a popup saying "Error: connect ECONNREFUSED::1::5866" and the following logs:

2023-11-01 10:36:03 [INFO]: The Delve repo was not found in your GOPATH. Downloading in a temporary directory...
2023-11-01 10:36:04 [INFO]: Preparing to debug locally: Lambda "gs-1-cb-post-confirmation-handler"
2023-11-01 10:36:04 [INFO]: Building SAM application...
2023-11-01 10:36:04 [INFO]: Command: (not started) [C:\Program Files\Amazon\AWSSAMCLI\bin\sam.cmd build --build-dir C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkWNNu5V\output --template C:/Users/TBrui/AppData/Local/Temp/aws-toolkit-vscode/vsctkWNNu5V/app___vsctk___template.yaml --base-dir C:/Users/TBrui/source/SEN-GS-1-CB-Trendi-Data-Hub/src/lambda/gs-1-cb-post-confirmation-handler]
2023-11-01 10:36:08 [INFO]: Building codeuri: C:/Users/TBrui/source/SEN-GS-1-CB-Trendi-Data-Hub/src/lambda/gs-1-cb-post-confirmation-handler runtime: go1.x metadata: {} architecture: x86_64 functions: gs1cbpostconfirmationhandler

2023-11-01 10:36:08 [INFO]:  Running GoModulesBuilder:Build

2023-11-01 10:36:10 [INFO]: 
Build Succeeded

2023-11-01 10:36:10 [INFO]: 
Built Artifacts  : output
Built Template   : output\template.yaml
2023-11-01 10:36:11 [INFO]: Build complete.
2023-11-01 10:36:11 [INFO]: Starting SAM application locally
2023-11-01 10:36:11 [INFO]: AWS.running.command
2023-11-01 10:36:14,513 | No config file found in this directory.
2023-11-01 10:36:14,513 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: 'C:\\Users\\TBrui\\AppData\\Local\\Temp\\aws-toolkit-vscode\\vsctkWNNu5V\\output\\samconfig.toml'
2023-11-01 10:36:14,513 | Config file location: C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkWNNu5V\output\samconfig.toml
2023-11-01 10:36:14,513 | Config file 'C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkWNNu5V\output\samconfig.toml' does not exist
2023-11-01 10:36:14,549 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: 'C:\\Users\\TBrui\\AppData\\Local\\Temp\\aws-toolkit-vscode\\vsctkWNNu5V\\output\\samconfig.toml'
2023-11-01 10:36:14,549 | Using config file: samconfig.toml, config environment: default
2023-11-01 10:36:14,549 | Expand command line arguments to:
2023-11-01 10:36:14,549 | --template_file=C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkWNNu5V\output\template.yaml --event=C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkWNNu5V\event.json --env_vars=C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkWNNu5V\env-vars.json --debug_port=(5866,) --debugger_path=c:\Users\TBrui\AppData\Roaming\Code\User\globalStorage\amazonwebservices.aws-toolkit-vscode\debuggers\delve --debug_args=-delveAPI=2 --function_logical_id=gs1cbpostconfirmationhandler --no_event --layer_cache_basedir=C:\Users\TBrui\AppData\Roaming\AWS SAM\layers-pkg --container_host=localhost --container_host_interface=127.0.0.1 
2023-11-01 10:36:14,549 | local invoke command is called
2023-11-01 10:36:14,553 | No Parameters detected in the template
2023-11-01 10:36:14,597 | Sam customer defined id is more priority than other IDs. Customer defined id for resource gs1cbpostconfirmationhandler is gs1cbpostconfirmationhandler
2023-11-01 10:36:14,597 | 0 stacks found in the template
2023-11-01 10:36:14,597 | No Parameters detected in the template
2023-11-01 10:36:14,627 | Sam customer defined id is more priority than other IDs. Customer defined id for resource gs1cbpostconfirmationhandler is gs1cbpostconfirmationhandler
2023-11-01 10:36:14,627 | 1 resources found in the stack 
2023-11-01 10:36:14,627 | Found Serverless function with name='gs1cbpostconfirmationhandler' and CodeUri='gs1cbpostconfirmationhandler'
2023-11-01 10:36:14,627 | --base-dir is not presented, adjusting uri gs1cbpostconfirmationhandler relative to C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkWNNu5V\output\template.yaml
2023-11-01 10:36:14,643 | Found one Lambda function with name 'gs1cbpostconfirmationhandler'
2023-11-01 10:36:14,643 | Invoking gs-1-cb-post-confirmation-handler (go1.x)
2023-11-01 10:36:14,643 | Environment variables data found for specific function in standard format
2023-11-01 10:36:14,644 | Loading AWS credentials from session with profile 'None'
2023-11-01 10:36:14,661 | Resolving code path. Cwd=C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkWNNu5V\output, CodeUri=C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkWNNu5V\output\gs1cbpostconfirmationhandler
2023-11-01 10:36:14,661 | Resolved absolute path to code is C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkWNNu5V\output\gs1cbpostconfirmationhandler
2023-11-01 10:36:14,661 | Code C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkWNNu5V\output\gs1cbpostconfirmationhandler is not a zip/jar file
2023-11-01 10:36:14,661 | Falling back to a previous version of the emulation image
2023-11-01 10:36:16,736 | Local image is up-to-date
2023-11-01 10:36:16,753 | Using local image: public.ecr.aws/lambda/go:1-rapid-x86_64.

2023-11-01 10:36:16,754 | Mounting C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkWNNu5V\output\gs1cbpostconfirmationhandler as /var/task:ro,delegated, inside runtime container
2023-11-01 10:36:18,172 | Setting up SIGTERM interrupt handler
START RequestId: 31b035ad-7535-4715-9522-0285053827dd Version: $LATEST
API server listening at: [::]:5866
2023-11-01T09:36:19Z warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
2023-11-01T09:36:19Z info layer=debugger launching process with args: [/var/task/gs-1-cb-post-confirmation-handler]
2023-11-01 10:36:19 [INFO]: Waiting for SAM application to start...
2023-11-01T09:36:20Z debug layer=debugger Adding target 31 "/var/task/gs-1-cb-post-confirmation-handler"
2023-11-01 10:36:20 [INFO]: Attaching debugger to SAM application...

It seems the docker container is not running properly, but I cannot find where the failure is. Anyone got any insight?

justinmk3 commented 11 months ago

My vscode task.json to achieve this looks as follows:

I assume you mean launch.json , right?

"localArguments": ["--debug"] should not be necessary and may actually cause problems.

Can you try "target": "template"? The AWS: Edit SAM Debug Configuration command is also a convenient way to run/debug without creating a launch config.

TBruines commented 11 months ago

Hi Justin, thanks for your reply! It was launch.json indeed.

I tried your suggestion (copied the function id from the cdk.out/XXX.template.json), but before building I get the following message:

2023-11-01 16:20:55 [ERROR]: SamLaunchRequestError: Invalid launch configuration: Template Resource PostConfirmationHandler8951DF10 in Template file c:\Users\TBrui\source\SEN-GS-1-CB-Trendi-Data-Hub\cdk.out\GS-1-CB-dev-AdminStack.template.json needs to be of type AWS::Serverless::Function or AWS::Lambda::Function [BadLaunchConfig]

While it is clearly an AWS::Lambda::Function:

  "PostConfirmationHandler8951DF10": {
   "Type": "AWS::Lambda::Function",
   "Properties": {
    "Code": {
     "S3Bucket": {
      "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
     },
     "S3Key": "5b11f1fa8ff425abd8ace2a85017a37f2f3ece348bd3a922e6d1710e1efaa857.zip"
    },
...

However I made some progress on another front: by changing the direct code launch task property "lambdaHandler" from the function workspace folder to 'bootstrap' as it is in the CDK template:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Invoke post-confirmation-handler",
            "type": "aws-sam",
            "request": "direct-invoke",
            // "sam": {
            //     "localArguments": ["--debug"]
            // },
            "invokeTarget": {
                "target": "code",
                "projectRoot": "${workspaceFolder}/src/lambda/gs-1-cb-post-confirmation-handler",
                **"lambdaHandler": "bootstrap"**
            },
            // "invokeTarget": {
            //     "target": "template",
            //     "logicalId": "PostConfirmationHandler8951DF10",
            //     "templatePath": "./cdk.out/GS-1-CB-dev-AdminStack.template.json"
            // },
            "lambda": {
                "timeoutSec": 30,
                "runtime": "go1.x",
                "payload": {
                    "path": "${workspaceFolder}/src/lambda/gs-1-cb-post-confirmation-handler/test/signupConfirmEvt.json"
                },
                "environmentVariables": {
                    "LOOKUP_TABLE_NAME": "LookupTable"
                }
            }
        }
    ],
}

it now seems to fully execute the function where it didn't before. However the debugger still does not attach. (Note: the 'PutItem returned an error..' message is expected behaviour at this point)

2023-11-01 16:27:36 [INFO]: The Delve repo was not found in your GOPATH. Downloading in a temporary directory...
2023-11-01 16:27:37 [INFO]: Preparing to debug locally: Lambda "bootstrap"
2023-11-01 16:27:37 [INFO]: Building SAM application...
2023-11-01 16:27:37 [INFO]: Command: (not started) [C:\Program Files\Amazon\AWSSAMCLI\bin\sam.cmd build --build-dir C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkNFgTcx\output --template C:/Users/TBrui/AppData/Local/Temp/aws-toolkit-vscode/vsctkNFgTcx/app___vsctk___template.yaml --base-dir C:/Users/TBrui/source/SEN-GS-1-CB-Trendi-Data-Hub/src/lambda/gs-1-cb-post-confirmation-handler]
2023-11-01 16:27:40 [INFO]: Building codeuri: C:/Users/TBrui/source/SEN-GS-1-CB-Trendi-Data-Hub/src/lambda/gs-1-cb-post-confirmation-handler runtime: go1.x metadata: {} architecture: x86_64 functions: gs1cbpostconfirmationhandler

2023-11-01 16:27:40 [INFO]:  Running GoModulesBuilder:Build

2023-11-01 16:27:42 [INFO]: 
Build Succeeded

2023-11-01 16:27:42 [INFO]: 
Built Artifacts  : output
Built Template   : output\template.yaml

Commands you can use next
=========================
[*] Validate SAM template: sam validate

[*] Invoke Function: sam local invoke -t output\template.yaml

[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch

[*] Deploy: sam deploy --guided --template-file output\template.yaml

2023-11-01 16:27:42 [INFO]: Build complete.
2023-11-01 16:27:42 [INFO]: Starting SAM application locally
2023-11-01 16:27:42 [INFO]: AWS.running.command
Invoking bootstrap (go1.x)
Falling back to a previous version of the emulation image
Local image is up-to-date
Using local image: public.ecr.aws/lambda/go:1-rapid-x86_64.

Mounting C:\Users\TBrui\AppData\Local\Temp\aws-toolkit-vscode\vsctkNFgTcx\output\gs1cbpostconfirmationhandler as /var/task:ro,delegated, inside runtime container
START RequestId: 14cee6c3-0a3b-41e0-837d-81b56b8cb379 Version: $LATEST
2023/11/01 15:27:51 PutItem returned an error: ResourceNotFoundException: Requested resource not found
END RequestId: 14cee6c3-0a3b-41e0-837d-81b56b8cb379
REPORT RequestId: 14cee6c3-0a3b-41e0-837d-81b56b8cb379  Init Duration: 0.17 ms  Duration: 554.02 ms Billed Duration: 555 ms Memory Size: 128 MB Max Memory Used: 128 MB 

Command stopped: "sam local invoke"
2023-11-01 16:27:53 [INFO]: Waiting for SAM application to start...
2023-11-01 16:27:54 [INFO]: Attaching debugger to SAM application...
TBruines commented 11 months ago

Another small update, I got the build working with the template invokeTarget and a specific template.yaml for the function. However the debugger is still not attaching (function is running to completion though)

justinmk3 commented 9 months ago

@TBruines do you see any improvement here with the latest sam cli (1.105+) and the latest AWS Toolkit (2.3.0)?

justinmk3 commented 8 months ago

I tried your suggestion (copied the function id from the cdk.out/XXX.template.json), but before building I get the following message:

2023-11-01 16:20:55 [ERROR]: SamLaunchRequestError: Invalid launch configuration: Template Resource PostConfirmationHandler8951DF10 in Template file c:\Users\TBrui\source\SEN-GS-1-CB-Trendi-Data-Hub\cdk.out\GS-1-CB-dev-AdminStack.template.json needs to be of type AWS::Serverless::Function or AWS::Lambda::Function [BadLaunchConfig]

While it is clearly an AWS::Lambda::Function:

That error message was indeed a bug, fixed by https://github.com/aws/aws-toolkit-vscode/pull/4282 . This fix will be included in AWS Toolkit 2.6.0

TBruines commented 5 months ago

Hi Justin, my apologies for the late reply, but I am still experiencing the same issue. SAM is running the function correctly but only tries to attach the debugger after it has finished running, giving an EConnRefused error.

2024-04-29 18:32:24.735 [info] The Delve repo was not found in your GOPATH. Downloading in a temporary directory...
2024-04-29 18:32:24.738 [info] Preparing to debug locally: Lambda "bootstrap"
2024-04-29 18:32:24.738 [info] Building SAM application...
2024-04-29 18:32:24.754 [info] Command: (not started) [C:\Program Files\Amazon\AWSSAMCLI\bin\sam.cmd build --build-dir [Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output --template [Users]/source/SEN-GS-1-CB-Trendi-Data-Hub/src/lambda/gs-1-cb-data-crawler/template.yaml]
2024-04-29 18:32:27.651 [info] Building codeuri: [Users]\source\SEN-GS-1-CB-Trendi-Data-Hub\src\lambda\gs-1-cb-data-crawler\     runtime: go1.x metadata: {} architecture: x86_64 functions: gs1cbdatacrawler
2024-04-29 18:32:27.763 [info] Workflow GoModulesBuilder does not support value "False" for building in source. Using default value "True".
2024-04-29 18:32:27.830 [info] Running GoModulesBuilder:Build
2024-04-29 18:32:29.180 [info] Build Succeeded
2024-04-29 18:32:29.184 [info] Built Artifacts  : ..\..\..\..\..\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output
Built Template   : ..\..\..\..\..\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\template.yaml

Commands you can use next
=========================
[*] Validate SAM template: sam validate

[*] Invoke Function: sam local invoke -t ..\..\..\..\..\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\template.yaml

[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch

[*] Deploy: sam deploy --guided --template-file ..\..\..\..\..\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\template.yaml
2024-04-29 18:32:29.335 [info] Build complete.
2024-04-29 18:32:29.335 [info] Starting SAM application locally
2024-04-29 18:32:29.345 [info] AWS.running.command
2024-04-29 18:32:32.035 [info] 2024-04-29 18:32:32,033 | No config file found in this directory.
2024-04-29 18:32:32.035 [info] 2024-04-29 18:32:32,034 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: 'C:\\Users\\TBrui\\AppData\\Local\\Temp\\aws-toolkit-vscode\\vsctka962e7c4\\output\\samconfig.toml'
2024-04-29 18:32:32,034 | Config file location: [Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\samconfig.toml
2024-04-29 18:32:32,034 | Config file '[Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\samconfig.toml' does not exist
2024-04-29 18:32:32.059 [info] 2024-04-29 18:32:32,059 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: 'C:\\Users\\TBrui\\AppData\\Local\\Temp\\aws-toolkit-vscode\\vsctka962e7c4\\output\\samconfig.toml'
2024-04-29 18:32:32.060 [info] 2024-04-29 18:32:32,059 | Using config file: samconfig.toml, config environment: default
2024-04-29 18:32:32,059 | Expand command line arguments to:
2024-04-29 18:32:32,059 | --template_file=[Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\template.yaml --event=[Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\event.json --env_vars=[Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\env-vars.json --debug_port=(5862,) --debugger_path=[Users]\AppData\Roaming\Code\User\globalStorage\amazonwebservices.aws-toolkit-vscode\debuggers\delve --debug_args=-delveAPI=2 --function_logical_id=gs1cbdatacrawler --no_event --layer_cache_basedir=[Users]\AppData\Roaming\AWS SAM\layers-pkg --container_host=localhost --container_host_interface=127.0.0.1 
2024-04-29 18:32:32,059 | local invoke command is called
2024-04-29 18:32:32.063 [info] 2024-04-29 18:32:32,062 | No Parameters detected in the template
2024-04-29 18:32:32.098 [info] 2024-04-29 18:32:32,096 | Sam customer defined id is more priority than other IDs. Customer defined id for resource gs1cbdatacrawler is gs1cbdatacrawler
2024-04-29 18:32:32.099 [info] 2024-04-29 18:32:32,097 | 0 stacks found in the template
2024-04-29 18:32:32,097 | No Parameters detected in the template
2024-04-29 18:32:32.121 [info] 2024-04-29 18:32:32,119 | Sam customer defined id is more priority than other IDs. Customer defined id for resource gs1cbdatacrawler is gs1cbdatacrawler
2024-04-29 18:32:32.122 [info] 2024-04-29 18:32:32,120 | 1 resources found in the stack 
2024-04-29 18:32:32,120 | Found Serverless function with name='gs1cbdatacrawler' and CodeUri='gs1cbdatacrawler'
2024-04-29 18:32:32,120 | --base-dir is not presented, adjusting uri gs1cbdatacrawler relative to [Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\template.yaml
2024-04-29 18:32:32.139 [info] 2024-04-29 18:32:32,138 | Found one Lambda function with name 'gs1cbdatacrawler'
2024-04-29 18:32:32,138 | Invoking bootstrap (go1.x)
2024-04-29 18:32:32.139 [info] 2024-04-29 18:32:32,138 | Environment variables data found for specific function in standard format
2024-04-29 18:32:32,138 | Loading AWS credentials from session with profile 'None'
2024-04-29 18:32:32.155 [info] 2024-04-29 18:32:32,154 | Resolving code path. Cwd=[Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output, CodeUri=[Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\gs1cbdatacrawler
2024-04-29 18:32:32,154 | Resolved absolute path to code is [Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\gs1cbdatacrawler
2024-04-29 18:32:32,154 | Resolving code path. Cwd=[Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output, CodeUri=[Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\gs1cbdatacrawler
2024-04-29 18:32:32,154 | Resolved real code path to [Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\gs1cbdatacrawler
2024-04-29 18:32:32.155 [info] 2024-04-29 18:32:32,154 | Code [Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\gs1cbdatacrawler is not a zip/jar file
2024-04-29 18:32:32,155 | Falling back to a previous version of the emulation image
2024-04-29 18:32:34.286 [info] 2024-04-29 18:32:34,286 | Local image is up-to-date
2024-04-29 18:32:34.297 [info] 2024-04-29 18:32:34,296 | Checking free port on 127.0.0.1:8486
2024-04-29 18:32:34.303 [info] 2024-04-29 18:32:34,302 | Using local image: public.ecr.aws/lambda/go:1-rapid-x86_64.
2024-04-29 18:32:34.304 [info] 2024-04-29 18:32:34,302 | Mounting [Users]\AppData\Local\Temp\aws-toolkit-vscode\vsctka962e7c4\output\gs1cbdatacrawler as /var/task:ro,delegated, inside runtime container
2024-04-29 18:32:34.769 [info] 2024-04-29 18:32:34,767 | Setting up SIGTERM interrupt handler
2024-04-29 18:32:35.292 [info] 2024-04-29 18:32:35,292 | Getting lock for the key localhost-8486
2024-04-29 18:32:35.293 [info] 2024-04-29 18:32:35,292 | Waiting to retrieve the lock (localhost-8486) to start invocation
2024-04-29 18:32:36.310 [info] START RequestId: 9bcadc9f-0b98-4143-944c-31ee27f4f90d Version: $LATEST
2024-04-29 18:32:46.625 [info] Received 3 deleted records
2024-04-29 18:32:46.627 [info] END RequestId: 9bcadc9f-0b98-4143-944c-31ee27f4f90d
REPORT RequestId: 9bcadc9f-0b98-4143-944c-31ee27f4f90d  Init Duration: 0.33 ms  Duration: 10315.47 ms   Billed Duration: 10316 ms   Memory Size: 1024 MB    Max Memory Used: 1024 MB
2024-04-29 18:32:46.629 [info] 
2024-04-29 18:32:46.629 [info] null
2024-04-29 18:32:46.637 [info] 2024-04-29 18:32:46,635 | [Container state] OOMKilled False
2024-04-29 18:32:47.052 [info] 2024-04-29 18:32:47,051 | Cleaning all decompressed code dirs
2024-04-29 18:32:47.054 [info] 2024-04-29 18:32:47,052 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-04-29 18:32:47.055 [info] 2024-04-29 18:32:47,053 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-04-29 18:32:47,054 | Unable to find Click Context for getting session_id.
2024-04-29 18:32:47.057 [info] 2024-04-29 18:32:47,056 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-04-29 18:32:47.191 [info] 
2024-04-29 18:32:47.192 [info] Command stopped: "sam local invoke"
2024-04-29 18:32:47.193 [info] Waiting for SAM application to start...
2024-04-29 18:32:48.203 [info] Attaching debugger to SAM application...

Would help us greatly if we could get local debugging to work.

justinmk3 commented 5 months ago

Those logs don't show SamLaunchRequestError, so that confirms at least that issue is resolved.

SAM is running the function correctly but only tries to attach the debugger after it has finished running, giving an EConnRefused error.

Possibly sam isn't waiting for Toolkit to connect. Or possibly Toolkit needs to send some sort of option.

Go is not well-supported by AWS Toolkit sam debugging, currently. It may be worth trying to get it working with sam cli + a hand-crafted vscode launch config. That would then confirm that this is a Toolkit bug.

TBruines commented 5 months ago

Hi Justin,

I have finally managed to get it working by running sam local start-lambda -d 5986 --debugger-path C:/Users/TBrui/go/bin/linux_amd64 --debug-args=-delveAPI=2 in a folder with a SAM yaml template, and then invoking the function via aws lambda invoke --function-name Gs1CbDatacrawler --endpoint "http://127.0.0.1:3001" --payload fileb://src/lambda/gs-1-cb-data-crawler/events/DynamoDbUpdate.json response.json.

The local API will then wait for the debugger to attach, which I do with a simple go attach task in launch.json.

Before attaching, the local API shows exactly the same output as the SAM local invoke did. This leads me to conclude that the SAM local invoke command does not complete before the lambda has finished handling the request, and thus does not allow vscode to move from a pre-launch task into the main debug config in launch.json.

Let me know if you want my feedback if/when you develop more on the Go debugging functionality of the toolkit :)

justinmk3 commented 5 months ago

Thanks! That narrows down the circumstances.