21
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CloudWatch Logsのログをローカル環境にダウンロードする

Last updated at Posted at 2020-12-29

概要

CloudWatch Logsコンソールからログを収集する作業が地味にきついのでツールを作りました。

ソースコード

特徴

  • dockerベースなのでセットアップ手間いらず
  • ロググループを指定することで、ログストリームを跨いだ検索が可能
  • 正規表現に一致したメッセージのみ抽出可能
  • 出力フォーマットはJSON形式

使い方

ロググループ ecs/production における2020年12月27日 15時59分 (UTC) のログを取得する場合。

$ docker run --rm -it --env-file=.env -v ${PWD}:/go/src/app cld -group=ecs/production-log -start="2020-12-27 15:59:00" -end="2020-12-27 15:59:59"

2020/12/29 07:05:42 Write results...
2020/12/29 07:05:42 Generated log file: ./dist/result_2020122970533.log

$ cat ./dist/result_2020122970533.log
[
  {
    "IngestionTime": "2020-12-27 15:59:22 +0000 UTC",
    "LogStream": "app/app/5302adeb527b42a0acbb11ac3444d98f",
    "Message": "Foo",
    "Timestamp": "2020-12-27 15:59:21 +0000 UTC"
  },
  {
    "IngestionTime": "2020-12-27 15:59:22 +0000 UTC",
    "LogStream": "app/app/5302adeb527b42a0acbb11ac3444d98f",
    "Message": "Bar",
    "Timestamp": "2020-12-27 15:59:21 +0000 UTC"
  },
  {
    "IngestionTime": "2020-12-27 15:59:22 +0000 UTC",
    "LogStream": "app/app/5302adeb527b42a0acbb11ac3444d98f",
    "Message": "Baz",
    "Timestamp": "2020-12-27 15:59:21 +0000 UTC"
  },
  ...
]
21
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?