aws sdk for go forbidden but aws cli works fine

回眸只為那壹抹淺笑 提交于 2021-01-29 06:13:52

问题


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"),
}
  • asuming several roles in the session.NewSessionWithOptions:
AssumeRoleTokenProvider: stscreds.StdinTokenProvider

Nothing works. We always get a forbidden.


回答1:


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,
}))


来源:https://stackoverflow.com/questions/61524125/aws-sdk-for-go-forbidden-but-aws-cli-works-fine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!