Last active
June 4, 2020 16:59
-
-
Save EduardoOliveira/56ba6f8e947736600950f656d2d71948 to your computer and use it in GitHub Desktop.
Aws Golang nested assume role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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