0Pricing
AWS Security Academy · Lesson

Metric Filters for Security Events

Turn matching log lines into a metric you can watch.

Metric Filters for Security Events is a free AWS Security Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

From Logs to Metrics

Raw logs are rich but passive. A metric filter scans incoming log events in a log group, matches a pattern you define, and turns each match into a numeric data point in a CloudWatch metric. This bridges text logs and the metric world, where you can graph trends and, crucially, trigger alarms.

Why Filters Matter for Security

Security signals are often buried in ordinary logs: a failed login, an unauthorized API call, a console sign-in without MFA. A metric filter extracts exactly those lines and counts them. Once a security event is a metric, it becomes something you can watch and alert on automatically instead of hoping a human notices it scrolling by.

Filter Pattern Syntax

The filter pattern defines what to match. For plain text it can be simple terms, and for JSON logs it can match specific fields, such as { $.errorCode = "AccessDenied*" }. CloudTrail events delivered to CloudWatch are JSON, so JSON filter patterns let you target precise event names and error codes.

{ ($.eventName = "ConsoleLogin") && ($.additionalEventData.MFAUsed = "No") }

The Metric Transformation

When a log event matches, the filter emits a value to a metric you name, placed in a metric namespace. Usually each match increments the metric by one, but you can also publish a numeric field from the log. You also set a default value so the metric reports zero when no events match, which keeps alarms healthy.

Common Security Filters

AWS publishes recommended filters for CIS-style monitoring: unauthorized API calls, sign-in without MFA, root account usage, IAM policy changes, security group changes, and CloudTrail configuration changes. These map directly to high-value detection points. Building this set gives you broad coverage of the riskiest control-plane actions in an account.

Detecting Unauthorized API Calls

A classic filter matches events where the errorCode is AccessDenied or UnauthorizedOperation. A sudden spike in these often means an attacker is probing what a stolen credential can do. Counting them as a metric lets you alarm when the rate crosses a threshold, catching reconnaissance early.

Filtering Network Changes

Changes to security groups, network ACLs, or route tables can quietly open a path for an attacker. A metric filter on event names like AuthorizeSecurityGroupIngress or CreateRoute surfaces these. Because legitimate changes happen too, the alarm tells you to verify the change matches an approved request rather than that something is definitely wrong.

Metric Filters versus Insights

CloudWatch Logs Insights is for ad-hoc, after-the-fact querying you run by hand. Metric filters are continuous and proactive: they evaluate every event as it arrives and feed alarms. Use Insights to explore and metric filters to detect. The exam often contrasts reactive investigation with proactive alerting.

Limits to Remember

Filters only apply to new events after the filter is created; they do not retroactively scan old logs. You also have a limit on the number of metric filters per log group. Plan your detection set up front, and remember that historical analysis still belongs to Insights or Athena over archived data.

Wiring to an Alarm

A metric filter alone just counts. Its value appears when you attach a CloudWatch alarm that watches the metric and notifies you through SNS when a threshold is breached. Metric filter plus alarm plus SNS is the standard pattern for turning a suspicious log line into a real-time page to your security team.

Putting It Together

Design your filters around the actions that matter most: identity changes, denied calls, network edits, and root activity. Give each a sensible threshold so normal noise does not page anyone, and route alerts to a channel your team actually watches. Well-tuned metric filters are the difference between detection and discovering a breach months later.

Quick Check

Check your understanding of metric filters.

Recap

A metric filter matches a filter pattern against incoming log events and converts hits into a CloudWatch metric. JSON patterns target CloudTrail fields like errorCode and eventName. Cover unauthorized calls, MFA-less logins, root use, and network changes. Filters act only on new events, and they shine when wired to an alarm and SNS for real-time detection.

Frequently asked questions

Is the “Metric Filters for Security Events” lesson free?

Yes — the full text of “Metric Filters for Security Events” is free to read here on the web, and the AWS Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Security Academy course, upgrade to CoddyKit PRO.

What will I learn in “Metric Filters for Security Events”?

Turn matching log lines into a metric you can watch. You practise AWS Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AWS Security Academy?

No prior experience is required. AWS Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Metric Filters for Security Events” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AWS Security Academy lesson?

Yes. Every AWS Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Collecting Logs into CloudWatch
  2. Metric Filters for Security Events
  3. Creating Alarms and Notifications
  4. Detecting Root Account Usage
← Back to AWS Security Academy