Skip to content

Instantly share code, notes, and snippets.

@kkung
Last active September 22, 2017 14:24
Show Gist options
  • Save kkung/9362034 to your computer and use it in GitHub Desktop.
Save kkung/9362034 to your computer and use it in GitHub Desktop.
Getting AWS RDS Log files
$ 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
# -*- 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])
@kkung
Copy link
Author

kkung commented Mar 5, 2014

@vasiliyb
Copy link

Should catch on except boto.exception.BotoServerError:for AWS API rate exceptions

@vasiliyb
Copy link

potentially you may be missing log entries, need to specify marker to conn.get_log_file method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment