From f2f5c1a345d5c35ca1130dfe263c409aa6efabd9 Mon Sep 17 00:00:00 2001 From: Alfred Krohmer Date: Mon, 7 Oct 2019 14:53:41 +0200 Subject: [PATCH] =?UTF-8?q?AWS=20=E2=80=93=20use=20`session.NewSession`=20?= =?UTF-8?q?instead=20of=20`session.New`=20to?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `session.New` is deprecated and requires the `AWS_SDK_LOAD_CONFIG` environment variable to be set in order to automatically call `AssumeRoleWithWebIdentity` when `AWS_WEB_IDENTITY_TOKEN_FILE` is set (which is not documented and most likely unintended). --- .../cloudprovider/aws/aws_manager.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/aws/aws_manager.go b/cluster-autoscaler/cloudprovider/aws/aws_manager.go index 016186c502cd..d4d7435ad879 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_manager.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_manager.go @@ -71,9 +71,14 @@ type asgTemplate struct { 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 @@ -95,7 +100,10 @@ func createAWSManagerInternal( } if autoScalingService == nil || ec2Service == nil { - sess := session.New(aws.NewConfig().WithRegion(getRegion())) + sess, err := session.NewSession(aws.NewConfig().WithRegion(getRegion())) + if err != nil { + return nil, err + } if autoScalingService == nil { autoScalingService = &autoScalingWrapper{autoscaling.New(sess), map[string]string{}}