aws boto3抓取子网

2024-05-17 04:02:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从aws获取子网列表,我有一个VPC的工作版本,我已经修改了:

ec2 = boto3.resource('ec2')
client = boto3.client('ec2')

filters = [{'Name':'tag:Name', 'Values':['*']}]
subnets = list(ec2.Subnet.filter(Filters=filters))

for subnet in subnets:
    response = client.describe_subnets(
        VpcIds=[
            vpc.id,
        ]
    )
    print(response['Subnets'])

我不断得到:

subnets = list(ec2.Subnet.filters(Filters=filters)) AttributeError: 'function' object has no attribute 'filters'

从我阅读的所有内容和其他例子来看,这应该是有效的

有什么想法吗?


Tags: name版本clientaws列表responseboto3ec2