I was unable to find this reported already
sam init --runtime=go1.x produces a make file file that does not work right out the gate which is a poor situation for developers trying to learn
sam init --name gomakefilebug --runtime go1.x --app-template hello-world
cd gomakefilebug
make
Orion:~ tbruno$ sam init --name gomakefilebug --runtime go1.x --app-template hello-world
Cloning app templates from https://github.com/awslabs/aws-sam-cli-app-templates.git
-----------------------
Generating application:
-----------------------
Name: gomakefilebug
Runtime: go1.x
Dependency Manager: mod
Application Template: hello-world
Output Directory: .
Next steps can be found in the README file at ./gomakefilebug/README.md
Orion:~ tbruno$ cd gomakefilebug/
Orion:gomakefilebug tbruno$ make
go get -u ./...
package _/Users/tbruno/gomakefilebug/hello-world: unrecognized import path "_/Users/tbruno/gomakefilebug/hello-world" (import path does not begin with hostname)
make: *** [deps] Error 1
Orion:gomakefilebug tbruno$
I would expect this to compile and be able to follow the documentation guides.
sam --version: SAM CLI, version 0.43.0I believe this issue is caused because the go.mod is in the hello-world directory instead of the project's root.
@tebruno99 You shouldn't need the makefile anymore. Since we support building Go functions now, you can use sam build instead of the makefile. We should update this though.
Thats cool, I just do teaching so we come across these issues with new developers often.
Thanks!
@jfuss Is there a way to have sam build make debug builds for go?
GOARCH=amd64 GOOS=linux go build -o <delve folder path>/dlv github.com/go-delve/delve/cmd/dlv
If the make file is changed to produce debug builds for go it could be useful as a good example for learning to debug if sam build is unable to do this yet.
@tebruno99 It is undocumented but is used by the AWS Toolkits to produce debug artifacts for Dotnetcore and for Go once they support it.
SAM_BUILD_MODE=debug sam build should do it.
Relevant code:
https://github.com/awslabs/aws-sam-cli/blob/b2c8d991d6876a8236ba3baaa13305befde86d43/samcli/commands/build/command.py#L115
https://github.com/awslabs/aws-lambda-builders/blob/develop/aws_lambda_builders/workflows/go_modules/builder.py#L50
Personally, I prefer makefile s -- would there be value in a PR with an optional makefile for go builds?
@JoelPagliuca We can totally leave the makefile but it does need an update. It was a miss when we released sam build support for Go which changed a couple things. Happy to accept a PR if you are willing to do it. sam init pulls from https://github.com/awslabs/aws-sam-cli-app-templates by default and only use the ones we package with the CLI if we cannot download the repo. So the PR should be made towards that repo first.
Thanks for the pointer @jfuss I'll see what I can do
Most helpful comment
@tebruno99 It is undocumented but is used by the AWS Toolkits to produce debug artifacts for Dotnetcore and for Go once they support it.
SAM_BUILD_MODE=debug sam buildshould do it.Relevant code:
https://github.com/awslabs/aws-sam-cli/blob/b2c8d991d6876a8236ba3baaa13305befde86d43/samcli/commands/build/command.py#L115
https://github.com/awslabs/aws-lambda-builders/blob/develop/aws_lambda_builders/workflows/go_modules/builder.py#L50