vanquish
vanquish

Reputation: 135

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

Upvotes: 7

Views: 7281

Answers (1)

helloV
helloV

Reputation: 52433

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

Upvotes: 16

Related Questions