gpt4 book ai didi

python-3.x - 无法删除安全组: An error occurred (DependencyViolation) when calling the DeleteSecurityGroup operation

转载 作者:行者123 更新时间:2023-12-03 08:46:36 24 4
gpt4 key购买 nike

我正在尝试删除具有 0 个接口(interface)且未在使用 boto3 的任何其他安全组的入口规则中引用的安全组。但我收到错误:调用DeleteSecurityGroup操作时发生错误(DependencyViolation):资源sg-XXYYZZ有依赖对象

我想要一个代码来列出引用安全组 sg-XXYYZZ 的入口规则,并在删除安全组之前使用 boto3 删除这些入口规则:response = ec2.delete_security_group( GroupId=sg, DryRun=False )

我使用以下方式列出入口规则:

    for sg in final_del_list:
response = ec2.describe_security_groups( GroupIds=[sg] )
print( "\n\n Security Group:", sg )
for res in response['SecurityGroups']:
msg = "The Ingress rules are as follows: " if len(res['IpPermissions']) > 0 else "No ingress rules"
print( msg )
for ip in res['IpPermissions']:
print( "IP Protocol: ", ip['IpProtocol'] )
try:
print( "PORT: ", str( ip['FromPort'] ) )
for range in ip['IpRanges']:
print( "IP Ranges: ", range['CidrIp'] )
except Exception:
print( "No value for ports and ip ranges available for this security group" )

有人可以指导我如何在其入口规则中列出引用 sg-XXYYZZ 的安全性或帮助我解决错误

最佳答案

通过查看您的错误:调用DeleteSecurityGroup操作时发生错误(DependencyViolation):资源sg-XXYYZZ有一个依赖对象

到目前为止,我可以在这里提出一些建议,而不是编写代码。1. 如果安全组与任何其他实例关联,即使实例处于停止状态,也无法进行安全组。2. 这可能看起来是一个孤立的安全组,但它可能与附加到实例的另一个安全组相关联。因此,您需要先编辑该安全组,然后才能删除指定的安全组。

我写了一个这样的script in github这可能对你有帮助

关于python-3.x - 无法删除安全组: An error occurred (DependencyViolation) when calling the DeleteSecurityGroup operation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61236712/

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