aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.52k stars 1.17k forks source link

Sam build does not work with latest Go version (1.16) #2810

Closed hunterwerlla closed 3 years ago

hunterwerlla commented 3 years ago

Description:

Go 1.16 made changes to modules (see the section "No automatic changes to go.mod and go.sum" here https://blog.golang.org/go116-module-changes), specifically "Previously, when the go command found a problem with go.mod or go.sum like ... a missing sum, it would attempt to fix the problem automatically." Since this is no longer the case and the template does not have a go.sum by default (https://github.com/aws/aws-sam-cli-app-templates/tree/master/go1.x/cookiecutter-aws-sam-hello-golang/%7B%7Bcookiecutter.project_name%7D%7D/hello-world), sam build fails out of the box:

$ sam build
Building codeuri: /Users/werlla/sam-app/hello-world runtime: go1.x metadata: {} functions: ['HelloWorldFunction']
Running GoModulesBuilder:Build

Build Failed
Error: GoModulesBuilder:Build - Builder Failed: go: github.com/aws/aws-lambda-go@v1.13.3: missing go.sum entry; to add it:
    go mod download github.com/aws/aws-lambda-go

to fix this, go mod download github.com/aws/aws-lambda-go or similar command that creats a go.sum file must be run in the code directory (hello-world out of the box)

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

  1. OS: All
  2. sam --version: All
  3. AWS region: All

Add --debug flag to command you are running

aahung commented 3 years ago

Can you try this (from https://github.com/aws/aws-sam-cli/pull/2646)?

go env -w GOFLAGS=-mod=mod
hunterwerlla commented 3 years ago

I could and I could also run go mod tidy, but I expect it to work out of the box with no changes

jfuss commented 3 years ago

This was fixed in https://github.com/aws/aws-sam-cli-app-templates/pull/99 and is now live.

Closing