
[英]How can I get the credentials associated with the attached EC2 IAM role using the Java v2 SDK?
[英]How to use IAM User credentials with Go AWS SDK v2
我正在动态获取IAM User凭证,并且我想使用我使用该程序生成的凭证来创建 session/client 。 不是共享凭据方法。 通过代码。 我试过这个,我知道它不是正确的方法,它无论如何都不起作用。 任何人都知道如何正确地做到这一点?
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{})
检查他们是否还活着。 如果有人对两者都有更好的解决方案,请随时发表评论
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.