0
0

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 5 years have passed since last update.

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

Posted at

前提条件

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
  1. 準備
    ===========

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}
  1. サブスクリプションフィルタ作成
    =================================

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

変数の確認
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}

結果(例):

  (戻り値なし)
  1. 事後作業
    ===========
コマンド
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"
      }
    ]
  }

完了

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?