Here's the way to do it:
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)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…