{"record":{"id":"f0ef6f5ec72e9641","repo":"kubernetes/kops","slug":"failed-to-get-q-from-ec2-meta-data-not-found","errorCode":null,"errorMessage":"failed to get %q from ec2 meta-data: not found","messagePattern":"failed to get %q from ec2 meta-data: not found","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/nodeup/nodetasks/prefix.go","lineNumber":116,"sourceCode":"\tresponse, err := t.Cloud.AssignIpv6Addresses(ctx, &ec2.AssignIpv6AddressesInput{\n\t\tIpv6PrefixCount:    new(int32(1)),\n\t\tNetworkInterfaceId: new(interfaceId),\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to assign prefix: %w\", err)\n\t}\n\tklog.V(2).Infof(\"assigned prefix to primary network interface: %q\", response.AssignedIpv6Prefixes[0])\n\n\treturn nil\n}\n\nfunc getInstanceMetadataFirstValue(ctx context.Context, category string) (string, error) {\n\tvalues, err := getInstanceMetadataList(ctx, category)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif len(values) == 0 {\n\t\treturn \"\", fmt.Errorf(\"failed to get %q from ec2 meta-data: not found\", category)\n\t}\n\n\treturn values[0], nil\n}\n\nfunc getInstanceMetadataList(ctx context.Context, category string) ([]string, error) {\n\tcfg, err := awsconfig.LoadDefaultConfig(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load aws config: %v\", err)\n\t}\n\tmetadata := imds.NewFromConfig(cfg)\n\tresp, err := metadata.GetMetadata(ctx, &imds.GetMetadataInput{Path: category})\n\tif err != nil {\n\t\tvar awsErr *smithyhttp.ResponseError\n\t\tif errors.As(err, &awsErr) && awsErr.HTTPStatusCode() == http.StatusNotFound {\n\t\t\treturn nil, nil\n\t\t} else {\n\t\t\treturn nil, fmt.Errorf(\"failed to get %q from ec2 meta-data: %v\", category, err)","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/nodeup/nodetasks/prefix.go#L98-L134","documentation":"getInstanceMetadataFirstValue queries the EC2 instance metadata service (IMDS) for a category (e.g. 'mac') and expects at least one value; an empty list means IMDS responded but the key was absent, so this error is returned. It indicates the instance metadata endpoint does not expose the requested field.","triggerScenarios":"IMDS returns 200 with an empty body, or getInstanceMetadataList returns a 404-mapped nil slice with no values, for categories like 'mac' or 'network/interfaces/macs/<mac>/ipv6-prefix'.","commonSituations":"Running nodeup outside a real EC2 instance (bare metal, containers, CI) where IMDS is absent or stubbed; hop limit too low so IMDS responses are dropped; metadata options restricting access.","solutions":["Run the node only on EC2 with IMDS enabled (HttpTokens/HttpEndpoint not disabled).","Raise the IMDS hop limit (e.g. `aws ec2 modify-instance-metadata-options --http-put-response-hop-limit 2`) when accessing via a container.","Verify the requested category path is valid for the instance (e.g. IPv6 enabled on the interface)."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"out, err := exec.Command(\"curl\", \"-sf\", \"http://169.254.169.254/latest/meta-data/\").Output()\nif err != nil { return errors.New(\"IMDS unreachable on this host\") }","typeGuard":null,"tryCatchPattern":"if err != nil {\n    var opErr *net.OpError\n    if errors.As(err, &opErr) { /* IMDS network issue: fail fast or fallback */ }\n}","preventionTips":["Run workloads only on EC2 instances with IMDS enabled","Set IMDS hop limit >= 2 when nodeup runs in containers","Confirm requested metadata categories exist for the instance type"],"tags":["aws","imds","instance-metadata","ec2"],"backgroundTag":"instance-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"}