Golang Debugger for Lambdas throws "Failed to install Delve for lambda container"
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 807
- Avg merge
- 10h 12m
- Merged PRs (30d)
- 7
Description
## Problem
I am trying to locally debug a golang-based lambda. As I press the Run/Start Debugging menu, nothing happens for a while then a message pops up stating "Failed to install Delve for the lambda container."
I can start dlv from the command line.
This also works:
sam local start-api --invoke-image artifactory.mydomain/sam/build-go1.x
## Steps to reproduce the issue
1. Go to Run/Start Debugging menu,
2. Click on 'Start Debugging'
3. See error above
## Expected behavior
The lambda should load and the breakpoints in code should be active.
## System details
OS: Darwin arm64 22.6.0
Visual Studio Code extension host: 1.84.2
AWS Toolkit: 2.2.0
node: 18.15.0
electron: 25.9.2
GO111MODULE=''
GOARCH='arm64'
GOBIN='/Users/myuser/go/bin'
GOCACHE='/Users/myuser/Library/Caches/go-build'
GOENV='/Users/myuser/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/myuser/go/pkg/mod'
GONOPROXY='\*.mydomain'
GONOSUMDB='\*.mydomain'
GOOS='darwin'
GOPATH='/Users/myuser'
GOPRIVATE='\*.mydomain'
GOPROXY='https://artifactory.mydomain/go/go-shared'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK='/Users/myuser/repos/myrepo/golang-go-al2/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/mf/6rd4nk591kz7d2qyjxydnm4h0000gp/T/go-build320416223=/tmp/go-build -gno-record-gcc-switches -fno-common'
### template.yaml:
```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
go-go1.x
Sample SAM Template for go-go1.x
Globals:
Function:
Timeout: 5
Resources:
S3ReadFileFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3-read-file/
Handler: bootstrap
Runtime: go1.x
Tracing: Active
Events:
CatchAll:
Type: Api
Properties:
Path: /get-file
Method: GET
Environment:
Variables:
PARAM1: VALUE
Architectures:
- arm64
Metadata:
BuildMethod: makefile
Outputs:
S3ReadFileAPI:
Description: "API Gateway endpoint URL for Prod environment for First Function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/get-file/"
S3ReadFileFunction:
Description: "First Lambda Function ARN"
Value: !GetAtt S3ReadFileFunction.Arn
S3ReadFileFunctionIamRole:
Description: "Implicit IAM Role created forS3ReadFile function"
Value: !GetAtt S3ReadFileFunctionRole.Arn
```
### launch.json:
```
{
"version": "0.2.0",
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "API go1.x:S3ReadFileFunction",
"invokeTarget": {
"target": "api",
"templatePath": "${workspaceFolder}/template.yaml",
"logicalId": "S3ReadFileFunction"
},
"api": {
"path": "/",
"httpMethod": "get",
"payload": {
"json": {}
}
},
"lambda": {
"runtime": "go1.x"
}
}
]
}
```
### Logs:
```
023-12-08 16:25:10 [INFO]: CloudFormationTemplateRegistry: building with: Watching **/*.{yaml,yml}, Untitled Files, Excluding /.*devfile\.(yaml|yml)/i, /.*[/\\]\.aws-sam([/\\].*|$)/
2023-12-08 16:25:10 [INFO]: CloudFormationTemplateRegistry: processed 1 items
2023-12-08 16:25:11 [INFO]: SAM CLI location (version: 1.97.0): /usr/local/bin/sam
2023-12-08 16:26:17 [INFO]: The Delve repo was not found in your GOPATH. Downloading in a temporary directory...
2023-12-08 16:26:18 [INFO]: Command: (not started) [/Users/myuser/Library/Application Support/Code/User/globalStorage/amazonwebservices.aws-toolkit-vscode/debuggers/delve/install-1.21.1.sh ]
2023-12-08 16:26:20 [ERROR]: [Delve install script] -> # runtime/cgo
linux_syscall.c:67:13: error: call to undeclared function 'setresgid'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
linux_syscall.c:67:13: note: did you mean 'setregid'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:593:6: note: 'setregid' declared here
linux_syscall.c:73:13: error: call to undeclared function 'setresuid'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
linux_syscall.c:73:13: note: did you mean 'setreuid'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:595:6: note: 'setreuid' declared here
2023-12-08 16:26:20 [ERROR]: Failed to cross-compile Delve debugger: 'Error: Install script did not generate the Delve binary: exit code 1'
2023-12-08 16:26:20 [ERROR]: SamLaunchRequestError: Failed to install Delve for the lambda container. [NoDelveInstallation]
```
Contributor guide
Research direction
Start with the launch.json and template.yaml configuration, then reproduce the Run/Start Debugging flow and inspect the Delve install script output in the logs. Investigate the cross-compilation failure involving setresgid and setresuid on Darwin arm64. Done means Delve installs successfully for the Lambda container, the function loads, and breakpoints become active.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, go, vscode
- Domain
- cloud, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100