Last active
September 26, 2017 17:29
-
-
Save renaudhager/3600a3572c1f748536d53e151c5b700f to your computer and use it in GitHub Desktop.
Revisions
-
renaudhager revised this gist
Sep 26, 2017 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import sys import json def get_tag(instance, tag_key): for tag in instance['Tags']: -
renaudhager created this gist
Sep 26, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ #!/usr/bin/python # Usage : # aws ec2 describe-instances --filter="Name=instance-state-name,Values=running" | aws-instances-lookup <tag name> <tag value> import sys import json import subprocess def get_tag(instance, tag_key): for tag in instance['Tags']: if tag['Key'] == tag_key: print tag['Value'] tag_key = sys.argv[1] tag_value = sys.argv[2] instances_id = [] instances_name = [] output = json.load(sys.stdin) reservations = output["Reservations"] for reservation in reservations: instance = reservation['Instances'][0] for tag in instance['Tags']: if tag['Key'] == tag_key: if tag['Value'] == tag_value: instances_id.append(str(instance['InstanceId'])) get_tag(instance, 'Name')