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"
)
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With