kubernetes/kops · error
found instance, but InstanceId was nil
Error message
found instance, but InstanceId was nil
What it means
Find() found exactly one matching instance, but its InstanceId field was nil, which should never happen for an instance returned by DescribeInstances. Rather than dereference a nil pointer, kOps returns this defensive error. It usually indicates an unexpected/SDK-level anomaly or a mocked response missing the ID.
Source
Thrown at upup/pkg/fi/cloudup/awstasks/instance.go:110
if response != nil {
for _, reservation := range response.Reservations {
instances = append(instances, reservation.Instances...)
}
}
if len(instances) == 0 {
return nil, nil
}
if len(instances) != 1 {
return nil, fmt.Errorf("found multiple Instances with name: %s", *e.Name)
}
klog.V(2).Info("found existing instance")
i := instances[0]
if i.InstanceId == nil {
return nil, fmt.Errorf("found instance, but InstanceId was nil")
}
actual := &Instance{
ID: i.InstanceId,
PrivateIPAddress: i.PrivateIpAddress,
InstanceType: i.InstanceType,
ImageID: i.ImageId,
Name: findNameTag(i.Tags),
}
// Fetch instance UserData
{
request := &ec2.DescribeInstanceAttributeInput{}
request.InstanceId = i.InstanceId
request.Attribute = ec2types.InstanceAttributeNameUserData
response, err := cloud.EC2().DescribeInstanceAttribute(ctx, request)
if err != nil {
return nil, fmt.Errorf("error querying EC2 for user metadata for instance %q: %v", *i.InstanceId, err)View on GitHub (pinned to 4c8573c808)
Solutions
- Re-run the operation to rule out a transient bad response.
- If using a fake/mock EC2 client, ensure DescribeInstances results always set InstanceId.
- Update the AWS SDK / kops version if a deserialization bug is suspected; report to kops if reproducible against real AWS.
Example fix
// mock fix
// before
ec2types.Instance{State: ...} // InstanceId omitted
// after
ec2types.Instance{InstanceId: aws.String("i-123"), State: ...} Defensive patterns
Strategy: type-guard
Validate before calling
// caller-side check when inspecting instance state
if i.InstanceId == nil { return errors.New("instance response missing InstanceId") } Type guard
func hasID(i ec2types.Instance) bool { return i.InstanceId != nil && aws.ToString(i.InstanceId) != "" } Try / catch
if err != nil && strings.Contains(err.Error(), "InstanceId was nil") {
// treat as transient/mocked-data bug: retry once, then report
return retryOnceOrReport(err)
} Prevention
- If using fake/mock EC2 clients (e.g. in tests or forks), always populate InstanceId.
- Keep the AWS SDK and kops versions current to rule out deserialization bugs.
- Report reproducible occurrences against real AWS to kops with the DescribeInstances response shape.
When it happens
Trigger: instances[0].InstanceId is nil when building the actual state — only realistically seen with stubbed/malformed AWS responses or severe SDK deserialization anomalies.
Common situations: Running against mocked/fake AWS clients in tests or custom tooling that omit InstanceId; corrupted API responses.
Related errors
- DIGITALOCEAN_ACCESS_TOKEN is required
- timed out waiting for volume to detach
- unexpected number of network interfaces for instance %q: %v
- unexpected amount of ipv6 prefixes on interface %q: %v
- getting primary MAC address from ec2 metadata: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/f4dcd687a42b926a.
Report an issue: GitHub.