python - How to iterate through security groups in AWS ec2? -


i trying iterate through ec2 security groups. have wrote following code connect , security groups:

security_groups = ec2_conn.get_all_security_groups() 

next step need use group id each security group. in loop used code print :

print(security_groups[group_id]) 

i tried many different attributes instead of [group_id] keep getting error :

"nameerror: name 'group_id' not defined"

what right way retrieve or print 1 attribute security groups ?

here working example of how iterate on security groups, , print group ids

import boto ec2_conn = boto.connect_ec2() security_groups = ec2_conn.get_all_security_groups() group in security_groups:     print(group.id) 

some additional information on manipulating security groups: http://boto.readthedocs.org/en/latest/security_groups.html


Comments

Popular posts from this blog

symfony - InvalidConfigurationException in SecurityExtension.php line 429: No authentication listener registered for firewall "secured_area" -

angular ui router - 10 digest iterations reached in angularjs when using $state.go -

javascript - Handling constructor related functions while testing with mocha and sinon -