☁️
CTHFM: AWS
  • Welcome
  • Getting Started
    • Account Setup
  • AWS CLI
    • AWS CLI Overview
    • Installation
  • AWS Fundamentals
    • AWS Documentation
    • AWS Shared Responsibility Model
    • Organizational Hierarchy
    • AWS Principals
    • IAM Fundamentals
      • IAM Policy Components
      • IAM Documentation References
    • AWS Security Services Overview
    • AWS Core Services
    • AWS Frameworks
    • Regions and Availability Zones
  • SQL
    • SQL Refresher for Threat Hunting
  • Logging Reference
    • Cloudtrail
      • What is Cloudtrail?
      • Setting Up Cloudtrail
      • Cloudtrail Events Structure
      • Filtering and Searching CloudTrail Logs
      • IAM ID Prefixes
      • Additional Resources
      • API References
    • VPCFlow Logs
    • GuardDuty
      • Multi-Account Setup
      • GuardDuty Concepts
      • GuardDuty Finding References
      • S3 Protection
      • Malware Protection
        • EC2 Malware Protection
          • EC2 Protection Resources
          • Monitoring Scans
          • EC2 Malware Protection Events: CloudWatch
        • S3 Malware Protection
          • Enabling S3 Malware Protection
          • After Enabling S3 Malware Protection
          • S3 Malware Resource Plan Status
          • S3 Malware Protection Quotas
      • RDS Protection Enablement
      • Lambda Protection Enablement
      • Trusted IP Lists and Threat Lists in Amazon GuardDuty
      • Remediation Recommendations
      • GuardDuty API Reference
      • GuardDuty Quotas
    • Access Analyzer
      • Setup
      • External Access and Unused Access Analyzer Findings
      • Review Findings
      • Access Analyzer Resources
      • Access Analyzer API Reference
    • AWS Network Firewall
      • Permissions
      • Firewall Log Contents
      • Logging Destinations
      • CloudWatch Firewall Metrics
    • AWS Config
      • Resource Management in AWS Config
      • AWS Config Integrations
      • AWS Config Resources
      • Configuration Item
      • Config Rules
        • Evaluation Modes
  • CloudWatch
    • Amazon CloudWatch
      • CloudWatch Concepts
      • CloudWatch Metrics
        • Filter Pattern Syntax
      • CloudWatch Alarms
        • Alarm Recommendations
      • Subscriptions
      • CloudWatch Agent
      • CloudWatch Insights
        • Supported Logs and Discovered Fields
        • CloudWatch Insights Query Syntax
      • Anomaly Detection
        • Create Anomaly Detector
        • Alarms for Anomaly Detections
      • CloudWatch Filter Syntax
      • CloudWatch Service Quota
  • Athena For Threat Hunting
    • Introduction to Athena
    • Setting Up Athena
    • SQL For Threat Hunters
    • Automated Response
    • Query Best Practices
  • AWS Security Research and Resources
    • AWS Security Blog
    • AWS Goat
    • Cloud Goat
    • Pacu
    • Prowler
    • Scout Suite
  • Threat Hunting in AWS
    • Threat Hunting in AWS
    • Threat Hunting Introduction
    • Threat Hunting Process
      • Hypothesis Generation
      • Investigation
      • Identification
      • Resolution & Follow Up
    • Pyramid of Pain
    • MITRE Att&ck
      • MITRE Att&ck Concepts
      • MITRE Att&CK Data Sources
      • MITRE Att&CK Mitigations
    • MITRE Att&ck: AWS
      • MITRE Att&CK Matrix
      • Amazon Web Services Security Control Mappings
    • AWS Threat Hunting Ideas
      • AWS Threat Hunting Ideas: EC2
      • AWS Threat Hunting Ideas: Lambda
      • AWS Threat Hunting Ideas: SQS
      • AWS Threat Hunting Ideas: SNS
      • AWS Threat Hunting Ideas: RDS
Powered by GitBook
On this page
  • Overview
  • Filter Pattern Uses:
  • Supported Filter Pattern Types:
  • Usage and Limitations:
  1. CloudWatch
  2. Amazon CloudWatch

CloudWatch Filter Syntax

Overview

CloudWatch Logs uses filter patterns to search, filter, and process log events in real-time. These patterns define terms, numeric values, or regular expressions (regex) to match log entries and are used across metric filters, subscription filters, log event searches, and Live Tail for monitoring logs.

Filter Pattern Uses:

  • Metric Filters: Convert matched log events into metrics for monitoring and alarms.

  • Subscription Filters: Route matching log events to AWS services (e.g., Kinesis, Lambda).

  • Log Events: Search logs interactively to identify key events or patterns.

  • Live Tail: View logs in real-time as they are ingested.

Supported Filter Pattern Types:

  1. Regex Patterns:

    • Surround regex expressions with % (e.g., %ERROR% matches "ERROR").

    • Supported regex operators include:

      • ^: Anchors match to the beginning.

      • $: Anchors match to the end.

      • |: OR operator (e.g., %gray|grey%).

      • \: Escape character (e.g., %10\.10\.0\.1% to match an IP address).

      • []: Character class (e.g., %[a-z]% matches any lowercase letter).

      • * / +: Match zero or more, or one or more instances.

    Example: %colou?r% matches both "color" and "colour."

  2. Unstructured Log Patterns:

    • Match specific terms or phrases.

      • Example: ERROR matches logs containing the word "ERROR."

      • Use double quotes for exact phrases with special characters (e.g., "ERROR 401").

  3. JSON Log Patterns:

    • Use {} to define conditions for JSON logs. Example: { $.eventType = "UpdateTrail" }

    • Use property selectors like $. to target nested fields or arrays.

    • Use AND (&&) and OR (||) for compound conditions.

    Example: { ($.user.id = 1) && ($.users[0].email = "John.Doe@example.com") } This matches logs where the user.id is 1 and the first user's email is "John.Doe@example.com".

  4. Space-Delimited Patterns:

    • Match terms in logs with space-separated fields. Example:

      [w1=ERROR, w2]

      This matches logs where the first word is "ERROR."

Usage and Limitations:

  • Filter Testing: Test patterns in the CloudWatch console to verify results.

  • Case Sensitivity: Filters are case-sensitive.

  • Regex Limitations:

    • Supports a subset of regex symbols and up to 5 regex-based filters per log group.

    • Multi-byte characters are not supported.

  • Quota: A filter pattern can contain up to 2 regex expressions for JSON or space-delimited patterns.

PreviousAlarms for Anomaly DetectionsNextCloudWatch Service Quota

Last updated 8 months ago