- AWS account with permissions to view CloudWatch Logs and create metric filters.
- A log group containing log events, or permission to create one.
-
Open the CloudWatch console
- Go to Services → CloudWatch.
- In the left navigation, choose Logs → Log groups.
-
(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.
-
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.
- Select the log group you want (e.g.,
-
Define the filter pattern
- The simplest pattern is a keyword or literal that appears in the log message.
- Examples:
ERROR, the exact token INFO, or the substring Warning:. Filter patterns are case-sensitive and must match the exact token/substring in your logs.

-
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.
-
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
ERRORmatch.

- 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
1to count each matching event as one occurrence. - Dimensions: optional key/value pairs to add context (for example,
Environment=prod).
- Filter name: identifier for the filter (e.g.,
- If the test matches the expected lines, configure the metric settings that CloudWatch will create when a log event matches the filter:
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.
- 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.

- 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)
- Open the LogGroup details and check Metric Filters. You should see:

- 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.
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.
- Amazon CloudWatch Logs – Metric filters and alarms
- Amazon CloudWatch Metrics and CloudWatch Alarms documentation