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?

CloudWatch Logsのリソースポリシーのサイズ制限(文字数5120文字以内)に注意

0
Posted at

事象

Route53ログクエリ出力がCloudWatchロググループに「AccessDeniedException 400」のエラーが出てしまい出力設定できない。が、S3への出力はできる。
でも可読性の観点からCloudWatchロググループに出力したい!

エラー内容

表示されたエラー内容は以下。
権限が足りないのか?なんなのか?
※Trace IDは仮置きです

不正なリクエストです。 (AccessDeniedException 400: [RSLVR-01605] Missing permission to log:* Trace Id: "xxxxxxxxxxxxxxxxxxxxxxxxx")

原因

CloudWatch Logs のリソースポリシーには、文字数 5120 文字という制限がある中、現在のリソースポリシー (Sid: AWSLogDeliveryWrite20150319) の文字数は 5078 文字であった・・・

5120 文字のサイズ制限を超過するまたは近づいているために、クエリログ記録の設定の際に自動的にリソースポリシーを設定することができなかった・・・

対処方法

リソースポリシー (Sid: AWSLogDeliveryWrite20150319) の文字数を削減し、Route 53 Resolver のクエリログのためのリソースポリシーを設定できるように対応が必要。

というのも、現在の環境のリソースポリシー(Sid: AWSLogDeliveryWrite20150319)のResourceブロックには、複数のロググループが設定されている。

以下のように共通するポリシーの箇所をワイルドカードで置き換える!

  • 変更前
(省略)
"arn:aws:logs:ap-northeast-1:アカウントID:log-group:/aws/transfer/s-xxxxxxxxxxxxx:log-stream:*",
"arn:aws:logs:ap-northeast-1:アカウントID:log-group:/aws/transfer/s-yyyyyyyyyyyyy:log-stream:*",
"arn:aws:logs:ap-northeast-1:アカウントID:log-group:/aws/transfer/s-zzzzzzzzzzzzz:log-stream:*",
(省略)
  • 変更後
(省略)
"arn:aws:logs:ap-northeast-1:アカウントID:log-group:/aws/transfer/*:*",
(省略)

手順

  1. CloudShellを開き、resource-policy.jsonを作成
nano resource-policy.json
  1. 以下の内容を記載
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AWSLogDeliveryWrite",
            "Effect": "Allow",
            "Principal": {
                "Service": "delivery.logs.amazonaws.com"
            },
            "Action": [
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": [
                "arn:aws:logs:ap-northeast-1:アカウントID:log-group:/aws/transfer/*:log-stream:*"
            ],
            "Condition": {
                "StringEquals": {
                    "aws:SourceAccount": "アカウントID"
                },
                "ArnLike": {
                    "aws:SourceArn": "arn:aws:logs:ap-northeast-1:アカウントID:*"
                }
            }
        }
    ]
}
  1. 既存のポリシーを置き換え
aws logs put-resource-policy --policy-name AWSLogDeliveryWrite20150319 --policy-document file://resource-policy.json

結果

無事CloudWatch Logsへログ出力できるようになりました

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?