禁止使用aws sdk,但aws cli可以正常工作 [英] aws sdk for go forbidden but aws cli works fine
问题描述
我们正在使用aws cli,它可以完美工作,我们可以创建taskdefinitions,创建服务等.当我们想使用sdk进行操作时,问题就来了.我们总是被禁止的.我们试图使用一个新的空会话,一个指定区域的会话,假设角色……没有任何效果.有谁知道我们该怎么解决?
We are using aws cli and it works perfectly, we can create taskdefinitions, create services, etc. The problem comes when we want to use the sdk for go. We always get a forbidden. We have tried to use a new empty session, a session specifying the region, asuming roles... nothing works. Does anyone know how we could solve it?
我们尝试了很多事情:-在创建新会话时设置新配置:
We have tried many things: - setting a new config when creating a new session:
Config: aws.Config{
CredentialsChainVerboseErrors: aws.Bool(true),
Credentials: credentials.NewEnvCredentials(),
Region: aws.String("eu-west-1"),
}
- 在会话中担任多个角色.NewSessionWithOptions:
AssumeRoleTokenProvider: stscreds.StdinTokenProvider
没有任何效果.我们总是被禁止的.
Nothing works. We always get a forbidden.
推荐答案
默认情况下,cli使用〜/.aws/credentials中的凭据,以及〜/.aws/config中的区域.尝试以下操作创建会话:
By default the cli uses your credentials from ~/.aws/credentials and region from ~/.aws/config. Try this to create your session:
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
这篇关于禁止使用aws sdk,但aws cli可以正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!