如何使用新的 AWS GO SDK-V2 担任跨账户访问角色

问题描述

在去年 12 月 24 日发布 GO SDK-v2 RC 之后,我不知道如何创建配置以在不同的 aws 帐户中担任角色。我找不到任何文档或示例,并尝试使用“config.WithAssumeRoleCredentialsOptions”或“stscreds.NewAssumeRoleProvider”,但没有任何结果。有没有人有这方面的例子或指示?

解决方法

方法如下:

ctx := context.TODO()
        cfg,err := config.LoadDefaultConfig(ctx,config.WithRegion("us-east-1"),//config.WithClientLogMode(aws.LogSigning),)
        if err != nil {
            log.Fatal(err)
        }
        stsClient := sts.NewFromConfig(cfg)
        provider := stscreds.NewAssumeRoleProvider(stsClient,roleARN)
        cfg.Credentials = aws.NewCredentialsCache(provider)
// without the following,I'm getting an error message: api error SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided.
    creds,err := cfg.Credentials.Retrieve(context.Background())
    if err != nil {
        log.Fatal(err)
    }