JBerto
JBerto

Reputation: 273

Get a count of active AWS network interfaces

I need to get a count of the number of 'active' network interfaces in my region.

I can use the query below to list out the active interfaces, however I am uncertain on how to get a 'count' of the active interfaces and not just a json payload as the output.

I can run this cli command to get the list of all attached interfaces.

aws ec2 describe-network-interfaces --filters "Name=group-name,Values=Redis" "Name=attachment.status,Values=attached"

However I'm not sure how to get a count of interfaces that are attached, i tried the query below but I'm not getting the desired output to just get a count.

aws ec2 describe-network-interfaces --filters "Name=group-name,Values=Redis" "Name=attachment.status,Values=attached" --query 'NetworkInterfaces[*][Attachment.Status,Attachment.Status.Count]'

The output comes out like below.

[
    [
        "attached",
        null
    ],
    [
        "attached",
        null
    ],
    [
        "attached",
        null
    ],
    [
        "attached",
        null
    ]
]

What I'd like to see if something like below.

[
  [
     type: "attached",
     Count: "x"
  ]
]

Upvotes: 0

Views: 1431

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 270104

It seems that you want to count the number of Elastic Network Interfaces (ENIs) in the region to know when you are approaching the limit.

The limits page in the EC2 management console doesn't seem to state that the ENI count is only for attached images, so you should probably count the total number of ENIs.

This could be done with:

aws ec2 describe-network-interfaces --query 'length(NetworkInterfaces)'

If you only wish to count count ENIs that are attached, use:

aws ec2 describe-network-interfaces --filters Name=attachment.status,Values=attached --query 'length(NetworkInterfaces)' 

Upvotes: 2

Related Questions