D02 Awscloudtrail Schema And Dataevents Check
Query
// REVIEW ONLY - Mandatory Step 1: AWSCloudTrail Schema, Dynamic Bag Keys & Data-Event Selector Discovery
// Run parts A, B, and C separately in Log Analytics during pre-deployment validation.
// --- Part A: Exact column names and types (detects legacy AWS vs AWSS3/CCF DCR variations) ---
AWSCloudTrail
| getschema
| project ColumnName, ColumnOrdinal, DataType, ColumnType
| take 200;
// --- Part B: Inspect dynamic JSON keys in RequestParameters, ResponseElements, AdditionalEventData ---
// Comment out Part A above when running Part B interactively.
// AWSCloudTrail
// | where TimeGenerated > ago(24h)
// | where EventName in ("ConsoleLogin", "AssumeRole", "PutEventSelectors", "GetObject", "UpdateAssumeRolePolicy")
// | extend ReqKeys = bag_keys(todynamic(column_ifexists("RequestParameters", "{}")))
// | extend RespKeys = bag_keys(todynamic(column_ifexists("ResponseElements", "{}")))
// | extend AddKeys = bag_keys(todynamic(column_ifexists("AdditionalEventData", "{}")))
// | summarize SampleCount=count(), ObservedReqKeys=make_set(ReqKeys, 50), ObservedRespKeys=make_set(RespKeys, 50), ObservedAddKeys=make_set(AddKeys, 50) by EventSource, EventName, ManagementEvent
// | take 100
// --- Part C: Verify whether S3 and Bedrock DATA events (ManagementEvent == false) are actually ingested ---
// AWSCloudTrail
// | where TimeGenerated > ago(7d)
// | summarize ManagementEvents=countif(ManagementEvent == true), DataEvents=countif(ManagementEvent == false),
// S3GetObjectEvents=countif(EventSource == "s3.amazonaws.com" and EventName == "GetObject"),
// BedrockRuntimeEvents=countif(EventSource == "bedrock-runtime.amazonaws.com")
// by RecipientAccountId, AWSRegionExplanation
This query is designed to perform a pre-deployment validation of AWS CloudTrail logs in Log Analytics. It consists of three separate parts, each with a specific focus:
-
Part A: Schema Discovery
- This part retrieves the schema of the AWSCloudTrail table, including the exact column names, their order, data types, and column types. It helps in identifying any variations in the schema, such as differences between legacy AWS logs and newer AWS S3/CCF DCR logs. The query limits the output to 200 rows.
-
Part B: Dynamic JSON Key Inspection
- This part is used to explore the dynamic JSON keys present in specific fields (
RequestParameters,ResponseElements,AdditionalEventData) of the AWSCloudTrail logs. It focuses on events like "ConsoleLogin", "AssumeRole", "PutEventSelectors", "GetObject", and "UpdateAssumeRolePolicy" that occurred in the last 24 hours. The query extends the data with keys from these fields and summarizes the count of samples and observed keys for each event source, event name, and management event type. The output is limited to 100 rows.
- This part is used to explore the dynamic JSON keys present in specific fields (
-
Part C: Data Event Verification
- This part checks whether specific data events, particularly those related to S3 and Bedrock, are being ingested. It summarizes the count of management events and data events over the past 7 days, focusing on "GetObject" events from S3 and events from the Bedrock runtime. The results are grouped by recipient account ID and AWS region.
Overall, the query helps in understanding the structure of AWS CloudTrail logs, inspecting dynamic data within the logs, and verifying the ingestion of specific types of events.