Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws boto3 grab subnet info

Im trying to grab a list of subnets from aws, I have a working version for VPC that I have modified:

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'])

I keep getting:

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

From everything im reading and other examples this should work

Any ideas?

like image 204
ben Avatar asked Jan 17 '17 13:01

ben


1 Answers

To access the subnets collection of ec2 resource,

subnets = list(ec2.subnets.filter(Filters=filters))
like image 148
franklinsijo Avatar answered Sep 28 '22 12:09

franklinsijo