{"record":{"id":"0018bdc85fb6f4a9","repo":"kubernetes/kops","slug":"resolving-ec2-endpoint-for-region-q-w","errorCode":null,"errorMessage":"resolving EC2 endpoint for region %q: %w","messagePattern":"resolving EC2 endpoint for region %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awsup/aws_utils.go","lineNumber":130,"sourceCode":"\n\t\tregion = zoneRegion\n\t}\n\n\tif region == \"\" {\n\t\treturn \"\", fmt.Errorf(\"could not determine cluster region: no subnet specifies a zone\")\n\t}\n\n\treturn region, nil\n}\n\n// SupportsS3BootstrapEndpoint reports whether the region uses the amazonaws.com partition DNS\n// suffix hard-coded by the nodeup bootstrap script. EC2 uses the same partition suffix as S3 and\n// can be resolved without a bucket.\nfunc SupportsS3BootstrapEndpoint(ctx context.Context, region string) (bool, error) {\n\tresolver := ec2.NewDefaultEndpointResolverV2()\n\tendpoint, err := resolver.ResolveEndpoint(ctx, ec2.EndpointParameters{Region: aws.String(region)})\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"resolving EC2 endpoint for region %q: %w\", region, err)\n\t}\n\n\treturn endpoint.URI.Hostname() == fmt.Sprintf(\"ec2.%s.amazonaws.com\", region), nil\n}\n\n// FindEC2Tag find the value of the tag with the specified key\nfunc FindEC2Tag(tags []ec2types.Tag, key string) (string, bool) {\n\tfor _, tag := range tags {\n\t\tif key == aws.ToString(tag.Key) {\n\t\t\treturn aws.ToString(tag.Value), true\n\t\t}\n\t}\n\treturn \"\", false\n}\n\n// FindASGTag find the value of the tag with the specified key\nfunc FindASGTag(tags []autoscalingtypes.TagDescription, key string) (string, bool) {\n\tfor _, tag := range tags {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awsup/aws_utils.go#L112-L148","documentation":"SupportsS3BootstrapEndpoint resolves the EC2 endpoint for a region with the SDK v2 endpoint resolver to learn the partition DNS suffix; if resolution fails (typically because the region is unknown to the resolver), the error is wrapped with this message. The function compares the resolved hostname against ec2.<region>.amazonaws.com to decide whether the S3 bootstrap endpoint style applies. Endpoint resolution failure usually means an unrecognized or unsupported region string.","triggerScenarios":"Calling SupportsS3BootstrapEndpoint (directly or via ResolveS3Region / awsValidateS3FileRepositoryPartition) with a region the ec2 endpoint resolver cannot map — typos, empty region, or regions from other partitions not in the resolver's endpoints model.","commonSituations":"New AWS regions not yet in the bundled AWS SDK endpoint model (SDK too old); misspelled region passed to kops; custom/private deployments whose region is not in the public endpoint set.","solutions":["Use a correct, current AWS region name for the target partition","Upgrade kops / aws-sdk-go-v2 so the endpoint resolver knows about newer regions","Set SKIP_REGION_CHECK or override endpoints if operating in a custom partition (advanced)"],"exampleFix":"// before\nkops create cluster --region us-east-42 ...\n// after\nkops create cluster --region us-east-1 ...","handlingStrategy":"validation","validationCode":"// ensure region is non-empty and matches known AWS naming before the call\nif region == \"\" || !regexp.MustCompile(`^[a-z]{2}(-gov)?-[a-z]+-\\d$`).MatchString(region) {\n    return fmt.Errorf(\"bad region %q\", region)\n}","typeGuard":null,"tryCatchPattern":"ok, err := SupportsS3BootstrapEndpoint(ctx, region)\nif err != nil {\n    return fmt.Errorf(\"cannot resolve endpoints for %q; upgrade SDK or fix region: %w\", region, err)\n}","preventionTips":["Keep aws-sdk-go-v2 updated so the endpoint resolver knows new regions","Verify region names against `aws ec2 describe-regions`","Handle non-amazonaws partitions explicitly rather than assuming amazonaws.com suffix"],"tags":["aws","endpoint-resolution","region","s3"],"backgroundTag":"aws-endpoint-resolution-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"}