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?
Advertisement
Answer
To access the subnets collection of ec2
resource,
subnets = list(ec2.subnets.filter(Filters=filters))