{"record":{"id":"4a43ab7be56d12fc","repo":"kubernetes/kops","slug":"error-initializing-aws-client-v-4a43ab","errorCode":null,"errorMessage":"error initializing AWS client: %v","messagePattern":"error initializing AWS client: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/toolbox_instance-selector.go","lineNumber":271,"sourceCode":"\tif commandline.Flags[subnets] != nil {\n\t\tuserSubnets := *commandline.StringSliceMe(commandline.Flags[subnets])\n\t\tdryRun := *commandline.BoolMe(commandline.Flags[dryRun])\n\t\terr := validateUserSubnets(userSubnets, cluster.Spec.Networking.Subnets)\n\t\tif err != nil && !dryRun {\n\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","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/toolbox_instance-selector.go#L253-L289","documentation":"RunToolboxInstanceSelector wraps any failure from awsup.NewAWSCloud, which builds the AWS SDK client for the cluster's region using the KubernetesCluster tag. NewAWSCloud validates the region and performs region discovery; any SDK init failure (invalid region, missing/bad credentials, network issues) is surfaced here. This error means kOps could not construct a working AWS client before doing any instance-selector work.","triggerScenarios":"awsup.NewAWSCloud(region, tags) returns an error: region string is invalid/empty, AWS credentials cannot be resolved (env, shared config, IAM role), or the EC2 metadata/region validation call fails.","commonSituations":"Passing a mistyped --region like us-east-1a or eu-west; running outside AWS without AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY set or ~/.aws/credentials absent; expired SSO session; corporate proxy blocking EC2 endpoints.","solutions":["Verify the --region value is a valid AWS region code (e.g. us-east-1), not an availability zone.","Check AWS credentials: run `aws sts get-caller-identity` to confirm auth works in this shell.","Ensure AWS_REGION/AWS_DEFAULT_REGION or the shared config file is consistent with the flag.","If behind a proxy/airgap, confirm EC2 endpoints for the region are reachable."],"exampleFix":"// before\nkops toolbox instance-selector --region us-east-1a ...\n// after\nkops toolbox instance-selector --region us-east-1 ...","handlingStrategy":"validation","validationCode":"region := \"us-east-1\"\nif region == \"\" || len(strings.Split(region, \"-\")) != 3 || strings.Contains(region, \"az\") {\n\treturn fmt.Errorf(\"invalid AWS region %q\", region)\n}\n// also verify credentials beforehand:\n// aws sts get-caller-identity","typeGuard":null,"tryCatchPattern":"if _, err := awsup.NewAWSCloud(region, tags); err != nil {\n\tlog.Fatalf(\"AWS client init failed: %v — check --region and AWS credentials\", err)\n}","preventionTips":["Always pass a region code (e.g. us-east-1), never an AZ name.","Run `aws sts get-caller-identity` in CI before kOps commands.","Pin AWS credentials via a profile and avoid expired SSO sessions in automation."],"tags":["aws","cloud-client","configuration"],"backgroundTag":"aws-client-init-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"}