-2

我们如何在不使用会话的情况下创建 AWS 服务客户端(例如 EC2、Autoscaling),而是直接使用 sahred 凭证,就像在 boto3 中一样。

使用这样的会话有效:

sess := session.New(&aws.Config{
        Region:      aws.String("us-east-1"),
        Credentials: credentials.NewSharedCredentials("", profile),
    })
svc := ec2.New(sess)

但是,这不起作用:

svc := ec2.New(&aws.Config{
        Region:      aws.String("us-east-1"),
        Credentials: credentials.NewSharedCredentials("", profile),
    })

错误:

无法在 ec2.New 的参数中使用 aws.Config 文字(类型 *aws.Config)作为类型 client.ConfigProvider:*aws.Config 未实现 client.ConfigProvider(缺少 ClientConfig 方法)

如何在没有会话的情况下使用 Go AWS SDK 直接创建客户端?

4

1 回答 1

2

SDK 需要避免循环依赖,为此它使用了一个名为session.Session. 然而,V2通过扁平化一些包摆脱了这种抽象:)

于 2018-05-31T21:24:32.380 回答