简体   繁体   English

boto3列出AWS账户的所有安全组

[英]boto3 list all security groups for AWS account

Is there any way to list all AWS security groups using boto3 ? 有什么办法可以使用boto3列出所有AWS安全组?

With this code i can get only 5 groups (out of 25 in region) 使用此代码,我只能获得5组(该地区25个组)

client = boto3.client('ec2')

response=client.describe_security_groups(



)
print response

I have 4 VPC's so i tried to get groups for each VPC, added this as filter: 我有4个VPC,因此我尝试获取每个VPC的组,将其添加为过滤器:

Filters=[
        {
            'Name': 'vpc-id',
            'Values': [
                'vpc-d60ee9b1',
            ]
        },
    ],

But as results i got this: 但结果我得到了这个:

{u'SecurityGroups': [], 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '44f39633-4f21-4c4f-b3f4-82fbce538c5f', 'HTTPHeaders': {'transfer-encoding': 'chunked', 'vary': 'Accept-Encoding', 'server': 'AmazonEC2', 'content-type': 'text/xml;charset=UTF-8', 'date': 'Thu, 03 May 2018 08:25:03 GMT'}}}

Tried to filter by region and got: The filter 'region' is invalid 尝试按区域进行过滤并得到: The filter 'region' is invalid

However, with AWS CLI it works: 但是,使用AWS CLI可以:

aws ec2 describe-security-groups --region $REGION

Does it means i need to stick with AWS CLI or boto3 has syntax to list ALL security groups for AWS account ? 这是否意味着我需要坚持使用AWS CLI或boto3具有列出AWS账户的所有安全组的语法?

You may be describing resources in a different region. 您可能正在描述其他地区的资源。 That's a common reason for things not showing up. 这是事情没有出现的普遍原因。

You can set the region as follows: 您可以如下设置区域:

ec2 = boto3.client('ec2', region_name='us-west-2')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM