Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws): always session from externalcreds #464

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 2 additions & 28 deletions aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -1686,12 +1686,7 @@ func GetAllResources(targetRegions []string, excludeAfter time.Time, resourceTyp
logging.Logger.Debugf("Checking region [%d/%d]: %s", count, totalRegions, GlobalRegion)

// As there is no actual region named global we have to pick a valid one just to create the session
sessionRegion := defaultRegion
session, err := newAWSSession(sessionRegion)
if err != nil {
return nil, err
}

session := newSession(defaultRegion)
globalResources := AwsRegionResource{}

// IAM Users
Expand Down Expand Up @@ -2003,16 +1998,7 @@ func NukeAllResources(account *AwsAccountResources, regions []string) error {
}, map[string]interface{}{
"region": region,
})
session, err := newAWSSession(sessionRegion)
if err != nil {
telemetry.TrackEvent(commonTelemetry.EventContext{
EventName: "Error creating session",
}, map[string]interface{}{
"region": region,
"sessionRegion": sessionRegion,
})
return err
}
session := newSession(sessionRegion)
telemetry.TrackEvent(commonTelemetry.EventContext{
EventName: "Nuking Region",
}, map[string]interface{}{
Expand All @@ -2034,15 +2020,3 @@ func NukeAllResources(account *AwsAccountResources, regions []string) error {

return nil
}

func newAWSSession(awsRegion string) (*session.Session, error) {
sessionOptions := session.Options{
SharedConfigState: session.SharedConfigEnable,
}
sess, err := session.NewSessionWithOptions(sessionOptions)
if err != nil {
return nil, errors.WithStackTrace(err)
}
sess.Config.Region = aws.String(awsRegion)
return sess, nil
}