Search code examples
amazon-web-servicesaws-sdkboto3

boto3 equivalent to gather all aws security groups


With the old version of boto you could pull all security groups inside an aws account with something like:

import boto.ec2
conn = boto3.connect_to_region("us-east-1")
groups = conn.get_all_security_groups()

However with boto3 the documentation isn't clear how to perform the same action. There's numerous references here dealing with changing policies with the new boto3 package, but not a mechanism to list all security groups and policies.

Is there a new method for this operation?


Solution

  • Boto3 provides a low level client which has almost identical method names that you can find in AWS API.
    So to get ( or in aws context usually called describe ) you can do the following:

    import boto3
    client = boto3.client('ec2')
    client.describe_security_groups()
    

    More info here: http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.describe_security_groups