Paginate DescribeNetworkInterfaces calls

This should help with VPCs containing large numbers of ENIs

Signed-off-by: Peter Rifel <pgrifel@gmail.com>
This commit is contained in:
Peter Rifel 2023-09-06 21:34:27 -05:00
parent 0086ad9a85
commit 7ec30b4a98
No known key found for this signature in database
GPG Key ID: BC6469E5B16DB2B6
1 changed files with 10 additions and 9 deletions

View File

@ -72,18 +72,19 @@ func DescribeENIs(cloud fi.Cloud, clusterName string) (map[string]*ec2.NetworkIn
request := &ec2.DescribeNetworkInterfacesInput{
Filters: filters,
}
response, err := c.EC2().DescribeNetworkInterfaces(request)
err := c.EC2().DescribeNetworkInterfacesPages(request, func(dnio *ec2.DescribeNetworkInterfacesOutput, b bool) bool {
for _, eni := range dnio.NetworkInterfaces {
// Skip ENIs that are attached
if eni.Attachment != nil {
continue
}
enis[aws.StringValue(eni.NetworkInterfaceId)] = eni
}
return true
})
if err != nil {
return nil, fmt.Errorf("error listing ENIs: %v", err)
}
for _, eni := range response.NetworkInterfaces {
// Skip ENIs that are attached
if eni.Attachment != nil {
continue
}
enis[aws.StringValue(eni.NetworkInterfaceId)] = eni
}
}
return enis, nil