gpt4 book ai didi

amazon-web-services - 如何在Go AWS SDK v2中使用IAM用户凭证

转载 作者:行者123 更新时间:2023-12-01 22:36:34 25 4
gpt4 key购买 nike

我正在动态获取 IAM用户凭据,并且要获取,我希望使用通过程序生成的凭据来创建 session /客户端。不是共享凭据方法。通过代码。我尝试了此方法,但我知道它的方法不正确,但还是无法正常工作。任何人都知道如何正确执行此操作吗?

    staticCred := aws.NewStaticCredentialsProvider(accessKey, secretKey, "")
cfg, err := external.LoadDefaultAWSConfig()
if err != nil {
panic("unable to load SDK config, " + err.Error())
}
cfg.Credentials = staticCred
cfg.Region = aws.String("ap-southeast-1")
fmt.Println(cfg)

svc := ssm.New(cfg)

req := svc.StartSessionRequest(&ssm.StartSessionInput{
Target: aws.String(instanceId),
})
fmt.Println(req)

resp, _ := req.Send(context.Background())
if err != nil {
log.Fatalf("error sending ssm request : %v", err)
}
fmt.Println(resp)

最佳答案

您必须等待一段时间,直到凭据真正起作用。我正在使用 Hashicorp Vault 来制作凭据。
我正在使用

GetCallerIdentityRequest(&sts.GetCallerIdentityInput {})

检查他们是否还活着。
如果任何人都有更好的解决方案,请随时发表评论

关于amazon-web-services - 如何在Go AWS SDK v2中使用IAM用户凭证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61560828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com