Skip to content

Commit

Permalink
fix(aws): always session from externalcreds (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
dixneuf19 committed Jul 3, 2023
1 parent b0d7647 commit 7e02ef4
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -1770,12 +1770,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 @@ -2089,16 +2084,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 @@ -2120,15 +2106,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
}

0 comments on commit 7e02ef4

Please sign in to comment.