【问题标题】:How to use IAM User credentials with Go AWS SDK v2如何在 Go AWS SDK v2 中使用 IAM 用户凭证
【发布时间】:2020-08-17 00:37:11
【问题描述】:

我正在动态获取 IAM 用户 凭证,并且我想使用我通过程序生成的凭证来创建会话/客户端。不是共享凭据方法。通过代码。我试过这个,我知道它不是正确的方法,它无论如何都不起作用。有人知道如何正确执行此操作吗?

    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)

【问题讨论】:

标签: amazon-web-services go sdk


【解决方案1】:

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

GetCallerIdentityRequest(&sts.GetCallerIdentityInput{})

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 2022-10-15
    • 2019-04-18
    • 1970-01-01
    • 2021-01-19
    • 2021-04-23
    相关资源
    最近更新 更多