Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no required module provides package github.com/aws/aws-sdk-go/aws

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"
)
like image 217
awslearner Avatar asked Nov 04 '25 16:11

awslearner


2 Answers

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
like image 114
Gregor Zurowski Avatar answered Nov 07 '25 08:11

Gregor Zurowski


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.

like image 39
Chris Concannon Avatar answered Nov 07 '25 10:11

Chris Concannon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!