// GetAwsSessWithAssumeRole returns a pointer to aws session which got the credentials by assuming the given role arn.
// It also returns an error if there was any.
GetAwsSessWithAssumeRole returns a pointer to aws session which got the credentials by assuming the given role arn.
It also returns an error if there was any.
// GetAwsSessWithAssumeRole returns a pointer to aws session which got the credentials by assuming the given role arn . // It also returns an error if there was any .
func GetAwsSessWithAssumeRole(roleArn string) (*session.Session, error) {
	sessPtr, err := GetAwsSessWithDefaultCreds()
	if err != nil {
		return nil, err
	}
	svc := sts.New(sessPtr)
	callerInfo, err := GetCallerInfo(svc)
	if err != nil {
		return nil, err
	}
	clogger.Debugf("Will Assume IAM Role Using Creds Of Identity: %s", *callerInfo.Arn)
	creds := stscreds.NewCredentials(sessPtr, roleArn)
	config := aws.Config{Credentials: creds}
	newSessPtr := createSession(session.Options{Config: config})
	if _, err := newSessPtr.Config.Credentials.Get(); err != nil {
		if aerr, ok := err.(awserr.Error); ok {
			return nil, fmt.Errorf("%s: %s", aerr.Code(), aerr.Message())
		}
	}
	if ok := IsCredsExpired(svc); ok {
		return nil, fmt.Errorf("AwsAssumeRoleCredsExpired: Provided AWS Assume Role's Credentials Have Expired")
	}
	return newSessPtr, nil
}
func GetAwsSessWithAssumeRole ( roleArn string ) ( * session . Session , error ) { sessPtr , err := GetAwsSessWithDefaultCreds ( ) if err != nil { return nil , err } svc := sts . New ( sessPtr ) callerInfo , err := GetCallerInfo ( svc ) if err != nil { return nil , err } clogger . Debugf ( " " , * callerInfo . Arn ) creds := stscreds . NewCredentials ( sessPtr , roleArn ) config := aws . Config { Credentials : creds } newSessPtr := createSession ( session . Options { Config : config } ) if _ , err := newSessPtr . Config . Credentials . Get ( ) ; err != nil { if aerr , ok := err . ( awserr . Error ) ; ok { return nil , fmt . Errorf ( " " , aerr . Code ( ) , aerr . Message ( ) ) } } if ok := IsCredsExpired ( svc ) ; ok { return nil , fmt . Errorf ( " " ) } return newSessPtr , nil }
GetAwsSessWithAssumeRole returns a pointer to aws session which got the credentials by assuming the given role arn.
GetAwsSessWithAssumeRole returns a pointer to aws session which got the credentials by assuming the given role arn .