Why am I getting this error message? I'm a beginner at using aws sam and Go.
Error: GoModulesBuilder:Build - Builder Failed: main.go:9:2: no required module provides package github.com/aws/aws-sdk-go/aws; to add it:
go get github.com/aws/aws-sdk-go/aws
main.go:10:2: no required module provides package github.com/aws/aws-sdk-go/aws/session; to add it:
go get github.com/aws/aws-sdk-go/aws/session
main.go:11:2: no required module provides package github.com/aws/aws-sdk-go/service/dynamodb; to add it:<br>
go get github.com/aws/aws-sdk-go/service/dynamodb
This is my code in vscode package main
import (
"logs"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
The issue is that AWS SAM creates a folder structure where the root of the SAM project contains the Makefile
where AWS has you build the executable, but the entry point of the application is in a sub-folder (ie the hello-world
folder).
The above two suggestions are correct, but you must run them from the same location as your main.go
and go.mod
files, not from the root folder of your SAM application.
So for anyone else learning SAM with go, try changing to the sub-folder with your go files before you run go commands.
You need to set up your Go project properly for dependency management. First follow the steps for initializing the project as described in Tutorial: Get started with Go :
go mod init YOUR_PROJECT_NAME
And then add your dependencies:
go get github.com/aws/aws-sdk-go/aws
go get github.com/aws/aws-sdk-go/service/dynamodb
If you already have go.mod file run the command below to find module for package xxx/xxx
go mod tidy
For people with this problem using AWS SAM
and vs-code
, if your folder look like this :
├── Makefile
├── README.md
├── hello-world
│ ├── go.mod
│ ├── go.sum
│ ├── main.go
│ └── main_test.go
└── template.yaml
Try to move the go.mod
and go.sum
to the root folder (where the vs-code was opened), like this:
├── Makefile
├── README.md
├── go.mod
├── go.sum
├── hello-world
│ ├── main.go
│ └── main_test.go
└── template.yaml
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.