gpt4 book ai didi

amazon-web-services - 如何查找未使用的 Amazon EC2 安全组

转载 作者:行者123 更新时间:2023-12-03 05:12:06 26 4
gpt4 key购买 nike

我正在尝试找到一种方法来确定孤立的安全组,以便我可以清理并摆脱它们。有谁知道如何发现未使用的安全组。

通过控制台或使用命令行工具都可以(在 Linux 和 OSX 计算机上运行命令行工具)。

最佳答案

注意:这仅考虑 EC2 中的安全使用,而不考虑 RDS 等其他服务。您需要做更多工作来包含在 EC2 外部使用的安全组。好处是,如果您错过了与另一项服务关联的一项,则您无法轻松(甚至可能不可能)删除事件安全组。

使用较新的 AWS CLI 工具,我找到了一种获得所需内容的简单方法:

首先,获取所有安全组的列表

aws ec2 describe-security-groups --query 'SecurityGroups[*].GroupId'  --output text | tr '\t' '\n'

然后获取与实例绑定(bind)的所有安全组,然后通过管道传送到sort,然后传送到uniq:

aws ec2 describe-instances --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' --output text | tr '\t' '\n' | sort | uniq

然后将其放在一起并比较这两个列表,看看主列表中哪些内容没有被使用:

comm -23  <(aws ec2 describe-security-groups --query 'SecurityGroups[*].GroupId'  --output text | tr '\t' '\n'| sort) <(aws ec2 describe-instances --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' --output text | tr '\t' '\n' | sort | uniq)

关于amazon-web-services - 如何查找未使用的 Amazon EC2 安全组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24685508/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com