$ python get_logs.py rds-db-instance-name rds.log aws-access-key aws-secret-key
$ ./pgbadger -p '%t:%r:%u@%d:[%p]:' ./rds.log
$ open out.html
-
-
Save jmlrt/5062a06fdf0d322f259056d17524f480 to your computer and use it in GitHub Desktop.
Getting AWS RDS Log files
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 characters
# -*- encoding: utf-8 -*- | |
import sys | |
import boto.rds | |
AWS_REGION = 'ap-northeast-1' | |
def get_all_logs(dbinstance_id, output, max_records=None, | |
aws_access_key_id=None, aws_secret_access_key=None): | |
conn = boto.rds.connect_to_region( | |
AWS_REGION, | |
aws_access_key_id=aws_access_key_id, | |
aws_secret_access_key=aws_secret_access_key) | |
with open(output, 'w') as f: | |
for log_file in conn.get_all_logs(dbinstance_id, | |
max_records=max_records): | |
print 'Download %s(%d)' % (log_file.log_filename, | |
int(log_file.size)) | |
try: | |
log = conn.get_log_file(dbinstance_id, log_file.log_filename) | |
try: | |
f.write(log.data) | |
except AttributeError: | |
pass | |
except: | |
print 'Error while download %s' % log_file.log_filename | |
if __name__ == '__main__': | |
get_all_logs(dbinstance_id=sys.argv[1], | |
output=sys.argv[2], | |
aws_access_key_id=sys.argv[3], | |
aws_secret_access_key=sys.argv[4]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment