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.46k stars 407 forks source link

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

Open rei-gun opened 1 year ago

rei-gun commented 1 year ago

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)

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
JadenSimon commented 1 year ago

@rei-gun

This might be related to this SAM CLI issue. Could you try downgrading SAM CLI or using one of the solutions in the comments and report back? Manually changing a dependency seems like it might work if downgrading doesn't.

rei-gun commented 1 year ago

I've tried using the script here, to downgrade to 1.64.0 and 1.65.0 but both not found

reigun@ip-192-168-68-70 work % ./brewv.sh aws-sam-cli 1.65.0
fatal: --unshallow on a complete repository does not make sense
Homebrew repo already unshallowed
No version matching '1.65.0' for 'aws-sam-cli'

Previous versions of the CLI don't seem to be available in homebrew?

reigun@ip-192-168-68-70 work % brew search '/^aws-sam-cli$|^aws-sam-cli@/'
Error: No formulae or casks found for "/^aws-sam-cli$|^aws-sam-cli@/".

With regards to manually changing a dependency, which one would I change? The post you've linked talks exclusively about a Python Lambda function whereas I am using Go

justinmk3 commented 1 year ago

Architectures:

- arm64

  - x86_64

As a workaround / for troubleshooting, can you try - arm64, see https://github.com/aws/aws-toolkit-vscode/issues/1566#issuecomment-1268636183