forked from openedx-unsupported/configuration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish_rds_logs_to_cloudwatch.py
executable file
·65 lines (57 loc) · 2.5 KB
/
publish_rds_logs_to_cloudwatch.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python3
"""
Publish RDS logs to cloudwatch
Example:
./publish_rds_logs_to_cloudwatch --db_engine mysql --db_identifier edx-mysql-db
./publish_rds_logs_to_cloudwatch --db_engine aurora --db_identifier edx-aurora-cluster
"""
from __future__ import absolute_import
from __future__ import print_function
import boto3
import argparse
def get_client():
rds_client = boto3.client('rds')
return rds_client
def publish_rds_logs_to_cloudwatch(db_engine,db_identifier,logs_to_publish):
client = get_client()
try:
if db_engine == "mysql":
response = client.modify_db_instance(
DBInstanceIdentifier=db_identifier,
CloudwatchLogsExportConfiguration={
'EnableLogTypes': [
logs_to_publish
]
}
)
if response["ResponseMetadata"]["HTTPStatusCode"] == 200:
id=response["DBInstance"]["DBInstanceIdentifier"]
logs_exports_to_cloudwatch=response["DBInstance"]["EnabledCloudwatchLogsExports"]
print(("RDS MySQL DB {} logs {} are enabled to exports to cloudwatch" \
.format(id,logs_exports_to_cloudwatch)))
elif db_engine == "aurora":
response = client.modify_db_cluster(
DBClusterIdentifier=db_identifier,
CloudwatchLogsExportConfiguration={
'EnableLogTypes':[
logs_to_publish
]
}
)
if response["ResponseMetadata"]["HTTPStatusCode"] == 200:
id=response["DBCluster"]["DBClusterIdentifier"]
logs_exports_to_cloudwatch=response["DBCluster"]["EnabledCloudwatchLogsExports"]
print(("RDS Aurora Cluster {} logs {} are enabled to exports to cloudwatch" \
.format(id,logs_exports_to_cloudwatch)))
else:
print("db_engine valid options are: mysql or aurora")
exit()
except Exception as e:
print(e)
if __name__=="__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--db_engine', help='RDS engine: mysql or aurora',required=True)
parser.add_argument('--db_identifier', help='RDS instance ID',required=True)
parser.add_argument('--logs_to_publish',help='Logs to export to cloudwatch',default='error')
args = parser.parse_args()
publish_rds_logs_to_cloudwatch(args.db_engine,args.db_identifier,args.logs_to_publish)