{"record":{"id":"8345751e19ad0b7e","repo":"kubernetes/kops","slug":"failed-to-load-aws-config-w-834575","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":"upup/pkg/fi/nodeup/command.go","lineNumber":412,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"error closing target: %w\", err)\n\t}\n\n\tif nodeupConfig.EnableLifecycleHook {\n\t\tif bootConfig.CloudProvider == api.CloudProviderAWS {\n\t\t\terr := completeWarmingLifecycleAction(ctx, cloud, modelContext)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to complete lifecylce action: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc getMachineType(ctx context.Context) (string, error) {\n\tconfig, err := awsconfig.LoadDefaultConfig(ctx)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to load AWS config: %w\", err)\n\t}\n\n\tmetadata := imds.NewFromConfig(config)\n\n\t// Get the actual instance type by querying the EC2 instance metadata service.\n\tresult, err := metadata.GetMetadata(ctx, &imds.GetMetadataInput{\n\t\tPath: \"instance-type\",\n\t})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get instance metadata type: %w\", err)\n\t}\n\tdefer result.Content.Close()\n\tinstanceTypeName, err := io.ReadAll(result.Content)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to read instance metadata response: %w\", err)\n\t}\n\treturn string(instanceTypeName), err\n}","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/nodeup/command.go#L394-L430","documentation":"getMachineType calls awsconfig.LoadDefaultConfig(ctx) to build an AWS SDK v2 config so it can query IMDS for the instance type. If the SDK cannot resolve credentials/region (LoadDefaultConfig errors), nodeup wraps the failure with this message and aborts machine-type detection.","triggerScenarios":"awsconfig.LoadDefaultConfig(ctx) returns an error on an AWS node — typically IMDS unreachable, EC2 instance metadata disabled, or a broken shared-config/env setup that the default config chain tries to load.","commonSituations":"EC2 launched with MetadataOptions HttpTokens required but IMDS hop limit/endpoint broken in a container; nodeup running where the metadata endpoint is blocked by iptables/NetworkPolicy; corrupted ~/.aws/config with an invalid profile; IMDSv2 packet limit set too low.","solutions":["Restore IMDS reachability: curl -s http://169.254.169.254/latest/api/token should return a token from the node.","If launched with metadata options requiring tokens, fix hop limit (>=2 for containerized nodeup) via instance metadata options.","Check for invalid AWS_PROFILE / ~/.aws/config on the node and remove it so defaults resolve from IMDS.","Run nodeup directly on the host (not in a network-isolated container) so the link-local metadata address is routable."],"exampleFix":"// before: container with hop-limit 1 cannot fetch IMDSv2 token\n// after: set instance metadata options\naws ec2 modify-instance-metadata-options --instance-id i-xxx \\\n  --http-tokens required --http-put-response-hop-limit 2","handlingStrategy":"retry","validationCode":"TOKEN=$(curl -sf -X PUT http://169.254.169.254/latest/api/token -H 'X-aws-ec2-metadata-token-ttl-seconds: 60') && curl -sf -H \"X-aws-ec2-metadata-token: $TOKEN\" http://169.254.169.254/latest/meta-data/instance-type","typeGuard":null,"tryCatchPattern":"machineType, err := getMachineType(ctx)\nif err != nil {\n    if isTransient(err) { // IMDS network errors\n        time.Sleep(retryBackoff)\n        machineType, err = getMachineType(ctx)\n    }\n    if err != nil {\n        klog.Fatalf(\"cannot determine machine type: %v\", err)\n    }\n}","preventionTips":["Set --http-put-response-hop-limit 2 when nodeup runs inside a container.","Never disable the EC2 metadata endpoint on nodes.","Avoid invalid AWS_PROFILE/~/.aws/config files on nodes.","Health-check IMDS as a nodeup pre-flight step."],"tags":["aws","imds","config","nodeup"],"backgroundTag":"aws-config-load-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"}