I'm trying to figure out how to find route_table_id based upon a subnet_id(in a vpc) using boto3. There is api in boto3(v1.3.1), ec2.RouteTableAssociation(id). With correct route_table_association_id, try to access the resource's attribute route_table_id, it gives exception as below:
In [19]: rta.route_table_id
---------------------------------------------------------------------------
ResourceLoadException Traceback (most recent call last)
<ipython-input-19-a7f51e66ef03> in <module>()
----> 1 rta.route_table_id
/usr/local/lib/python2.7/site-packages/boto3/resources/factory.pyc in property_loader(self)
341 else:
342 raise ResourceLoadException(
--> 343 '{0} has no load method'.format(self.__class__.__name__))
344
345 return self.meta.data.get(name)
ResourceLoadException: ec2.RouteTableAssociation has no load method
I'm looking for a clue why this failed.
James
1 Answer. You can do this very easily using the boto3 library. all you need is to create a list of ids of all the ec2 instances you wish to terminate. Then using the filter method pass in that list of ids as a keyworded argument named InstanceIds and call the terminate method on the returned value and you are done.
figure out to do this way:
response = client.describe_route_tables(
Filters=[
{
'Name': 'association.subnet-id',
'Values': [
source_subnet_id
]
}
]
)
print(response['RouteTables'][0]['Associations'][0]['RouteTableId'])
Try describe_route_tables.
All required info is under the responding JSON ['RouteTables'][*]["Associations"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With