{"record":{"id":"e86366d41e2a229a","repo":"kubernetes/kops","slug":"failed-to-load-aws-config-w","errorCode":null,"errorMessage":"failed to load AWS config: %w","messagePattern":"failed to load AWS config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nodeup/pkg/model/context.go","lineNumber":595,"sourceCode":"// RunningOnGCE returns true if we are running on GCE\nfunc (c *NodeupModelContext) RunningOnGCE() bool {\n\treturn c.CloudProvider() == kops.CloudProviderGCE\n}\n\n// RunningOnAzure returns true if we are running on Azure\nfunc (c *NodeupModelContext) RunningOnAzure() bool {\n\treturn c.CloudProvider() == kops.CloudProviderAzure\n}\n\n// GetMetadataLocalIP returns the local IP address read from metadata\nfunc (c *NodeupModelContext) GetMetadataLocalIP(ctx context.Context) (string, error) {\n\tvar internalIP string\n\n\tswitch c.BootConfig.CloudProvider {\n\tcase kops.CloudProviderAWS:\n\t\tconfig, err := awsconfig.LoadDefaultConfig(ctx)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to load AWS config: %w\", err)\n\t\t}\n\t\tmetadata := imds.NewFromConfig(config)\n\t\tlocalIPv4, err := getMetadata(ctx, metadata, \"local-ipv4\")\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to get local-ipv4 address from ec2 metadata: %w\", err)\n\t\t}\n\t\tinternalIP = localIPv4\n\n\tcase kops.CloudProviderHetzner:\n\t\tclient := hcloudmetadata.NewClient()\n\t\tprivateNetworksYaml, err := client.PrivateNetworks()\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to get private networks from hetzner cloud metadata: %w\", err)\n\t\t}\n\t\tvar privateNetworks []struct {\n\t\t\tIP           net.IP   `json:\"ip\"`\n\t\t\tAliasIPs     []net.IP `json:\"alias_ips\"`\n\t\t\tInterfaceNum int      `json:\"interface_num\"`","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/nodeup/pkg/model/context.go#L577-L613","documentation":"GetMetadataLocalIP resolves the node's internal IP from cloud metadata. On AWS it first loads an AWS SDK v2 default config; if that fails (no region, bad credentials/IMDS availability config) it wraps the SDK error. Without a usable config the EC2 IMDS client cannot be built, so the function returns early.","triggerScenarios":"awsconfig.LoadDefaultConfig fails inside GetMetadataLocalIP on an AWS node — typically no region resolvable (no IMDS, no env/AWS_REGION) because IMDS is unreachable or disabled (IMDSv2 hop limit, metadata options set to disabled).","commonSituations":"EC2 instance metadata disabled or blocked by iptables/network policy; running nodeup outside AWS (e.g. in CI) with BootConfig.CloudProvider misconfigured as AWS; IMDSv2 hop limit too low for container/pod-based execution.","solutions":["Fix instance metadata access: ensure metadata options are enabled and IMDSv2 hop limit ≥ 2 (`aws ec2 modify-instance-metadata-options --http-tokens required --http-put-response-hop-limit 2`)","Check network/firewall rules allow 169.254.169.254 from the node","Verify BootConfig.CloudProvider is correct — this path only runs for AWS; a misconfigured provider should be corrected in the cluster spec and `kops update cluster` re-run","Set AWS_REGION / AWS_DEFAULT_REGION env on the node config if IMDS is intentionally unavailable"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// check IMDS reachability before nodeup runs\nif !curl -s --max-time 2 http://169.254.169.254/latest/api/token >/dev/null; then\n  echo \"EC2 IMDS unreachable; fix metadata options before nodeup\"\nfi","typeGuard":null,"tryCatchPattern":"ip, err := c.GetMetadataLocalIP(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to load AWS config\") {\n        klog.Errorf(\"AWS SDK config unavailable — check IMDS enabled, hop limit >= 2, and AWS_REGION: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep EC2 metadata options enabled with IMDSv2 hop limit >= 2","Allow 169.254.169.254 egress on the node","Set CloudProvider correctly in the cluster spec","Only run this code path on actual AWS nodes"],"tags":["aws","metadata","network","nodeup","imds"],"backgroundTag":"cloud-metadata-unavailable","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"}