{"record":{"id":"a6e18f1bb792451d","repo":"kubernetes/kops","slug":"error-loading-aws-config-v-a6e18f","errorCode":null,"errorMessage":"error loading AWS config: %v","messagePattern":"error loading AWS config: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awsup/aws_utils.go","lineNumber":60,"sourceCode":"var allRegions []ec2types.Region\nvar allRegionsMutex sync.Mutex\n\n// ValidateRegion checks that an AWS region name is valid\nfunc ValidateRegion(ctx context.Context, region string) error {\n\tallRegionsMutex.Lock()\n\tdefer allRegionsMutex.Unlock()\n\n\tif allRegions == nil {\n\t\tklog.V(2).Infof(\"Querying EC2 for all valid regions\")\n\n\t\trequest := &ec2.DescribeRegionsInput{}\n\t\tawsRegion := os.Getenv(\"AWS_REGION\")\n\t\tif awsRegion == \"\" {\n\t\t\tawsRegion = \"us-east-1\"\n\t\t}\n\t\tcfg, err := loadAWSConfig(ctx, awsRegion)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error loading AWS config: %v\", err)\n\t\t}\n\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error starting a new AWS session: %v\", err)\n\t\t}\n\n\t\tclient := ec2.NewFromConfig(cfg)\n\n\t\tresponse, err := client.DescribeRegions(ctx, request)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"got an error while querying for valid regions (verify your AWS credentials?): %v\", err)\n\t\t}\n\t\tallRegions = response.Regions\n\t}\n\n\tfor _, r := range allRegions {\n\t\tname := aws.ToString(r.RegionName)\n\t\tif name == region {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awsup/aws_utils.go#L42-L78","documentation":"ValidateRegion loads an AWS SDK v2 config (via loadAWSConfig) to test whether a region is valid, and wraps any config-loading failure with this message. Config loading fails when the SDK cannot resolve credentials, profile, or region configuration from env vars, shared config files, or other sources. It is the first failure mode of the region-validation path before any EC2 call is made.","triggerScenarios":"Calling ValidateRegion (directly or via BuildCloud) when loadAWSConfig returns an error — e.g. malformed AWS_SDK_LOAD_CONFIG shared file, invalid profile name, unresolvable credential chain, or bad region format passed to config loading.","commonSituations":"AWS_CONFIG_FILE or ~/.aws/credentials is corrupt or has wrong permissions; AWS_PROFILE names a nonexistent profile; credential_process returns junk; running in CI without any AWS env configuration.","solutions":["Check ~/.aws/config and ~/.aws/credentials parse correctly (run `aws sts get-caller-identity` with the same environment)","Unset or fix AWS_PROFILE / AWS_CONFIG_FILE if they point to broken profiles","Provide valid credentials via env vars (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) or a proper credential source (SSO, instance role)","Update AWS SDK to ensure the config loader supports your SSO/config format"],"exampleFix":"// before\nexport AWS_PROFILE=no-such-profile\n// after\nexport AWS_PROFILE=staging-admin  # profile that exists in ~/.aws/config","handlingStrategy":"try-catch","validationCode":"// fail fast with a clear message before calling kops\nif os.Getenv(\"AWS_PROFILE\") != \"\" {\n    if _, err := os.Stat(filepath.Join(home, \".aws\", \"config\")); err != nil {\n        log.Fatalf(\"AWS_PROFILE set but no ~/.aws/config\")\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := kopsValidateRegion(ctx, region); err != nil {\n    if strings.Contains(err.Error(), \"error loading AWS config\") {\n        log.Fatalf(\"fix AWS config/credentials: %v\", err)\n    }\n    return err\n}","preventionTips":["Run `aws sts get-caller-identity` in the same shell/CI job before invoking kops","Keep ~/.aws/config syntactically valid; avoid hand-editing while jobs run","Pin AWS_PROFILE per environment and document required env vars for CI"],"tags":["aws","config","credentials","sdk"],"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"}