Reputation: 45
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"
)
Upvotes: 3
Views: 6675
Reputation: 495
maybe late to the party, but kind of encounter this problem also.
I believe the problem more on the import path,
from the documentation every submodule is on ../aws-sdk-go/service/<sub-module-name
.
But the right one should be: ../aws-sdk-go/aws/<sub-module-name
notice the aws
instead service
Upvotes: 0
Reputation: 443
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 (i.e. the hello-world
folder).
You must run go mod init
and go mod tidy
from the same location as the 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.
Upvotes: 3
Reputation: 654
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
Upvotes: 0
Reputation: 1117
If you already have go.mod file run the command below to find module for package xxx/xxx
go mod tidy
Call code in an external package
Upvotes: 1
Reputation: 2346
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
Upvotes: 4