For an AWS Security Group to be considered in-use/active it will be assigned to an Elastic network interface (ENI's).
The following Python script will determine currently unused security groups by:
- Query AWS for all active ENI's in an account region.
- For each interface, extract the attached security group(s).
- Query AWS for all security groups within the same account region.
- Determine where and output a security group which currently has zero assignments to any active ENI's.