Aws-sam-cli: sam init --runtime go1.x produces project Makefile that does not work

Created on 26 Feb 2020  路  7Comments  路  Source: aws/aws-sam-cli

I was unable to find this reported already

Description

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

Steps to reproduce

sam init --name gomakefilebug --runtime go1.x --app-template hello-world
cd gomakefilebug
make

Observed result

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$

Expected result

I would expect this to compile and be able to follow the documentation guides.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: OSX 10.14.5
  2. sam --version: SAM CLI, version 0.43.0
  3. Go 1.13.8

I believe this issue is caused because the go.mod is in the hello-world directory instead of the project's root.

arebuild areinit

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 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

All 7 comments

@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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhangzhx picture zhangzhx  路  3Comments

cvuijst picture cvuijst  路  3Comments

drumadrian picture drumadrian  路  3Comments

cmccoypdx picture cmccoypdx  路  3Comments

Caian picture Caian  路  3Comments