{"record":{"id":"eadb801227a3c4ea","repo":"kubernetes/kops","slug":"region-is-not-a-recognized-ec2-region-q-check-y","errorCode":null,"errorMessage":"Region is not a recognized EC2 region: %q (check you have specified valid zones?)","messagePattern":"Region is not a recognized EC2 region: %q \\(check you have specified valid zones\\?\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awsup/aws_utils.go","lineNumber":88,"sourceCode":"\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 {\n\t\t\treturn nil\n\t\t}\n\t}\n\n\tif os.Getenv(\"SKIP_REGION_CHECK\") != \"\" {\n\t\tklog.Infof(\"AWS region does not appear to be valid, but skipping because SKIP_REGION_CHECK is set\")\n\t\treturn nil\n\t}\n\n\treturn fmt.Errorf(\"Region is not a recognized EC2 region: %q (check you have specified valid zones?)\", region)\n}\n\n// FindRegion determines the region from the zones specified in the cluster\nfunc FindRegion(cluster *kops.Cluster) (string, error) {\n\tregion := \"\"\n\n\tfor _, subnet := range cluster.Spec.Networking.Subnets {\n\t\tif subnet.Zone == \"\" {\n\t\t\t// The zone of a subnet specified by ID is looked up from the cloud later.\n\t\t\tif subnet.ID == \"\" {\n\t\t\t\treturn \"\", fmt.Errorf(\"subnet %q must specify a zone or the ID of an existing subnet\", subnet.Name)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tif len(subnet.Zone) <= 2 {\n\t\t\treturn \"\", fmt.Errorf(\"invalid AWS zone: %q in subnet %q\", subnet.Zone, subnet.Name)\n\t\t}","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awsup/aws_utils.go#L70-L106","documentation":"After querying EC2 for all valid regions, ValidateRegion checks whether the requested region name appears in that list. If it does not — and SKIP_REGION_CHECK is not set — the library rejects the region as not a recognized EC2 region and suggests checking the specified zones. This guards against typos in region names that would otherwise produce confusing failures later during cluster creation.","triggerScenarios":"Calling ValidateRegion (via BuildCloud) with a region string that is not in the DescribeRegions response — misspelled region, wrong partition (e.g. us-gov-west-1 with standard credentials), or an empty/garbage value derived from zones.","commonSituations":"Typo like 'us-east1' or 'eu-west' in kops cluster spec; using a China/GovCloud region with the wrong account; SKIP_REGION_CHECK unset in offline/air-gapped environments where DescribeRegions response was unusable.","solutions":["Correct the region name in the cluster spec / --zone flags to a valid EC2 region (e.g. us-east-1, eu-west-1)","Set SKIP_REGION_CHECK=1 only as a deliberate override when you know the region is valid but EC2 cannot be queried","Verify the region belongs to the partition your credentials support"],"exampleFix":"// before\nzones: [\"us-east1a\"]\n// after\nzones: [\"us-east-1a\"]","handlingStrategy":"validation","validationCode":"var regionRe = regexp.MustCompile(`^(us|eu|ap|ca|sa|af|me|il)-[a-z]+-\\d$|^cn-north(-\\d+)?$|^us-gov-[a-z]+-\\d$`)\nfunc regionLooksValid(region string) bool { return regionRe.MatchString(region) }","typeGuard":null,"tryCatchPattern":"if err := kopsValidateRegion(ctx, region); err != nil {\n    if strings.Contains(err.Error(), \"not a recognized EC2 region\") {\n        log.Fatalf(\"typo in region %q? check zones flags\", region)\n    }\n    return err\n}","preventionTips":["Validate region names against the output of `aws ec2 describe-regions` in CI","Derive the region from zone names programmatically rather than hardcoding","Use SKIP_REGION_CHECK=1 only deliberately, never to silence typos"],"tags":["aws","region","validation","config"],"backgroundTag":"invalid-aws-region","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}