{"record":{"id":"af681680e096eb1b","repo":"kubernetes/kops","slug":"error-initializing-instance-selector-v","errorCode":null,"errorMessage":"error initializing instance selector: %v","messagePattern":"error initializing instance selector: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/toolbox_instance-selector.go","lineNumber":276,"sourceCode":"\t\t\treturn err\n\t\t}\n\t\tigSubnets = userSubnets\n\t}\n\n\tzones := []string{}\n\tfor _, igSubnet := range igSubnets {\n\t\tzones = append(zones, strings.ReplaceAll(igSubnet, \"utility-\", \"\"))\n\t}\n\n\ttags := map[string]string{\"KubernetesCluster\": options.ClusterName}\n\tcloud, err := awsup.NewAWSCloud(region, tags)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error initializing AWS client: %v\", err)\n\t}\n\n\tinstanceSelector, err := selector.New(ctx, cloud.Config())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error initializing instance selector: %v\", err)\n\t}\n\tigCount := options.InstanceGroupCount\n\tfilters := getFilters(commandline, region, zones)\n\tmutatedFilters := filters\n\tif commandline.Flags[instanceGroupCount] != nil || filters.Flexible != nil {\n\t\tif filters.VCpusToMemoryRatio == nil {\n\t\t\tdefaultStartRatio := float64(2.0)\n\t\t\tmutatedFilters.VCpusToMemoryRatio = &defaultStartRatio\n\t\t}\n\t}\n\n\tnewInstanceGroups := []*kops.InstanceGroup{}\n\n\tfor i := 0; i < igCount; i++ {\n\t\tigNameForRun := options.InstanceGroupName\n\t\tif igCount != 1 {\n\t\t\tigNameForRun = fmt.Sprintf(\"%s%d\", options.InstanceGroupName, i+1)\n\t\t}","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/toolbox_instance-selector.go#L258-L294","documentation":"This wraps a failure from selector.New(ctx, cloud.Config()), which initializes the kOps instance-type selector by fetching EC2 instance type/price data (via the AWS pricing/EC2 APIs). If that discovery fails, the selector cannot be constructed and the command aborts.","triggerScenarios":"selector.New fails while enumerating EC2 instance types or pricing for the region: API throttling, denied permissions on ec2:DescribeInstanceTypes or pricing API, network failure, or unsupported/empty region data.","commonSituations":"IAM policy lacking ec2:DescribeInstanceTypes; running in a region where pricing data is unavailable; transient AWS API throttling on large accounts; network egress blocked to pricing endpoints.","solutions":["Grant the caller IAM permissions ec2:DescribeInstanceTypes and access to the AWS Pricing API.","Retry after a short delay if throttling (RequestLimitExceeded) is the underlying cause.","Confirm network access to ec2 and pricing endpoints for the region.","Upgrade kOps if the region is newly launched and not yet known to this build."],"exampleFix":"// IAM policy: allow selector initialization\n// before\n{\"Effect\": \"Deny\", \"Action\": [\"ec2:Describe*\"], \"Resource\": \"*\"}\n// after\n{\"Effect\": \"Allow\", \"Action\": [\"ec2:DescribeInstanceTypes\", \"ec2:DescribeAvailabilityZones\"], \"Resource\": \"*\"}","handlingStrategy":"retry","validationCode":"// Pre-flight IAM check\n// aws ec2 describe-instance-types --region $REGION --max-items 1\n// exit code != 0 => permissions/network problem","typeGuard":null,"tryCatchPattern":"var selectorInstance *selector.InstanceSelector\nfor attempt := 0; attempt < 3; attempt++ {\n\tselectorInstance, err = selector.New(ctx, cloud.Config())\n\tif err == nil { break }\n\ttime.Sleep(time.Duration(1<<attempt) * time.Second)\n}","preventionTips":["Include ec2:DescribeInstanceTypes and pricing permissions in the operator role.","Add exponential backoff around AWS metadata calls to survive throttling.","Keep kOps updated for newly launched regions."],"tags":["aws","instance-selector","iam-permissions"],"backgroundTag":"aws-api-permission-denied","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"}