S3 に5分毎に出力される AWS LB ログファイルを時間帯を指定してまとめてダウンロード

概要

AWS で LB のログを S3 に保存設定をしている場合に、 インシデントがあった時間帯のログがまとめて欲しいという時に awscli でまとめてログ取得しています。

その時の手順を備忘録としてまとめました。

事前準備

  • awscli インストール

本件の実行環境は以下になります。

macOS%$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.12.6
BuildVersion:   16G1036

macOS%$ aws --version
aws-cli/1.15.50 Python/3.7.0 Darwin/16.7.0 botocore/1.10.49

ログファイルダウンロード

例) 2018年9月12日 14時台の ALB ログファイルをダウンロード

// 2018年9月12日 14時台のログファイルをダウンロード
macOS%$ aws s3 --profile <profile> cp s3://<log bucket name>/<lb name>/AWSLogs/123456789012/elasticloadbalancing/ap-northeast-1/2018/09/12/ . --recursive --exclude "*" --include "*20180912T05*"

// ログファイル解凍
gunzip *.gz

// log を1ファイルにまとめ
cat *.log > all.log

// HTTP コードが 50x のものを 50x.log にまとめる
awk '{if($9 ~ 50) print $0}' all.log > 50x.log

`--profile <profile>` は `aws configure --profile <profile>` で設定した場合の設定です。
default を利用する場合は `--profile <profile>` の指定は不要です。

以上です。

S3 に5分毎に出力される AWS LB ログファイルを時間帯を指定してまとめてダウンロード

https://kenzo0107.github.io/2018/09/11/2018-09-12-s3-5-aws-lb/

Author

Kenzo Tanaka

Posted on

2018-09-12

Updated on

2020-05-07

Licensed under

コメント