From 07e43f476ab61fe59d27182e1450bec9c99e1d1f Mon Sep 17 00:00:00 2001 From: Nithish Date: Thu, 21 Nov 2019 14:02:42 -0600 Subject: [PATCH] Remove deprecated session.New method --- pkg/ec2metadata/client.go | 7 +++++-- pkg/ec2metadatawrapper/ec2metadatawrapper.go | 10 ++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/ec2metadata/client.go b/pkg/ec2metadata/client.go index 5d13e06faa..d710385167 100644 --- a/pkg/ec2metadata/client.go +++ b/pkg/ec2metadata/client.go @@ -25,7 +25,10 @@ type EC2Metadata interface { Region() (string, error) } -// NewEC2Metadata creates a new EC2Metadata object +// New creates a new EC2Metadata object func New() EC2Metadata { - return ec2metadatasvc.New(session.New(), aws.NewConfig().WithMaxRetries(10)) + awsSession := session.Must(session.NewSession(aws.NewConfig(). + WithMaxRetries(10), + )) + return ec2metadatasvc.New(awsSession) } diff --git a/pkg/ec2metadatawrapper/ec2metadatawrapper.go b/pkg/ec2metadatawrapper/ec2metadatawrapper.go index c6a55d7aa5..072bc8baae 100644 --- a/pkg/ec2metadatawrapper/ec2metadatawrapper.go +++ b/pkg/ec2metadatawrapper/ec2metadatawrapper.go @@ -1,4 +1,4 @@ -// package ecmetadatawrapper is used to retrieve data from EC2 IMDS +// Package ec2metadatawrapper is used to retrieve data from EC2 IMDS package ec2metadatawrapper import ( @@ -32,10 +32,12 @@ type ec2MetadataClientImpl struct { // New creates an ec2metadata client to retrieve metadata func New(client HttpClient) EC2MetadataClient { if client == nil { - return &ec2MetadataClientImpl{client: ec2metadata.New(session.New(), aws.NewConfig().WithMaxRetries(metadataRetries))} - } else { - return &ec2MetadataClientImpl{client: client} + awsSession := session.Must(session.NewSession(aws.NewConfig(). + WithMaxRetries(metadataRetries), + )) + return &ec2MetadataClientImpl{client: ec2metadata.New(awsSession)} } + return &ec2MetadataClientImpl{client: client} } // InstanceIdentityDocument returns instance identity documents