Last active
May 3, 2025 02:52
-
-
Save murarisumit/950c12998440c4c4bef0 to your computer and use it in GitHub Desktop.
Boto fetch all running instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pprint import pprint | |
from boto import ec2 | |
def main(): | |
ec2conn=ec2.connect_to_region('us-east-1') | |
reservations=ec2conn.get_all_instances(filters={"tag:tag_name": "value",'instance-state-name' : 'running'}}) | |
output=[] | |
for reservation in reservations: | |
#instance is a list. type is <resultset>, a modified version of python LIST | |
resultset=reservation.instances | |
#Get instance object | |
instance=resultset[0] | |
newEntry=instance.private_ip_address+"("+instance.tags['Name']+" )" | |
print newEntry | |
output.append(str(newEntry)) | |
#pprint(output) | |
if __name__ = __main__: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment