英文:
no required module provides package github.com/aws/aws-sdk-go/aws
问题
为什么我会收到这个错误消息?我是一个使用aws sam和Go的初学者。
错误:GoModulesBuilder:Build - 构建失败:main.go:9:2:没有所需的模块提供包github.com/aws/aws-sdk-go/aws;要添加它:
go get github.com/aws/aws-sdk-go/aws
main.go:10:2:没有所需的模块提供包github.com/aws/aws-sdk-go/aws/session;要添加它:
go get github.com/aws/aws-sdk-go/aws/session
main.go:11:2:没有所需的模块提供包github.com/aws/aws-sdk-go/service/dynamodb;要添加它:
go get github.com/aws/aws-sdk-go/service/dynamodb
这是我在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"
)
英文:
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"
)
答案1
得分: 4
你需要正确设置你的Go项目以进行依赖管理。首先按照Tutorial: Get started with Go中描述的步骤初始化项目:
go mod init YOUR_PROJECT_NAME
然后添加你的依赖项:
go get github.com/aws/aws-sdk-go/aws
go get 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
答案2
得分: 3
问题在于AWS SAM创建了一个文件夹结构,其中SAM项目的根目录包含了Makefile
,AWS要求你在其中构建可执行文件,但应用程序的入口点位于子文件夹中(即hello-world
文件夹)。
你必须在与main.go
和go.mod
文件相同的位置运行go mod init
和go mod tidy
,而不是从SAM应用程序的根文件夹运行。
所以,对于其他学习SAM和Go的人来说,在运行go命令之前,尝试切换到包含Go文件的子文件夹。
英文:
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.
答案3
得分: 1
如果你已经有了 go.mod 文件,请运行下面的命令来查找包 xxx/xxx 的模块:
go mod tidy
在外部包中调用代码:
英文:
If you already have go.mod file run the command below to find module for package xxx/xxx
go mod tidy
答案4
得分: 0
对于使用AWS SAM
和vs-code
的人来说,如果你的文件夹看起来像这样:
├── Makefile
├── README.md
├── hello-world
│ ├── go.mod
│ ├── go.sum
│ ├── main.go
│ └── main_test.go
└── template.yaml
尝试将go.mod
和go.sum
移动到根文件夹(打开vs-code的文件夹),像这样:
├── Makefile
├── README.md
├── go.mod
├── go.sum
├── hello-world
│ ├── main.go
│ └── main_test.go
└── template.yaml
英文:
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
答案5
得分: 0
也许有点晚了,但我也遇到了这个问题。
我认为问题更多是出在导入路径上,
根据文档,每个子模块都在../aws-sdk-go/service/<sub-module-name>
。
但正确的路径应该是:../aws-sdk-go/aws/<sub-module-name>
注意service
应该是aws
。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论