Skip to main content
In this lesson you’ll learn how to push custom metrics to Amazon CloudWatch by creating a metric filter that converts matching log events into CloudWatch metrics. Metric filters let you scan log data and emit metric data points whenever a log event matches a filter pattern — enabling dashboards, alarms, and metric-based observability from plain logs. Prerequisites
  • AWS account with permissions to view CloudWatch Logs and create metric filters.
  • A log group containing log events, or permission to create one.
Steps
  1. Open the CloudWatch console
    • Go to Services → CloudWatch.
    • In the left navigation, choose Logs → Log groups.
  2. (Optional) Create an isolated log group for this demo
    • Click Create log group.
    • Enter a name (this guide uses LogGroup1).
    • Choose a retention setting (for a demo you can set to Never Expire).
    • Optionally configure tags, encryption, or other settings.
    • Click Create log group.
  3. Select your log group and create a metric filter
    • Select the log group you want (e.g., LogGroup1).
    • Choose Actions → Create metric filter.
    • A metric filter scans log events and emits metric data when a log event matches the pattern.
  4. Define the filter pattern
    • The simplest pattern is a keyword or literal that appears in the log message.
    • Examples:
These patterns match lines containing the word ERROR, the exact token INFO, or the substring Warning:. Filter patterns are case-sensitive and must match the exact token/substring in your logs.
Screenshot of the AWS CloudWatch "Create metric filter" page, showing the Filter pattern input with "ERROR" entered and optional field selection criteria below. The browser toolbar and AWS account/region header are visible at the top.
  1. Field selection criteria (optional)
    • Use Field Selection Criteria when you have structured logs (JSON, key/value) or a centralized log group where you want to extract specific fields.
    • For simple text matching (like searching for ERROR) you can skip field selection.
  2. Test your filter pattern
    • Use Select Log Data to Test → Custom Log Data and paste representative sample log events into the Test Pattern area. Example sample log data:
  • Run the test. CloudWatch will highlight which lines match the filter pattern. In this example, lines containing ERROR match.
A browser screenshot of the AWS CloudWatch "Create metric filter" page showing test pattern results. It lists two matched log events, including "ERROR Database connection failed" and "ERROR Application timeout."
  1. Configure the metric to publish on each match
    • If the test matches the expected lines, configure the metric settings that CloudWatch will create when a log event matches the filter:
      • Filter name: identifier for the filter (e.g., ErrorCountFilter).
      • Metric namespace: logical grouping for custom metrics (e.g., DemoApplication).
      • Metric name: the metric identifier inside the namespace (e.g., ErrorCount).
      • Metric value: commonly 1 to count each matching event as one occurrence.
      • Dimensions: optional key/value pairs to add context (for example, Environment=prod).
Using a metric value of 1 makes the metric behave as a counter: each matching log event contributes one data point that you can aggregate.
Using a metric value of 1 is a common pattern: each matching log event contributes one unit to the metric so you can graph counts, create alarms, or build dashboards from the aggregated values.
A screenshot of the AWS CloudWatch console on the "Create metric filter" page showing the Metric namespace set to "DemoApplication" and the Metric name set to "ErrorCount." The page shows options to create a new namespace and configure metric values.
  1. Review and create
    • Review your filter configuration and click Create metric filter.
    • After creation you should see a success confirmation and the filter listed under the log group.
A screenshot of the AWS CloudWatch console showing a log group named "LogGroup1" with a green success banner reading Metric filter "ErrorCountFilter" has been created. The page shows log group details and action buttons like "View in Logs Insights" and "Search log group."
  1. Verify the metric filter in the log group
    • Open the LogGroup details and check Metric Filters. You should see:
      • Filter name
      • Metric namespace / name
      • Configured metric value (for example, 1)
A screenshot of the AWS CloudWatch console showing LogGroup1 metric filter details, with the metric "DemoApplication / ErrorCount" and Metric value 1. The browser and AWS navigation bars are visible at the top.
  1. Use the published metric
  • After the filter is active, matching log events will cause CloudWatch to publish metric data for events ingested after the filter was created.
  • You can then:
    • Graph the metric in CloudWatch Metrics.
    • Add the metric to dashboards.
    • Create CloudWatch alarms to notify on threshold breaches.
Metric filters evaluate only log events ingested after the filter’s creation. They do not retroactively create metrics for older log events unless those events are re-ingested.
Quick reference — Metric filter configuration Troubleshooting tips
  • If no matches appear after creation, verify:
    • Your filter pattern is case-sensitive and matches the exact token in logs.
    • Log events were ingested after the filter was created.
  • Use the test pattern feature to validate patterns against sample log lines before creating the filter.
Links and references That’s the end-to-end process for converting log events into custom CloudWatch metrics using metric filters.

Watch Video

Practice Lab