{"record":{"id":"51d0c8352039261a","repo":"kubernetes/kops","slug":"failed-to-load-default-aws-config-for-imds-client","errorCode":null,"errorMessage":"failed to load default aws config for IMDS client: %w","messagePattern":"failed to load default aws config for IMDS client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dnsprovider/pkg/dnsprovider/providers/aws/route53/route53.go","lineNumber":60,"sourceCode":"var MaxBatchSize = 900\n\nfunc init() {\n\tdnsprovider.RegisterDNSProvider(ProviderName, func(config io.Reader) (dnsprovider.Interface, error) {\n\t\treturn newRoute53()\n\t})\n}\n\n// newRoute53 creates a new instance of an AWS Route53 DNS Interface.\nfunc newRoute53() (*Interface, error) {\n\tctx := context.TODO()\n\n\timdsCfg, err := awsconfig.LoadDefaultConfig(ctx,\n\t\tawsconfig.WithRetryer(func() aws.Retryer {\n\t\t\treturn retry.AddWithMaxAttempts(retry.NewStandard(), 5)\n\t\t}),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load default aws config for IMDS client: %w\", err)\n\t}\n\timdsClient := imds.NewFromConfig(imdsCfg)\n\n\tvar region string\n\timdsRegionResp, err := imdsClient.GetRegion(ctx, &imds.GetRegionInput{})\n\tif err != nil {\n\t\tklog.V(4).Infof(\"Unable to discover region by IMDS, using SDK defaults: %s\", err)\n\t\t// Don't use imdsClient if it's erroring (we're probably not running on EC2 here, e.g. kops update)\n\t\timdsClient = nil\n\t} else {\n\t\tregion = imdsRegionResp.Region\n\t}\n\n\tawsOptions := []func(*awsconfig.LoadOptions) error{\n\t\tawsconfig.WithClientLogMode(aws.LogRetries),\n\t\tawslog.WithAWSLogger(),\n\t\tawsconfig.WithRetryer(func() aws.Retryer {\n\t\t\treturn retry.AddWithMaxAttempts(retry.NewStandard(), 5)","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/dnsprovider/pkg/dnsprovider/providers/aws/route53/route53.go#L42-L78","documentation":"newRoute53 first loads a default AWS config (via aws config.LoadDefaultConfig) solely to build an EC2 IMDS client used to discover the region. If LoadDefaultConfig fails while building that IMDS config, the error is wrapped and returned.","triggerScenarios":"Calling newRoute53 when LoadDefaultConfig fails for the initial IMDS config load — e.g. malformed AWS_PROFILE, unreadable/broken shared config files (~/.aws/config, ~/.aws/credentials), invalid env values, or SDK config loading errors.","commonSituations":"Corrupt or syntactically invalid ~/.aws/config; AWS_CONFIG_FILE/AWS_SHARED_CREDENTIALS_FILE pointing at missing files; malformed SSO or assume-role profiles; bad AWS_RETRY_MODE or other env values the SDK rejects.","solutions":["Inspect the wrapped %w error for the underlying config-load cause and fix that file/setting.","Validate ~/.aws/config and ~/.aws/credentials syntax; unset AWS_CONFIG_FILE/AWS_SHARED_CREDENTIALS_FILE if mispointed.","Test with `aws sts get-caller-identity` using the same profile to confirm config validity.","Unset AWS_PROFILE (or pick a valid one) and retry."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight: ensure AWS config files parse\nif os.Getenv(\"AWS_CONFIG_FILE\") != \"\" {\n    if _, err := os.Stat(os.Getenv(\"AWS_CONFIG_FILE\")); err != nil {\n        return fmt.Errorf(\"AWS_CONFIG_FILE missing: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"zone, err := dnsprovider.InitDnsProvider(\"aws-route53\", ...)\nif err != nil && strings.Contains(err.Error(), \"failed to load default aws config for IMDS client\") {\n    // surface the wrapped cause: errors.Unwrap(err) and inspect *aws.ConfigLoadError\n    return fmt.Errorf(\"check ~/.aws/config and AWS_PROFILE: %w\", err)\n}","preventionTips":["Keep ~/.aws/config and ~/.aws/credentials syntactically valid.","Run `aws configure list` / `aws sts get-caller-identity` before automation.","Avoid pointing AWS_CONFIG_FILE at nonexistent paths."],"tags":["aws","route53","config"],"backgroundTag":"aws-config-load-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}