-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistRDSInstancesInAWS.py
41 lines (36 loc) · 1.49 KB
/
listRDSInstancesInAWS.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
40
41
import boto3
import sys
import logging
import argparse
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[
logging.FileHandler("debug.log"),
logging.StreamHandler()
]
)
def list_instances():
client = boto3.client('rds')
instances = client.describe_db_instances()
columns_format="%-3s %-20s %-60s %-12s %-7s %-8s %-8s %-12s"
logging.info(columns_format % ("num", "Identifier", "Endpoint Address", "Class", "Engine", "Version", "MultiAZ","Status"))
num = 1
for n in range(len(instances.get('DBInstances'))):
logging.info(columns_format % (
num,
instances.get('DBInstances')[n].get('DBInstanceIdentifier'),
instances.get('DBInstances')[n].get('Endpoint').get('Address'),
instances.get('DBInstances')[n].get('DBInstanceClass'),
instances.get('DBInstances')[n].get('Engine'),
instances.get('DBInstances')[n].get('EngineVersion'),
instances.get('DBInstances')[n].get('MultiAZ'),
instances.get('DBInstances')[n].get('DBInstanceStatus')
))
num = num + 1
def main():
parser = argparse.ArgumentParser(description='List all the RDS instances')
arg = parser.parse_args()
list_instances()
if __name__ == '__main__':
sys.exit(main())