Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boto3 aws remove all inbound security group rules

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

like image 985
vanquish Avatar asked Mar 18 '17 20:03

vanquish


People also ask

How do I delete inbound rules in AWS?

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.

How do I delete all security groups in AWS?

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.

How do I remove a security group from an EC2 instance?

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.


1 Answers

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

like image 143
helloV Avatar answered Oct 26 '22 12:10

helloV