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.5k stars 419 forks source link

Go: SAM: user can run/debug "nested" target=code lambdas #1724

Open justinmk3 opened 3 years ago

justinmk3 commented 3 years ago

Problem

Go support was added in Toolkit 1.25, but there is a known limitation:

If a Go handler is defined in ./foo/bar/baz.go but the manifest is defined in an ancestor directory /.foo/ , user cannot define a launch config that works.

Solution

PR: https://github.com/aws/aws-toolkit-vscode/pull/1688

  1. Introduce a handler format that encodes the path starting from projectRoot
  2. Toolkit strips the handler to something supported by sam, before invoking sam build

Status

Waiting for feedback from SAM CLI: https://github.com/aws/aws-sam-cli/issues/2844

justinmk3 commented 3 years ago

same as https://github.com/aws/aws-toolkit-vscode/issues/757 ?

JadenSimon commented 3 years ago

The issues are unrelated though the concepts are similar. This mainly is an issue with what CodeUri means. For Go templates, this must be the direct parent directory of the handler file, while for other runtimes the Handler property can be a relative path to the file, starting from CodeUri. Our code right now is fine, albeit pretty confusing. rootUri becomes projectRoot becomes codeRoot becomes CodeUri as it progresses from CodeLens -> Launch config -> Debug config -> Final template

In my opinion, CodeUri referring to the manifest file's parent directory is the correct interpretation (it should be named ProjectUri). SAM CLI just doesn't handle that use case for Go.

Astenna commented 1 year ago

I'm bumping it up, as I've just lost a couple of hours before I discovered that I need to manually adjust the projectRoot to run and debug lambda put in a subfolder.

Another unexpected behaviour that I noticed is that when:

\---WorkspaceFolder
    \---lambda
        \---handler1.go
    \---another-package
        \---function.go
    \---go.mod

then the breakpoint put in the handler1.go is not hit, whereas the breakpoint put inside the function.go works.

I am new to golang and AWS sam, so I don't know if those issues are related or not.

justinmk3 commented 1 year ago

sam cli now supports this: https://github.com/aws/aws-lambda-builders/pull/406