Add support for processing CloudTrail logs from CloudWatch subscription filters #45695
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add CloudWatch Logs Subscription Filter Support for CloudTrail
Summary
This PR adds support for processing CloudTrail logs delivered via CloudWatch Logs subscription filters to the
awslogsencodingextension. Previously, the extension only supported CloudTrail logs stored in S3.Changes
Core Implementation
fromCloudWatch()method: Handles CloudTrail logs from CloudWatch Logs subscription filter formatextractFirstKey()to detect the CloudWatch envelope ("messageType") vs S3 format ("Records")logEvents[].messagefield (each message contains a single CloudTrail event as an escaped JSON string)aws.log.group.names,aws.log.stream.names) in addition to CloudTrail attributes (cloud.provider,cloud.region,cloud.account.id)Format Differences
S3 Format
{ "Records": [ { "eventVersion": "1.11", "eventName": "PutObject", ... }, { "eventVersion": "1.11", "eventName": "GetObject", ... } ] }CloudWatch Format
{ "messageType": "DATA_MESSAGE", "logGroup": "/aws/cloudtrail/logs", "logStream": "123456789010_CloudTrail_us-east-1", "logEvents": [ { "id": "eventId1", "timestamp": 1418530010000, "message": "{\"eventVersion\":\"1.11\",\"eventName\":\"PutObject\",...}" }, { "id": "eventId2", "timestamp": 1418530020000, "message": "{\"eventVersion\":\"1.11\",\"eventName\":\"GetObject\",...}" } ] }Key difference: In CloudWatch format, each
logEvents[].messageis an escaped JSON string containing a single CloudTrail event, whereas S3 files contain an array of events.Configuration Example
Related Issues
Testing
New Test Cases
Valid CloudWatch subscription filter format: Tests the new CloudWatch format parsing with real CloudWatch subscription filter event structuretestdata/cloudtrail_log_cw.json- CloudWatch subscription filter message with CloudTrail eventstestdata/cloudtrail_log_cw_expected.yaml- Properly mapped OpenTelemetry logsBreaking Changes
None. This is a backwards-compatible addition that extends existing functionality.