如何找到所有 AWS 安全组中未使用的安全组?

How to find Unused Security Groups of all AWS Security Groups?

如何使用 Boto 查找与所有 aws 资源相关联的所有使用过的安全组?
目前以下脚本仅提供 ec2 实例 -

     sec_grps = ec2_conn.get_all_security_groups()  
     for group in sec_grps:   
         print group, " Instances attached ", group.instances()  

有没有办法获取所有 aws 资源未使用的所有安全组?

这是一个稍微困难的请求,因为安全组被许多不同的资源使用,包括:

  • Amazon EC2 实例
  • Amazon RDS 实例
  • VPC 弹性网络接口 (ENI)
  • Amazon Redshift 集群
  • Amazon ElastiCache 集群
  • Amazon Elastic MapReduce 集群
  • 亚马逊工作区
  • ...很可能还有其他服务

要获取未使用的安全组列表,您需要查询上述所有服务以发现哪些是 "in use"。

或者,您可以尝试删除它们——如果您尝试删除正在使用的安全组,则会生成错误。 (但请在删除重要安全组之前测试此方法!)

手动过程:复制安全组 ID

go to network interface in ec2 console and paste SG Here in n/w interface see whether attached any ENI