aws / aws/aws-toolkit-vscode

Unable to debug Go lambda locally: ECONNREFUSED

Open
#3,984 9 comments 0 reactions 0 assignees View on GitHub
guidance lambda language:go sam
Dominant language
TypeScript
Stars
2k
Forks
807
Avg merge
10h 12m
Merged PRs (30d)
7

Description

## System details (run the `AWS: About Toolkit` command)

- OS: Windows 11
- Visual Studio Code version: 1.83.1
- AWS Toolkit version: 1.96.0

## 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?

Contributor guide

Open the contributing guide

Research direction

Start with the launch.json configuration, the Go Lambda entry point under src/lambda/gs-1-cb-post-confirmation-handler/main.go, and test/signupConfirmEvt.json; reproduce the direct-invoke debug flow with the AWS SAM CLI and inspect the Delve and port 5866 logs. Done means the local container starts without ECONNREFUSED, VS Code attaches to Delve, and breakpoints can be hit during invocation.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, go, typescript, vscode
Domain
backend, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.