AWS Toolkit can only debug locally on .go file in top directory
I created a simple test project with main.go under the project directory. Creating a lambda works just fine here and I can debug locally:
The lambdas displayed in the AWS Explorer window are code that is deployed into AWS and is not in this project. The code that I debug locally is a main.go in the project directory and is not deployed to AWS.
In an existing project I need to debug code locally that has the .go files several directories under the project directory:
When I try to create a new lambda on one of these .go files it fails with this error:
Building codeuri: /home/username/src/projectdir runtime: go1.x metadata: {} functions: ['Function']
Running GoModulesBuilder:Build
Build Failed
Error: GoModulesBuilder:Build - Builder Failed: no Go files in /home/username/src/projectdir
SAM Build has failed: Command did not exist successfully, exit code: 1
a-d-user-handler has failed: Command did not exist successfully, exit code: 1
AWS Toolkit is looking in the project directory for the .go files when the .go file I want to debug is several directories below the project dir. The Create New Lambda dialog doesn't give me the ability to choose which .go file I'm going to debug locally.
How do I debug locally when I have several .go files in directories below the project directory?
Please sign in to leave a comment.
I'm not the AWS Toolkit plugin maintainer/supporter, but I probably understand how to debug your Lambdas in different directories.
First off, your configuration is set up From handler (by default via gutter icons), and it uses the following sam build command:
Pay attention to the --template flag. It uses the temporary template to run your handlers. If you navigate to the template, you can see the following content:
CodeUri entry is what we need, and it uses it by default. That's why you can run/debug Lambdas inside the project root. As far as I understand, the AWS Toolkit plugin creates configuration with From handler option always with a point to the project root (CodeUri). I'm not sure that we can change it in the settings and I found the other way.
You can edit your run configuration and select From template instead of From handler.
Before that, you should create a template with the correct CodeUri path and point it to the directory with a lambda instead of a project root. You can find an example in .aws-sam/temp-template.yaml file.
I've created a small repository with an example: https://github.com/s0xzwasd/lambdas-debug
I hope it helps.