簡體   English   中英

boto3列出AWS賬戶的所有安全組

[英]boto3 list all security groups for AWS account

有什么辦法可以使用boto3列出所有AWS安全組?

使用此代碼,我只能獲得5組(該地區25個組)

client = boto3.client('ec2')

response=client.describe_security_groups(



)
print response

我有4個VPC,因此我嘗試獲取每個VPC的組,將其添加為過濾器:

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

但結果我得到了這個:

{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'}}}

嘗試按區域進行過濾並得到: The filter 'region' is invalid

但是,使用AWS CLI可以:

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

這是否意味着我需要堅持使用AWS CLI或boto3具有列出AWS賬戶的所有安全組的語法?

您可能正在描述其他地區的資源。 這是事情沒有出現的普遍原因。

您可以如下設置區域:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM