页面删除vpc时,resource sg-096098d152c41a58d has a dependent object
根据手册逐一排查删除安全组 sg-096098d152c41a58d
时仍然遇到 DependencyViolation
错误,表示该安全组与某些资源仍然存在关联。以下是进一步排查和解决此问题的步骤:
1. 检查依赖关系
a. EC2 实例
确保没有 EC2 实例使用该安全组:
aws ec2 describe-instances --filters "Name=instance.group-id,Values=sg-096098d152c41a58d" --query "Reservations[].Instances[].InstanceId" --output text
b. 弹性网络接口(ENI)
检查是否有网络接口与该安全组关联:
aws ec2 describe-network-interfaces --filters "Name=group-id,Values=sg-096098d152c41a58d" --query "NetworkInterfaces[].NetworkInterfaceId" --output text
c. RDS 实例
确认没有 RDS 实例使用该安全组:
aws rds describe-db-instances --query "DBInstances[?contains(VpcSecurityGroups[].VpcSecurityGroupId, 'sg-096098d152c41a58d')].DBInstanceIdentifier" --output text
d. 负载均衡器
检查是否有负载均衡器使用该安全组:
aws elbv2 describe-load-balancers --query "LoadBalancers[?contains(SecurityGroups, 'sg-096098d152c41a58d')].LoadBalancerArn" --output text
e. Lambda 函数
确认没有 Lambda 函数使用该安全组(如果它们在 VPC 中):
aws lambda list-functions --query "Functions[?VpcConfig.SecurityGroupIds[?contains(@, 'sg-096098d152c41a58d')]].FunctionName" --output text
但是都是空的
还是先看看安全组的描述先
aws ec2 describe-security-groups --group-ids sg-096098d152c41a58d
得到一个描述
{
"SecurityGroups": [
{
"Description": "Security group attached to database-4 to allow EC2 instances with specific security groups attached to connect to the database. Modification could lead to connection loss.",
"GroupName": "rds-ec2-2",
"IpPermissions": [],
"OwnerId": "043942809940",
"GroupId": "sg-096098d152c41a58d",
"IpPermissionsEgress": [],
"VpcId": "vpc-01af842d907c8b31a"
}
]
}
但是查看RDS,没有任何实例和资源残留
aws的提示太费解了,只能提工单咨询下了,好在下午反馈就回来了
结果就是他建议把default也删除,但是这个也无法删除,陷入循环了,回信还是个无效地址只能再去提一个工单
-------------
终于收到客服邮件回复了
由于 sg-0d86b6f74d768069f 是默认安全组因此您是无法删除的,这是个预期行为,由于有依存关系因此会建议您进行以下操作:
1. 删除所有 sg-0d86b6f74d768069f 里的规则,不必删除安全组
2. 删除 sg-096098d152c41a58d 安全组
3. 删除您的 vpc-01af842d907c8b31a
按照提示把default安全组上的入站和出站规则都清空
这时候再回过头来删除要删除的安全组,果然成功了
关于安全组是是如何嵌套依赖的我实在回忆不起来了, 不过aws对vpc的依赖提示确实不能不让人吐槽,有时候只能提工单解决