Skip to content

Commit 59504c1

Browse files
committed
updated pkg/server to use v2
1 parent ac43edb commit 59504c1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pkg/server/server.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
"sync"
2929
"time"
3030

31-
"github.com/aws/aws-sdk-go/aws/ec2metadata"
32-
"github.com/aws/aws-sdk-go/aws/session"
31+
awsconfig "github.com/aws/aws-sdk-go-v2/config"
32+
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
3333
"sigs.k8s.io/aws-iam-authenticator/pkg/config"
3434
"sigs.k8s.io/aws-iam-authenticator/pkg/ec2provider"
3535
"sigs.k8s.io/aws-iam-authenticator/pkg/errutil"
@@ -199,12 +199,16 @@ func (c *Server) getHandler(backendMapper BackendMapper, ec2DescribeQps int, ec2
199199
panic(fmt.Sprintf("describeinstancesrole %s is not a valid arn", c.ServerEC2DescribeInstancesRoleARN))
200200
}
201201
}
202-
sess := session.Must(session.NewSession())
203-
ec2metadata := ec2metadata.New(sess)
204-
instanceRegion, err := ec2metadata.Region()
202+
cfg, err := awsconfig.LoadDefaultConfig(context.Background())
203+
if err != nil {
204+
logrus.WithError(err).Errorln("Could not load config")
205+
}
206+
imdsClient := imds.NewFromConfig(cfg)
207+
instanceRegionOutput, err := imdsClient.GetRegion(context.TODO(), &imds.GetRegionInput{})
205208
if err != nil {
206209
logrus.WithError(err).Errorln("Region not found in instance metadata.")
207210
}
211+
instanceRegion := instanceRegionOutput.Region
208212

209213
h := &handler{
210214
verifier: token.NewVerifier(c.ClusterID, c.PartitionID, instanceRegion),

0 commit comments

Comments
 (0)