[アップデート] Amazon EventBridgeのEvent Busでログ出力設定ができるようになりました
コスト効率よくカスタムEvent Busに送信されたイベントのログを出力したい
こんにちは、のんピ(@non____97)です。
皆さんはコスト効率よくカスタムEvent Busに送信されたイベントのログを出力したいなと思ったことはありますか? 私はあります。
「EventBridge Ruleでイベントをトリガーするようにしており、イベントを送信しているはずだが、トリガーしていない」という状況はあるあるです。
そんな時は、EventBridge RuleのターゲットとしてCloudWatch Logsロググループを指定してトラブルシューティングすることが多いのではないでしょうか。
しかし、広範囲なイベントパターンの場合はログ出力量が気になります。また、これはあくまでイベントパターンとマッチしているか否かの確認観点であり、イベントパターンとマッチしているがターゲットを何かしらの原因で呼び出せなかったという時の原因調査として情報が不足してしまいます。
今回、Amazon EventBridgeのEvent Busでログ出力設定ができるようになりました。
AWS Blogにも投稿されています。
これにより、コスト効率よくEvent Busがイベントを受信しているか、マッチするEventBridge Ruleがあるか、正常にターゲットを呼び出せたのかのログを確認することが可能になります。
実際に試したので紹介します。
いきなりまとめ
- Event Bus単位でイベントログの出力設定が可能になった
- ログで確認できる情報例
- Event Busでイベントの受信が成功/失敗した
- イベントがEventBridge Ruleのイベントパターンにマッチした/していない
- ターゲットの呼び出しが成功/失敗した
- ログレベルは以下の4種類
- OFF
- ERROR
- INFO
- TRACE
- ログ出力先は以下の3種類
- CloudWatch Logs
- S3 Bucket
- Data Firehose
- TraceログをS3に、ErrorログをCloudWatch Logに、といったことは現状できない
- ログ出力内容はEvent Busでイベントを出力したことだけでなく、EventBridge Ruleにマッチしたのか、正常にターゲットを呼び出せたのかといったログも出力可能
- 料金はCloudWatch LogsのVended Logsに基づいて請求
- 特定のルールにマッチした場合にのみログ出力したい場合は、EventBridge RuleのターゲットとしてCloudWatcg Logsを指定することになる
ドキュメントを眺める
ログレベル
まずはドキュメントを眺めてみましょう。
情報は以下ドキュメントにまとまっています。
ログレベルは以下の4種類があります。
- OFF
- ERROR
- INFO
- TRACE
各イベントに対してどのログレベルで記録されるのかの表は以下のとおりです。
Step | TRACE | INFO | ERROR | OFF |
---|---|---|---|---|
Event Ingested | x | x | ||
Event Ingestion Failed | x | x | x | |
Event Received | x | |||
Invocation Attempt Started | x | |||
Invocation Attempt Permanent Failure | x | x | x | |
Invocation Attempt Retry-able Failure | x | x | x | |
Invocation Attempt Succeeded | x | |||
Invocation Attempt Throttled | x | x | x | |
Invocation DLQ | x | x | x | |
Invocation Failed | x | x | x | |
Invocation Started | x | x | ||
Invocation Succeeded | x | x | ||
Invocation Throttle Started | x | x | x | |
No Rules Matched | x | x | ||
Rule Matched | x | x | ||
Rule Matching Started | x |
抜粋 : Configuring logs for Amazon EventBridge event buses - Amazon EventBridge
TRACEにした場合は、Event Busで受け取った全ての受信イベントを記録するため、それなりのログ量になるでしょう。
図示すると以下のとおりです。
抜粋 : What Amazon EventBridge logs for event buses - Amazon EventBridge
INFOであってもそれなりにログを拾ってくれる印象がありますね。
ログの出力先
ログ出力先は以下の3種類があります。
- CloudWatch Logs
- S3 Bucket
- Data Firehose
CloudWatch Logsの選択肢が増えたことが嬉しいですね。
料金としてはevents:AllowVendedLogDeliveryForResource
のアクションを許可する必要があることから、CloudWatch LogsのVended Logsの料金が適用されると考えます。
2025/7/21時点の東京リージョンでのVended Logsの料金は以下のとおりです。
Data Ingested | CloudWatch Logs Standard | CloudWatch Logs Infrequent Access | Amazon S3 | Amazon Data Firehose |
---|---|---|---|---|
First 10TB per month | $0.76 per GB | $0.38 per GB | $0.38 per GB | $0.38 per GB |
Next 20TB per month | $0.38 per GB | $0.228 per GB | $0.228 per GB | $0.228 per GB |
Next 20TB per month | $0.152 per GB | $0.114 per GB | $0.114 per GB | $0.114 per GB |
Over 50TB per month | $0.076 per GB | $0.076 per GB | $0.076 per GB | $0.076 per GB |
Data Stored | $0.033 per GB compressed* | $0.033 per GB compressed* | See S3 Pricing | N/A |
Format Converted to Apache Parquet | N/A | N/A | $0.056 per GB** | N/A |
抜粋 : Amazon CloudWatch Pricing – Amazon Web Services (AWS)
ログ出力の対象となるイベント
ログ出力の対象となるイベントは以下のとおりです。
- Event BusのEvent Ruleに一致するAWSサービスイベント
- イベントが正常に取り込まれたかどうか、またはルールに一致するかどうかに関係なく、次の方法で配信されるすべてのイベント
- パートナーイベントソースからのイベント
- アーカイブから再生されたイベント
PutEvents
経由でEvent Busに送信されるイベント
AWSサービスイベントについてはEvent Ruleにマッチしたもののみ記録されるとのことなので、defaultのEvent BusでログレベルをTRACEにしても大量のログが出力される訳ではなさそうです。
また、Auto ScalingやAWS Config、GuardDutyといったAWSサービスのマネージドのEventBridge Ruleのログは記録されないようです。
EventBridge does not log events that only match managed rules.
Configuring logs for Amazon EventBridge event buses - Amazon EventBridge
注意点
主な注意点としては以下のとおりです。
- ログ配信はベストエフォート
- 以下については記録されない
- カスタマー管理キーを使用して暗号化されたログレコードがログ送信先に配信される際に生成されるAWS KMSの
Decrypt
およびGenerateDataKey
イベント - Event Busのログ配信によってFirehoseで生成される
PutRecordBatch
イベント
- カスタマー管理キーを使用して暗号化されたログレコードがログ送信先に配信される際に生成されるAWS KMSの
- EventBridge のイベント通知が有効になっているS3 Bucketをログの送信先として指定することは非推奨
他注意点としてはログレコードの最大サイズは1MBであるという点が挙げられます。超過した場合は特定のフィールドを削除します。普段はあまり気にすることはないかと思いますが、実行データを記録するように設定をしていると超過してしまうこともあるでしょう。
Truncating data in event bus logs
Due to log destination constraints, EventBridge limits log records to 1 MB. If a log record exceeds this limit, EventBridge truncates the record by removing the following fields in the following order:
- target_input
- target_properties
- target_response_body
EventBridge removes the event_detail field from the following log record types if necessary:
- EVENT_RECEIVED
- EVENT_INGESTED
- EVENT_INGESTED_FAILED
- RULE_MATCH_STARTED
If truncation is necessary, EventBridge removes the entire field.
If EventBridge does truncate fields in the event, the dropped_fields field includes a list of the excised data fields.
Configuring logs for Amazon EventBridge event buses - Amazon EventBridge
やってみた
カスタムEvent Busの作成
実際に試してみましょう。
まずはカスタムEvent Busの作成をします。
トレースログをCloudWatch LogsとS3 Bucketに出力するように設定します。ログレベルごとにログ出力先を変更することはできないようです。
作成したEvent Busを確認します。ログレベルとログ出力先のリソースの情報が記載されています。
このタイミングでS3 Bucketのバケットポリシーは以下のようになっていました。
{
"Version": "2012-10-17",
"Id": "AWSLogDeliveryWrite20150319",
"Statement": [
{
"Sid": "AWSLogDeliveryWrite1",
"Effect": "Allow",
"Principal": {
"Service": "delivery.logs.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::non-97-eventbridge-log/AWSLogs/<AWSアカウントID>/EventBusLogs/*",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "<AWSアカウントID>",
"s3:x-amz-acl": "bucket-owner-full-control"
},
"ArnLike": {
"aws:SourceArn": "arn:aws:logs:us-east-1:<AWSアカウントID>:delivery-source:EventBusSource-non-97-test-eventbus-ERROR_LOGS"
}
}
},
{
"Sid": "AWSLogDeliveryWrite2",
"Effect": "Allow",
"Principal": {
"Service": "delivery.logs.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::non-97-eventbridge-log/AWSLogs/<AWSアカウントID>/EventBusLogs/*",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "<AWSアカウントID>",
"s3:x-amz-acl": "bucket-owner-full-control"
},
"ArnLike": {
"aws:SourceArn": "arn:aws:logs:us-east-1:<AWSアカウントID>:delivery-source:EventBusSource-non-97-test-eventbus-INFO_LOGS"
}
}
},
{
"Sid": "AWSLogDeliveryWrite3",
"Effect": "Allow",
"Principal": {
"Service": "delivery.logs.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::non-97-eventbridge-log/AWSLogs/<AWSアカウントID>/EventBusLogs/*",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "<AWSアカウントID>",
"s3:x-amz-acl": "bucket-owner-full-control"
},
"ArnLike": {
"aws:SourceArn": "arn:aws:logs:us-east-1:<AWSアカウントID>:delivery-source:EventBusSource-non-97-test-eventbus-TRACE_LOGS"
}
}
}
]
}
各ログレベルごとにステートメントが設定されていますね。
EventBridge Ruleの作成
作成したカスタムEvent BusをソースとするEventBridge Ruleを作成します。
イベントパターンは適当に設定しました。
ターゲットはCloudWatch Logsのロググループを指定します。
他は特に設定せずに作成します。
テストイベントのPUT
テストイベントのPUTをして、どのようなログ出力がされているのか確認をします。
先ほど作成したEventBridge Ruleのイベントパターンとマッチするようにイベント設定を行い、送信します。
イベントが正常に送信されたことを確認します。
Event Busで設定したログ出力先のCloudwatch Logsロググループを確認すると、EventBridgeEventBusLogs
というログストリームが出力されていました。
Event Busごとのログストリームではないため、複数のEvent Busのログ出力先を一つのロググループに集約してしまうと、見づらそうですね。
ログストリームを確認すると、以下のようなログが出力されていました。
{
"resource_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus",
"message_timestamp_ms": 1753148952569,
"event_bus_name": "non-97-test-eventbus",
"request_id": "1d83e007-bd15-44c2-bc9e-943b1a3dbc5e",
"event_id": "7a796044-b1d4-a13b-0e26-54a8a53227d8",
"message_type": "EVENT_RECEIPT",
"log_level": "TRACE",
"details": {
"caller_account_id": "<AWSアカウントID>",
"source_time_ms": 1753148951000,
"source": "event.non-97.net",
"detail_type": "myDetail",
"resources": [],
"event_detail": "{\"message\":\"test\"}"
}
}
{
"resource_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus",
"message_timestamp_ms": 1753148952591,
"event_bus_name": "non-97-test-eventbus",
"request_id": "1d83e007-bd15-44c2-bc9e-943b1a3dbc5e",
"event_id": "7a796044-b1d4-a13b-0e26-54a8a53227d8",
"message_type": "EVENT_INGEST_SUCCESS",
"log_level": "INFO",
"details": {
"caller_account_id": "<AWSアカウントID>",
"source_time_ms": 1753148951000,
"source": "event.non-97.net",
"detail_type": "myDetail",
"resources": [],
"event_detail": "{\"message\":\"test\"}"
}
}
{
"resource_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus",
"message_timestamp_ms": 1753148952605,
"event_bus_name": "non-97-test-eventbus",
"request_id": "1d83e007-bd15-44c2-bc9e-943b1a3dbc5e",
"event_id": "7a796044-b1d4-a13b-0e26-54a8a53227d8",
"message_type": "RULE_MATCH_START",
"log_level": "TRACE",
"details": {
"caller_account_id": "<AWSアカウントID>",
"source_time_ms": 1753148951000,
"source": "event.non-97.net",
"detail_type": "myDetail",
"resources": [],
"event_detail": "{\"message\":\"test\"}"
}
}
{
"resource_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus",
"message_timestamp_ms": 1753148952607,
"event_bus_name": "non-97-test-eventbus",
"request_id": "1d83e007-bd15-44c2-bc9e-943b1a3dbc5e",
"event_id": "7a796044-b1d4-a13b-0e26-54a8a53227d8",
"message_type": "RULE_MATCH",
"log_level": "INFO",
"details": {
"rule_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:rule/non-97-test-eventbus/non-97-test-rule",
"target_arns": [
"arn:aws:logs:us-east-1:<AWSアカウントID>:log-group:/aws/events/non-97-test-rule"
],
"invocation_ids": [
"7a796044-b1d4-a13b-0e26-54a8a53227d8_97b3d853-f719-38f6-1f02-6d147b73b8ba"
]
}
}
{
"resource_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus",
"message_timestamp_ms": 1753148952610,
"event_bus_name": "non-97-test-eventbus",
"request_id": "1d83e007-bd15-44c2-bc9e-943b1a3dbc5e",
"event_id": "7a796044-b1d4-a13b-0e26-54a8a53227d8",
"invocation_id": "7a796044-b1d4-a13b-0e26-54a8a53227d8_97b3d853-f719-38f6-1f02-6d147b73b8ba",
"message_type": "INVOCATION_START",
"log_level": "INFO",
"details": {
"rule_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:rule/non-97-test-eventbus/non-97-test-rule",
"target_arn": "arn:aws:logs:us-east-1:<AWSアカウントID>:log-group:/aws/events/non-97-test-rule",
"attempt_count": 1,
"target_input": "{\"version\":\"0\",\"id\":\"7a796044-b1d4-a13b-0e26-54a8a53227d8\",\"detail-type\":\"myDetail\",\"source\":\"event.non-97.net\",\"account\":\"<AWSアカウントID>\",\"time\":\"2025-07-22T01:49:11Z\",\"region\":\"us-east-1\",\"resources\":[],\"detail\":{\"message\":\"test\"}}",
"target_properties": "{}"
}
}
{
"resource_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus",
"message_timestamp_ms": 1753148952643,
"event_bus_name": "non-97-test-eventbus",
"request_id": "1d83e007-bd15-44c2-bc9e-943b1a3dbc5e",
"event_id": "7a796044-b1d4-a13b-0e26-54a8a53227d8",
"invocation_id": "7a796044-b1d4-a13b-0e26-54a8a53227d8_97b3d853-f719-38f6-1f02-6d147b73b8ba",
"message_type": "INVOCATION_ATTEMPT_START",
"log_level": "TRACE",
"details": {
"rule_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:rule/non-97-test-eventbus/non-97-test-rule",
"target_arn": "arn:aws:logs:us-east-1:<AWSアカウントID>:log-group:/aws/events/non-97-test-rule",
"attempt_count": 1,
"target_input": "{\"version\":\"0\",\"id\":\"7a796044-b1d4-a13b-0e26-54a8a53227d8\",\"detail-type\":\"myDetail\",\"source\":\"event.non-97.net\",\"account\":\"<AWSアカウントID>\",\"time\":\"2025-07-22T01:49:11Z\",\"region\":\"us-east-1\",\"resources\":[],\"detail\":{\"message\":\"test\"}}",
"target_properties": "{}"
}
}
{
"resource_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus",
"message_timestamp_ms": 1753148952979,
"event_bus_name": "non-97-test-eventbus",
"request_id": "1d83e007-bd15-44c2-bc9e-943b1a3dbc5e",
"event_id": "7a796044-b1d4-a13b-0e26-54a8a53227d8",
"invocation_id": "7a796044-b1d4-a13b-0e26-54a8a53227d8_97b3d853-f719-38f6-1f02-6d147b73b8ba",
"message_type": "INVOCATION_ATTEMPT_SUCCESS",
"log_level": "TRACE",
"details": {
"rule_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:rule/non-97-test-eventbus/non-97-test-rule",
"target_arn": "arn:aws:logs:us-east-1:<AWSアカウントID>:log-group:/aws/events/non-97-test-rule",
"attempt_type": "FIRST",
"attempt_count": 1,
"target_duration_ms": 335,
"target_response_body": "{\"sdkResponseMetadata\":{\"requestId\":\"5dc857a7-e7a4-481e-8e8b-b142af302132\"},\"sdkHttpMetadata\":{\"httpHeaders\":{\"Content-Length\":\"80\",\"Content-Type\":\"application/x-amz-json-1.1\",\"Date\":\"Tue, 22 Jul 2025 01:49:12 GMT\",\"x-amzn-RequestId\":\"5dc857a7-e7a4-481e-8e8b-b142af302132\"},\"httpStatusCode\":200,\"allHttpHeaders\":{\"x-amzn-RequestId\":[\"5dc857a7-e7a4-481e-8e8b-b142af302132\"],\"Content-Length\":[\"80\"],\"Date\":[\"Tue, 22 Jul 2025 01:49:12 GMT\"],\"Content-Type\":[\"application/x-amz-json-1.1\"]}},\"nextSequenceToken\":\"49665214931813691304424540034204419589502662194933792930\"}",
"http_status_code": 200
}
}
{
"resource_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus",
"message_timestamp_ms": 1753148952979,
"event_bus_name": "non-97-test-eventbus",
"request_id": "1d83e007-bd15-44c2-bc9e-943b1a3dbc5e",
"event_id": "7a796044-b1d4-a13b-0e26-54a8a53227d8",
"invocation_id": "7a796044-b1d4-a13b-0e26-54a8a53227d8_97b3d853-f719-38f6-1f02-6d147b73b8ba",
"message_type": "INVOCATION_SUCCESS",
"log_level": "INFO",
"details": {
"rule_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:rule/non-97-test-eventbus/non-97-test-rule",
"target_arn": "arn:aws:logs:us-east-1:<AWSアカウントID>:log-group:/aws/events/non-97-test-rule",
"target_input": "{\"version\":\"0\",\"id\":\"7a796044-b1d4-a13b-0e26-54a8a53227d8\",\"detail-type\":\"myDetail\",\"source\":\"event.non-97.net\",\"account\":\"<AWSアカウントID>\",\"time\":\"2025-07-22T01:49:11Z\",\"region\":\"us-east-1\",\"resources\":[],\"detail\":{\"message\":\"test\"}}",
"target_properties": "{}",
"total_attempts": 1,
"final_invocation_status": "SUCCESS",
"ingestion_to_start_latency_ms": 48,
"ingestion_to_complete_latency_ms": 384,
"ingestion_to_success_latency_ms": 384,
"target_duration_ms": 335,
"target_response_body": "{\"sdkResponseMetadata\":{\"requestId\":\"5dc857a7-e7a4-481e-8e8b-b142af302132\"},\"sdkHttpMetadata\":{\"httpHeaders\":{\"Content-Length\":\"80\",\"Content-Type\":\"application/x-amz-json-1.1\",\"Date\":\"Tue, 22 Jul 2025 01:49:12 GMT\",\"x-amzn-RequestId\":\"5dc857a7-e7a4-481e-8e8b-b142af302132\"},\"httpStatusCode\":200,\"allHttpHeaders\":{\"x-amzn-RequestId\":[\"5dc857a7-e7a4-481e-8e8b-b142af302132\"],\"Content-Length\":[\"80\"],\"Date\":[\"Tue, 22 Jul 2025 01:49:12 GMT\"],\"Content-Type\":[\"application/x-amz-json-1.1\"]}},\"nextSequenceToken\":\"49665214931813691304424540034204419589502662194933792930\"}",
"http_status_code": 200
}
}
- イベント受信
- EventBridge Ruleとのイベントマッチ
- ターゲットの呼び出し
の一連の処理が行われていることが分かりますね。
ログ出力先のS3 Bucketも確認します。
複数のオブジェクトが出力されていますね。一イベントにつき一オブジェクトではなさそうです。
<AWSアカウントID>_EventBusLogs_us-east-1-20250722T01Z-fba9de65.log.gz
をダウンロードして解凍すると、JSON Lines形式でログが記録されていました。
{"resource_arn":"arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus","message_timestamp_ms":1753148952591,"event_bus_name":"non-97-test-eventbus","request_id":"1d83e007-bd15-44c2-bc9e-943b1a3dbc5e","event_id":"7a796044-b1d4-a13b-0e26-54a8a53227d8","message_type":"EVENT_INGEST_SUCCESS","log_level":"INFO","details":{"caller_account_id":"<AWSアカウントID>","source_time_ms":1753148951000,"source":"event.non-97.net","detail_type":"myDetail","resources":[],"event_detail":"{\"message\":\"test\"}"}}
{"resource_arn":"arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus","message_timestamp_ms":1753148952979,"event_bus_name":"non-97-test-eventbus","request_id":"1d83e007-bd15-44c2-bc9e-943b1a3dbc5e","event_id":"7a796044-b1d4-a13b-0e26-54a8a53227d8","invocation_id":"7a796044-b1d4-a13b-0e26-54a8a53227d8_97b3d853-f719-38f6-1f02-6d147b73b8ba","message_type":"INVOCATION_SUCCESS","log_level":"INFO","details":{"rule_arn":"arn:aws:events:us-east-1:<AWSアカウントID>:rule/non-97-test-eventbus/non-97-test-rule","target_arn":"arn:aws:logs:us-east-1:<AWSアカウントID>:log-group:/aws/events/non-97-test-rule","target_input":"{\"version\":\"0\",\"id\":\"7a796044-b1d4-a13b-0e26-54a8a53227d8\",\"detail-type\":\"myDetail\",\"source\":\"event.non-97.net\",\"account\":\"<AWSアカウントID>\",\"time\":\"2025-07-22T01:49:11Z\",\"region\":\"us-east-1\",\"resources\":[],\"detail\":{\"message\":\"test\"}}","target_properties":"{}","total_attempts":1,"final_invocation_status":"SUCCESS","ingestion_to_start_latency_ms":48,"ingestion_to_complete_latency_ms":384,"ingestion_to_success_latency_ms":384,"target_duration_ms":335,"target_response_body":"{\"sdkResponseMetadata\":{\"requestId\":\"5dc857a7-e7a4-481e-8e8b-b142af302132\"},\"sdkHttpMetadata\":{\"httpHeaders\":{\"Content-Length\":\"80\",\"Content-Type\":\"application/x-amz-json-1.1\",\"Date\":\"Tue, 22 Jul 2025 01:49:12 GMT\",\"x-amzn-RequestId\":\"5dc857a7-e7a4-481e-8e8b-b142af302132\"},\"httpStatusCode\":200,\"allHttpHeaders\":{\"x-amzn-RequestId\":[\"5dc857a7-e7a4-481e-8e8b-b142af302132\"],\"Content-Length\":[\"80\"],\"Date\":[\"Tue, 22 Jul 2025 01:49:12 GMT\"],\"Content-Type\":[\"application/x-amz-json-1.1\"]}},\"nextSequenceToken\":\"49665214931813691304424540034204419589502662194933792930\"}","http_status_code":200}}
{"resource_arn":"arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus","message_timestamp_ms":1753148952607,"event_bus_name":"non-97-test-eventbus","request_id":"1d83e007-bd15-44c2-bc9e-943b1a3dbc5e","event_id":"7a796044-b1d4-a13b-0e26-54a8a53227d8","message_type":"RULE_MATCH","log_level":"INFO","details":{"rule_arn":"arn:aws:events:us-east-1:<AWSアカウントID>:rule/non-97-test-eventbus/non-97-test-rule","target_arns":["arn:aws:logs:us-east-1:<AWSアカウントID>:log-group:/aws/events/non-97-test-rule"],"invocation_ids":["7a796044-b1d4-a13b-0e26-54a8a53227d8_97b3d853-f719-38f6-1f02-6d147b73b8ba"]}}
{"resource_arn":"arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus","message_timestamp_ms":1753148952610,"event_bus_name":"non-97-test-eventbus","request_id":"1d83e007-bd15-44c2-bc9e-943b1a3dbc5e","event_id":"7a796044-b1d4-a13b-0e26-54a8a53227d8","invocation_id":"7a796044-b1d4-a13b-0e26-54a8a53227d8_97b3d853-f719-38f6-1f02-6d147b73b8ba","message_type":"INVOCATION_START","log_level":"INFO","details":{"rule_arn":"arn:aws:events:us-east-1:<AWSアカウントID>:rule/non-97-test-eventbus/non-97-test-rule","target_arn":"arn:aws:logs:us-east-1:<AWSアカウントID>:log-group:/aws/events/non-97-test-rule","attempt_count":1,"target_input":"{\"version\":\"0\",\"id\":\"7a796044-b1d4-a13b-0e26-54a8a53227d8\",\"detail-type\":\"myDetail\",\"source\":\"event.non-97.net\",\"account\":\"<AWSアカウントID>\",\"time\":\"2025-07-22T01:49:11Z\",\"region\":\"us-east-1\",\"resources\":[],\"detail\":{\"message\":\"test\"}}","target_properties":"{}"}}
特にログのフォーマットは変わりありません。
ログスキーマについては以下AWS公式ドキュメントをご覧ください。
ターゲットの呼び出しに失敗するように設定して、再度テストイベントをPUT
ターゲットの呼び出しに失敗するように設定して、再度テストイベントをPUTしましょう。
大量のログが出力されるとノイズになるため、ログレベルをERRORに変更します。
ログレベルが変更されたことを確認します。
EventBridge Ruleのターゲットに指定していたCloudWatch Logsグループを削除します。
これでエラーが出力されるか確認します。
テストイベントをPUTします。イベントの内容は以下のとおりです。
{
"version": "0",
"id": "82c508eb-bf5e-7de8-8c79-fec14d3dff4e",
"detail-type": "myDetailType",
"source": "event.non-97.net",
"account": "<AWSアカウントID>",
"time": "2025-07-22T02:04:39Z",
"region": "us-east-1",
"resources": [],
"detail": {
"message": "test"
}
}
CloudWatch Logsに出力されたログは以下のとおりです。
{
"resource_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus",
"message_timestamp_ms": 1753149881232,
"event_bus_name": "non-97-test-eventbus",
"request_id": "2b9bc32f-ef6d-4615-8556-b838c30014cb",
"event_id": "82c508eb-bf5e-7de8-8c79-fec14d3dff4e",
"invocation_id": "82c508eb-bf5e-7de8-8c79-fec14d3dff4e_31f5c567-ae16-37b0-3126-33780a59cb25",
"message_type": "INVOCATION_ATTEMPT_PERMANENT_FAILURE",
"log_level": "ERROR",
"details": {
"rule_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:rule/non-97-test-eventbus/non-97-test-rule",
"target_arn": "arn:aws:logs:us-east-1:<AWSアカウントID>:log-group:/aws/events/non-97-test-rule",
"attempt_type": "FIRST",
"attempt_count": 1,
"invocation_status": "NO_RESOURCE",
"target_duration_ms": 276,
"target_response_body": "{\"errorType\":\"Unknown\",\"errorMessage\":\"Could not complete synchronized putLogEvents call for /aws/events/non-97-test-rule\",\"statusCode\":0,\"userFacingMessage\":\"Could not complete putLogEvents call for /aws/events/non-97-test-rule.\",\"userFacingErrorResponse\":{\"empty\":true,\"present\":false},\"userFacingServiceException\":{\"empty\":true,\"present\":false},\"message\":\"Could not complete synchronized putLogEvents call for /aws/events/non-97-test-rule (Service: null; Status Code: 0; Error Code: null; Request ID: null; Proxy: null)\",\"retryable\":true,\"suppressed\":[],\"localizedMessage\":\"Could not complete synchronized putLogEvents call for /aws/events/non-97-test-rule (Service: null; Status Code: 0; Error Code: null; Request ID: null; Proxy: null)\"}",
"http_status_code": 0
},
"error": {
"http_status_code": 0,
"error_message": "Could not complete putLogEvents call for /aws/events/non-97-test-rule."
}
}
{
"resource_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:event-bus/non-97-test-eventbus",
"message_timestamp_ms": 1753149881232,
"event_bus_name": "non-97-test-eventbus",
"request_id": "2b9bc32f-ef6d-4615-8556-b838c30014cb",
"event_id": "82c508eb-bf5e-7de8-8c79-fec14d3dff4e",
"invocation_id": "82c508eb-bf5e-7de8-8c79-fec14d3dff4e_31f5c567-ae16-37b0-3126-33780a59cb25",
"message_type": "INVOCATION_FAILURE",
"log_level": "ERROR",
"details": {
"rule_arn": "arn:aws:events:us-east-1:<AWSアカウントID>:rule/non-97-test-eventbus/non-97-test-rule",
"target_arn": "arn:aws:logs:us-east-1:<AWSアカウントID>:log-group:/aws/events/non-97-test-rule",
"target_input": "{\"version\":\"0\",\"id\":\"82c508eb-bf5e-7de8-8c79-fec14d3dff4e\",\"detail-type\":\"myDetailType\",\"source\":\"event.non-97.net\",\"account\":\"<AWSアカウントID>\",\"time\":\"2025-07-22T02:04:39Z\",\"region\":\"us-east-1\",\"resources\":[],\"detail\":{\"message\":\"test\"}}",
"target_properties": "{}",
"total_attempts": 1,
"final_invocation_status": "NO_RESOURCE",
"ingestion_to_start_latency_ms": 57,
"ingestion_to_complete_latency_ms": 333,
"target_duration_ms": 276,
"target_response_body": "{\"errorType\":\"Unknown\",\"errorMessage\":\"Could not complete synchronized putLogEvents call for /aws/events/non-97-test-rule\",\"statusCode\":0,\"userFacingMessage\":\"Could not complete putLogEvents call for /aws/events/non-97-test-rule.\",\"userFacingErrorResponse\":{\"empty\":true,\"present\":false},\"userFacingServiceException\":{\"empty\":true,\"present\":false},\"message\":\"Could not complete synchronized putLogEvents call for /aws/events/non-97-test-rule (Service: null; Status Code: 0; Error Code: null; Request ID: null; Proxy: null)\",\"retryable\":true,\"suppressed\":[],\"localizedMessage\":\"Could not complete synchronized putLogEvents call for /aws/events/non-97-test-rule (Service: null; Status Code: 0; Error Code: null; Request ID: null; Proxy: null)\"}",
"http_status_code": 0
},
"error": {
"http_status_code": 0,
"error_message": "Could not complete putLogEvents call for /aws/events/non-97-test-rule."
}
}
正しく、エラーとなったことがログとして記録されていますね。
defaultのEvent BusでTRACEログを記録
最後にdefaultのEvent BusでTRACEログを記録するようにした場合にイベント受信のログが記録されないことを確認します。
defaultのEvent BusでTRACEログを記録するように変更します。
とりあえず30分ほど待ちましたが、何もログ出力されません。
「defaultのEvent BusでTRACEログを出力すると即課金」という形ではなく、安心しました。
トラブルシューティングのお供に
Amazon EventBridgeのEvent Busでログ出力設定ができるようになったアップデートを紹介しました。
トラブルシューティングのお供として有効活用できそうですね。
とりあえずログレベルをERRORで設定しても良いと感じました。
この記事が誰かの助けになれば幸いです。
以上、クラウド事業本部 コンサルティング部の のんピ(@non____97)でした!