Skip to content

Commit

Permalink
Merge pull request #2428 from LogMeIn/fix/aws-use-newsession
Browse files Browse the repository at this point in the history
AWS – use `session.NewSession` instead of `session.New` to
  • Loading branch information
k8s-ci-robot authored Oct 8, 2019
2 parents 23e0668 + f7695c5 commit a258103
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cluster-autoscaler/cloudprovider/aws/aws_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,14 @@ func newAWSSDKProvider(cfg *provider_aws.CloudConfig) *awsSDKProvider {
func getRegion(cfg ...*aws.Config) string {
region, present := os.LookupEnv("AWS_REGION")
if !present {
svc := ec2metadata.New(session.New(), cfg...)
if r, err := svc.Region(); err == nil {
region = r
sess, err := session.NewSession()
if err != nil {
klog.Errorf("Error getting AWS session while retrieving region: %v", err)
} else {
svc := ec2metadata.New(sess, cfg...)
if r, err := svc.Region(); err == nil {
region = r
}
}
}
return region
Expand Down Expand Up @@ -182,8 +187,11 @@ func createAWSManagerInternal(

if autoScalingService == nil || ec2Service == nil {
awsSdkProvider := newAWSSDKProvider(cfg)
sess := session.New(aws.NewConfig().WithRegion(getRegion()).
sess, err := session.NewSession(aws.NewConfig().WithRegion(getRegion()).
WithEndpointResolver(getResolver(awsSdkProvider.cfg)))
if err != nil {
return nil, err
}

if autoScalingService == nil {
autoScalingService = &autoScalingWrapper{autoscaling.New(sess), map[string]string{}}
Expand Down

0 comments on commit a258103

Please sign in to comment.