aws cliでRDSのログを取得する
事前準備
IAMロールに下記のpolicyを作成し、割り当てる
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"rds:DownloadDBLogFilePortion",
"rds:DownloadCompleteDBLogFile",
"rds:DescribeDBLogFiles"
],
"Resource": "arn:aws:rds:*:1234567890:db:*"
}
]
}
RDSのパラメータグループの設定
- log_output = FILE
- slow_query = 1
- general_log = 1 #(必要によって有効にする)
ログの取得
ログの一覧を取得
全体
aws rds describe-db-log-files --db-instance-identifier DB識別子名
slow
aws rds describe-db-log-files --db-instance-identifier DB識別子名 --filename-contains slow --output text
DESCRIBEDBLOGFILES 1710393600550 slowquery/mysql-slowquery.log 850
DESCRIBEDBLOGFILES 1710392402586 slowquery/mysql-slowquery.log.2024-03-14.5 510
general
aws rds describe-db-log-files --db-instance-identifier DB識別子名 --filename-contains general --output text
DESCRIBEDBLOGFILES 1710393794063 general/mysql-general.log 64426397
DESCRIBEDBLOGFILES 1710392403842 general/mysql-general.log.2024-03-14.5 4084579
error
aws rds describe-db-log-files --db-instance-identifier DB識別子名 --filename-contains error --output text | head
DESCRIBEDBLOGFILES 1710393802367 error/mysql-error.log 183643
DESCRIBEDBLOGFILES 1710393600670 error/mysql-error-running.log 1394446
DESCRIBEDBLOGFILES 1709200801186 error/mysql-error-running.log.2024-02-29.10 31188
ログの取得
slow
aws rds download-db-log-file-portion --db-instance-identifier DB識別子名 --log-file-name slowquery/mysql-slowquery.log --output text | less
general
aws rds download-db-log-file-portion --db-instance-identifier DB識別子名 --log-file-name general/mysql-general.log --output text | less
error
aws rds download-db-log-file-portion --db-instance-identifier DB識別子名 --log-file-name error/mysql-error.log --output text | less