Go 1.11 introduced preliminary support for modules, enabling users to create applications outside of GOPATH and integrating support for versioning and package distribution. The default AWS Lambda function created by the AWS SAM CLI does not include module support, but it is simple to add.
In a terminal window, change directory to the root of your SAM app, e.g., sam-app, and copy and paste the following text:
go mod init github.com/aws-samples/golang-workshopYou do not need to do this inside each separate Lambda function, only once at the top of the SAM application where your template.yaml file is located.
This will create the go.mod file for you with your module name, go version, and required packages.
Next paste the following into the same terminal window:
make depsThis downloads all of your dependencies and creates the go.sum file as outlined in the Go documentation.
The Makefile target deps created by SAM CLI works for both GOPATH and Go modules without modification.