How to delete default egress rule in a specific security group using boto

621 views
Skip to first unread message

Andy Andy

unread,
Aug 9, 2015, 9:13:24 AM8/9/15
to boto-users
Hi everyone,

I notice there is always a default outbound rule once a security group is created. 
The rule's type is 'All traffic' with Protocol 'All'.
How should i delete this default rule using boto?

I tried

>>> group = c.revoke_security_group_egress(group.id,'All')

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    group = c.revoke_security_group_egress(group.id,'All')
  File "C:\Python27\lib\site-packages\boto-2.38.0-py2.7.egg\boto\ec2\connection.py", line 3447, in revoke_security_group_egress
    params, verb='POST')
  File "C:\Python27\lib\site-packages\boto-2.38.0-py2.7.egg\boto\connection.py", line 1227, in get_status
    raise self.ResponseError(response.status, response.reason, body)
EC2ResponseError: EC2ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidParameterValue</Code><Message>Invalid value 'All' for IP protocol. Unknown protocol.</Message></Error></Errors><RequestID>105afe65-1a4e-42a3-b754-1fc519c54ca4</RequestID></Response>

Please help me take a look at this issue.
Thanks,

Best wishes,
Andy

krishnak...@reancloud.com

unread,
Nov 25, 2015, 10:31:32 AM11/25/15
to boto-users
you can use following snippet 

import boto.ec2
conn = boto.ec2.connect_to_region("us-west-2")
groups = conn.get_all_security_groups(filters={'group-name': ['SG-Name']})[0]
for rule in groups.rules_egress:
        for grant in rule.grants:
                conn.revoke_security_group_egress(groups.id,rule.ip_protocol,rule.from_port,rule.to_port,grant.group_id,grant.cidr_ip)
Reply all
Reply to author
Forward
0 new messages