Query Details

D05 Awsroute53resolver Schema Check

Query

// REVIEW ONLY - Mandatory Step 1: AWSRoute53Resolver Schema, SrcIds & Answer Bag Keys Discovery
// Validates Resolver Query Log coverage, DNS Firewall fields, and SrcIds dynamic structure (instance/eni).
AWSRoute53Resolver
| where TimeGenerated > ago(24h)
| extend SrcIdKeys = bag_keys(SrcIds),
    SampleAnswerKeys = iff(array_length(Answers) > 0, bag_keys(Answers[0]), dynamic([]))
| summarize
    QueryCount = count(),
    LogTypes = make_set(LogType, 10),
    Rcodes = make_set(Rcode, 20),
    QueryTypes = make_set(QueryType, 20),
    FirewallActions = make_set(FirewallRuleAction, 10),
    ObservedSrcIdKeys = make_set(SrcIdKeys, 20),
    ObservedAnswerKeys = make_set(SampleAnswerKeys, 20)
    by AccountId, Region, VpcId
| order by QueryCount desc
| take 200

Explanation

This query is designed to analyze and summarize DNS query logs from AWS Route 53 Resolver over the past 24 hours. Here's a breakdown of what it does:

  1. Data Source: It uses the AWSRoute53Resolver table, which contains DNS query logs.

  2. Time Filter: It filters the logs to only include those generated in the last 24 hours.

  3. Key Extraction:

    • It extracts the keys from the SrcIds field into a new column called SrcIdKeys.
    • It also extracts keys from the first element of the Answers array (if it exists) into a column called SampleAnswerKeys.
  4. Aggregation:

    • It counts the total number of queries (QueryCount).
    • It collects unique values for several fields:
      • LogType: Types of logs.
      • Rcode: Response codes.
      • QueryType: Types of DNS queries.
      • FirewallRuleAction: Actions taken by DNS firewall rules.
      • ObservedSrcIdKeys: Unique keys observed in the SrcIds field.
      • ObservedAnswerKeys: Unique keys observed in the Answers field.
  5. Grouping: The results are grouped by AccountId, Region, and VpcId.

  6. Ordering and Limiting:

    • The results are ordered by QueryCount in descending order, showing the most queried accounts, regions, and VPCs first.
    • It limits the output to the top 200 results.

In simple terms, this query helps you understand the distribution and characteristics of DNS queries in your AWS environment, focusing on the last 24 hours and highlighting the most active accounts, regions, and VPCs.