LoginSignup
10
7

More than 3 years have passed since last update.

CloudWatchLogsのログをElasticSearchに流す

Posted at

概要

CloudWatchLogsからElasticSearchにログを流します。
ログを流す際にLambdaを経由する形になります。

スクリーンショット_2019-11-01_14_49_39.jpg

CloudWatchLogsのアクションからロググループを選んで「Amazon Elasticsearch Serviceへのストリーム」を選択します。

あとは画面に従って設定するだけです。

注意点

ロール

VPC内のElasticSearchに書き込みたい場合はLambdaにAWSLambdaVPCAccessExecutionRoleをつけましょう。

セキュリティーグループ

ElasticSearchにアクセスできるようにセキュリティグループを設定してください。

Lambdaの関数が古い

ElasticSearchにCloudWatchLogsのログを投げるNode.jsで書かれているLambdaの関数がES7.xに対応していないのでLogの流し込みに失敗する場合があります。

具体的にはElasticSearchのindexのマッピングをdynamicではなく、自分で指定した場合に、index._typeがlogEvent.logGroupとなっていますが、ElasticSearch7.xでは複数の_typeに対応していないために落ちます。ここは

        var action = { "index": {} };
        action.index._index = indexName;
        action.index._type = '_doc'; // changed for ES 7.x
        action.index._id = logEvent.id;

として、変更しておきます。

10
7
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
10
7