Issue
Using boto in Python, how can I find the boto.ec2 instance object given an IP address?
id='dv4'>
Solution
Digging through the boto documentation, I found the get_only_instances
method, which you use to get all instances. You can pass a filter dictionary to it, to filter by IP Address (I found this in the EC2 API Reference under the Filter.N title).
So for example, to get the instance with IP 1.1.1.1
, you would do:
filters = {"ip-address": "1.1.1.1"}
result_list = conn.get_only_instances(filters=filters)
Then result_list[0]
should be the Instance object for the instance with that IP address.
Answered By - alonsovb Answer Checked By - Terry (WPSolving Volunteer)