forked from znudevops/shell-scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_tag_fetch.py
More file actions
35 lines (28 loc) · 1.12 KB
/
lambda_tag_fetch.py
File metadata and controls
35 lines (28 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import boto3
def lambda_handler(event, context):
value = list_instances_by_tag_value("intl_scheduler_id","1")
print(value)
def list_instances_by_tag_value(tagkey,tagvalue):
# When passed a tag key, tag value this will return a list of InstanceIds that were found.
ec2client = boto3.client('ec2')
response = ec2client.describe_instances(
Filters=[
{
'Name': 'tag:'+tagkey,
'Values': [tagvalue]
}
]
)
instancelist = []
for reservation in (response["Reservations"]):
for instance in reservation["Instances"]:
name = ""
scheduler_value = ""
for instancetag in instance['Tags']:
# instancelist.append(instancetag)
if instancetag['Key'] == 'Name':
name = instancetag['Value']
if instancetag['Key'] == 'intl_scheduler':
scheduler_value = instancetag['Value']
instancelist.append({"Server_name": name, "SDT_scheduler_value": scheduler_value })\
return instancelist