Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save flowerinthenight/33f5e03e9990abcc01203acbea178a1a to your computer and use it in GitHub Desktop.
Save flowerinthenight/33f5e03e9990abcc01203acbea178a1a to your computer and use it in GitHub Desktop.
ctx := context.Background()
assumecnf, _ := config.LoadDefaultConfig(
ctx, config.WithRegion("{aws-region}"),
config.WithCredentialsProvider(aws.NewCredentialsCache(
credentials.NewStaticCredentialsProvider(
"{aws-assume-role-key}",
"{aws-assume-role-secret}", "",
)),
),
)
stsclient := sts.NewFromConfig(assumecnf)
cnf, _ := config.LoadDefaultConfig(
ctx, config.WithRegion("{aws-region}"),
config.WithCredentialsProvider(aws.NewCredentialsCache(
stscredsv2.NewAssumeRoleProvider(
stsclient,
"{rolearn-to-assume}",
)),
),
)
client := s3.NewFromConfig(cnf)
res, _ := client.GetObject(ctx, &s3.GetObjectInput{
Bucket: awsv2.String("{some-bucket}"),
Key: awsv2.String("{some-key}"),
})
...
@andygeorge
Copy link

Just want to say "thank you!!!" - this was a big help (and somehow not something readily available in the AWS documentation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment