Help us understand the problem. What is going on with this article?

[JAWS-UG CLI] CloudWatch Logs:#9 サブスクリプションフィルタの作成

More than 3 years have passed since last update.

前提条件

CloudWatch Logsへの権限

CloudWatch Logsに対してフル権限があること。

AWS CLI

以下のバージョンで動作確認済

  • AWS CLI 1.11.28
コマンド
aws --version
結果(例)
      aws-cli/1.11.7 Python/2.7.11 Darwin/15.6.0 botocore/1.4.64

バージョンが古い場合は最新版に更新しましょう。

コマンド
sudo -H pip install -U awscli

0. 準備

AWS IDの取得

変数の設定
AWS_ID=$( \
        aws sts get-caller-identity \
          --query 'Account' \
          --output text \
) \
        && echo ${AWS_ID}

結果(例)

  XXXXXXXXXXXX

0.2. ロググループの指定

変数の設定
LOGS_GROUP_NAME='RDSOSMetrics'

1. 事前作業

1.1. ログフィルタの指定

変数の設定
LOGS_FILTER_NAME='datadog'
LOGS_FILTER_PATTERN=''

1.2. サブスクリプション先の指定

変数の設定
LOGS_DEST_ARN="arn:aws:lambda:${AWS_DEFAULT_REGION}:${AWS_ID}:function:${LAMBDA_FUNC_NAME}" \
        && echo ${LOGS_DEST_ARN}

2. サブスクリプションフィルタ作成

サブスクリプションフィルタを作成します。

変数の確認
cat << ETX

        LOGS_GROUP_NAME:      ${LOGS_GROUP_NAME}
        LOGS_FILTER_NAME:     ${LOGS_FILTER_NAME}
        LOGS_FILTER_PATTERN: "${LOGS_FILTER_PATTERN}"
        LOGS_DEST_ARN:        ${LOGS_DEST_ARN}

ETX
コマンド
aws logs put-subscription-filter \
        --log-group-name ${LOGS_GROUP_NAME} \
        --filter-name ${LOGS_FILTER_NAME} \
        --filter-pattern "${LOGS_FILTER_PATTERN}" \
        --destination-arn ${LOGS_DEST_ARN}

結果(例):

  (戻り値なし)

3. 事後作業

コマンド
aws logs describe-subscription-filters \
        --log-group-name ${LOGS_GROUP_NAME} \
        --filter-name-prefix ${LOGS_FILTER_NAME}

結果(例):

  {
    "subscriptionFilters": [
      {
          "filterName": "datadog",
          "destinationArn": "arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:function:datadog_process_rds_metrics-20161212",
          "creationTime": 1481613928175,
          "filterPattern": "",
          "logGroupName": "RDSOSMetrics"
      }
    ]
  }

完了

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away