aws / aws/aws-toolkit-vscode

Debugging Lambda in VSCode dlv and sam not found (CPU: M2, Template: go 1.x image)

Open
#3,078 3 comments 0 reactions 0 assignees View on GitHub
bug language:go needs-response sam
Dominant language
TypeScript
Stars
2k
Forks
807
Avg merge
10h 12m
Merged PRs (30d)
7

Description

## Problem

## Steps to reproduce the issue

It seems like VSCode/AWS-Toolkit can't access my OS's path because it always complains that delve can't be found (even though I can access it via VSCode's and my OS' terminal) and it can't find sam either.
## Expected behavior

function is invoked and breakpoints are hit

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

- OS: Ventura 13.1 (Darwin arm64 22.2.0)
- Visual Studio Code version: 1.74.2
- AWS Toolkit version: 1.60.0
- SAM CLI version: 1.67.0

aws_toolkit logs:

```
2023-01-02 13:14:46 [VERBOSE]: SAM debug: config: "parsley:ParseCSVFunction (go1.x)"
2023-01-02 13:14:46 [INFO]: The Delve repo was not found in your GOPATH. Downloading in a temporary directory...
2023-01-02 13:14:47 [INFO]: Preparing to debug locally: Lambda "ParseCSVFunction"
2023-01-02 13:14:47 [INFO]: Building SAM application...
2023-01-02 13:14:47 [VERBOSE]: running: (not started) [/opt/homebrew/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctkCU8hzF/output --template /Users/reigun/work/repos/parsley/template.yaml]
2023-01-02 13:14:47 [INFO]: Command: (not started) [/opt/homebrew/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctkCU8hzF/output --template /Users/reigun/work/repos/parsley/template.yaml]
2023-01-02 13:14:47 [ERROR]: SamLaunchRequestError: "sam build" failed. Timed out waiting for build. [BuildFailure]
```

launch.json
```
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "parsley:ParseCSVFunction (go1.x)",
"invokeTarget": {
"target": "template",
"templatePath": "${workspaceFolder}/template.yaml",
"logicalId": "ParseCSVFunction"
},
"lambda": {
"payload": {},
"environmentVariables": {},
"runtime": "go1.x"
}
}
]
}
```

template.yaml
```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
upton

Sample SAM Template for upton

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 5
MemorySize: 128
Tracing: Active
Api:
TracingEnabled: true

Parameters:
S3BucketName:
Type: String
Description: The name of the S3 bucket in which the Swagger specification is stored
# Value: "swagger"
StageName:
Type: String
Description: The name of the stage, e.g. "dev", "preprod", "prod"
Default: dev

Resources:
# ------------------------------------------------ Lambda Function ------------------------------------------------------------------------------------
ParseCSVFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
PackageType: Image
Timeout: 300
Architectures:
# - arm64
- x86_64
Metadata:
DockerTag: go1.x-v1
DockerContext: ./parsley
Dockerfile: Dockerfile
# ------------------------------------------------ S3 ------------------------------------------------------------------------------------
S3:
Type: AWS::S3::Bucket
Properties:
BucketEncryption:
# BucketKeyEnabled: false
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: 'aws:kms'
KMSMasterKeyID: KMS-KEY-ARN
BucketName: loudnclear-stg-csv-uploads
ResourceGroup:
Type: "AWS::ResourceGroups::Group"
Properties:
Name: "ParsleyResourceGroup"
Description: "Parsley's Resource Group"
ResourceQuery:
Type: CLOUDFORMATION_STACK_1_0
ApplicationInsightsMonitoring:
Type: AWS::ApplicationInsights::Application
Properties:
ResourceGroupName: "Parsley ApplicationInsights ResourceGroup"
# !Join:
# - ''
# - - 'ApplicationInsights-SAM-'
# - !Ref: AWS::StackName
AutoConfigurationEnabled: true
DependsOn: ApplicationResourceGroup
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
ParsleyFunction:
Description: First Lambda Function ARN
Value: !GetAtt ParsleyFunction.Arn
ParsleyFunctionIamRole:
Description: Implicit IAM Role created for Hello World function
Value: !GetAtt ParsleyFunctionRole.Arn
S3Bucket:
Description: S3 Bucket to hold uploaded CSVs
Value: !GetAtt S3.BucketName
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the local debug flow with the shown launch.json and template.yaml, then inspect the AWS Toolkit logs around SAM build and Delve discovery. Check the AWS: About Toolkit details and verify whether the function is invoked and breakpoints are hit; done means debugging works for this SAM Go image configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, go, vscode
Domain
backend, cloud, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.