I need to remove all security group rules from a security group. I' getting the rules by using:
import boto3
ec2 = boto3.resource('ec2')
sg = ec2.SecurityGroup('sg-someID')
sg.ip_permissions
but I'm not sure how to loop through it using the revoke_ingress command
Sign in to the AWS Management Console and open the Amazon VPC console at https://console.aws.amazon.com/vpc/ . In the navigation pane, under Network Firewall, choose Network Firewall rule groups. In the Network Firewall rule groups page, select the name of the rule group that you want to delete, and then choose Delete.
Open the Amazon VPC console at https://console.aws.amazon.com/vpc/ . In the navigation pane, choose Security Groups. Select one or more security groups and choose Actions, Delete security groups.
To delete a security groupOpen the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Security Groups. Select a security group and choose Actions, Delete Security Group. Choose Yes, Delete.
Just call revoke_ingress()
and pass the rules you want to delete. Since you want to delete all rules, pass the entire rules array.
sg.revoke_ingress(IpPermissions=sg.ip_permissions)
From: revoke_ingress
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With