Skip to content

Instantly share code, notes, and snippets.

@EduardoOliveira
Last active June 4, 2020 16:59
Show Gist options
  • Save EduardoOliveira/56ba6f8e947736600950f656d2d71948 to your computer and use it in GitHub Desktop.
Save EduardoOliveira/56ba6f8e947736600950f656d2d71948 to your computer and use it in GitHub Desktop.
Aws Golang nested assume role
func main(){
sess, err := session.NewSessionWithOptions(session.Options{
Profile: "name",
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
log.Println(err)
}
c := stscreds.NewCredentials(sess, "arn:aws:iam::xxxx:role/final_role", func(a *stscreds.AssumeRoleProvider) {
a.Client.AssumeRole(&sts.AssumeRoleInput{RoleArn: aws.String("arn:aws:iam::xxx:role/intermidiate_role")})
})
svc := iam.New(sess, &aws.Config{
Credentials: c,
})
result, err := svc.ListUsers(&iam.ListUsersInput{})
if err != nil {
log.Println("error listing users", err)
}
log.Println("result", result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment