@@ -67,6 +67,8 @@ func newRoute53() (*Interface, error) {
6767 imdsRegionResp , err := imdsClient .GetRegion (ctx , & imds.GetRegionInput {})
6868 if err != nil {
6969 klog .V (4 ).Infof ("Unable to discover region by IMDS, using SDK defaults: %s" , err )
70+ // Don't use imdsClient if it's erroring (we're probably not running on EC2 here, e.g. kops update)
71+ imdsClient = nil
7072 } else {
7173 region = imdsRegionResp .Region
7274 }
@@ -83,7 +85,7 @@ func newRoute53() (*Interface, error) {
8385 return nil , fmt .Errorf ("failed to load default aws config for STS client: %w" , err )
8486 }
8587
86- cfg , err := awsconfig .LoadDefaultConfig ( ctx ,
88+ awsOptions := [] func ( * awsconfig.LoadOptions ) error {
8789 awsconfig .WithClientLogMode (aws .LogRetries ),
8890 awslog .WithAWSLogger (),
8991 awsconfig .WithRetryer (func () aws.Retryer {
@@ -93,11 +95,15 @@ func newRoute53() (*Interface, error) {
9395 // Ensure the STS client has a region configured, if discovered by IMDS
9496 aro .Client = sts .NewFromConfig (stsCfg )
9597 }),
96- awsconfig .WithEC2IMDSRegion (func (o * awsconfig.UseEC2IMDSRegion ) {
98+ }
99+
100+ if imdsClient != nil {
101+ awsOptions = append (awsOptions , awsconfig .WithEC2IMDSRegion (func (o * awsconfig.UseEC2IMDSRegion ) {
97102 o .Client = imdsClient
98- }),
99- )
103+ }))
104+ }
100105
106+ cfg , err := awsconfig .LoadDefaultConfig (ctx , awsOptions ... )
101107 if err != nil {
102108 return nil , fmt .Errorf ("failed to load default aws config: %w" , err )
103109 }
0 commit comments