-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlambda_function.py
39 lines (25 loc) · 1.14 KB
/
lambda_function.py
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
36
37
38
39
import json
import boto3
def lambda_handler(event, context):
client = boto3.client('rds')
response = client.describe_db_instances()
# Find ARN of Every DB Instances
for items in response['DBInstances']:
res = client.list_tags_for_resource(
ResourceName = items['DBInstanceArn']
)
# Flag is used for check flag present in DB Instance
flag1 = False
# Check Flag present in given DB Instance
for tag in res['TagList']:
if tag['Key'] == 'Tag1' and tag['Value'] == 'Value1':
flag1 = True
# If flag is True We need to stop Instance
if flag1 :
# To Stop RDS Cluster
if 'DBClusterIdentifier' in items:
Res = client.stop_db_cluster(DBClusterIdentifier=items['DBClusterIdentifier'])
print('Response for Cluster Stop Call: ', Res)
else:
Res = stop_db_instance(DBInstanceIdentifier = items['DBInstanceIdentifier'])
print('Response for Instance Stop Call: ', Res)