A fraud-detection workload needs to react within seconds whenever a specific error pattern appears in an application's CloudWatch Logs, by invoking an AWS Lambda function that quarantines the offending account. The team has been running a five-minute scheduled query and finds it too slow. They want each matching log event delivered to the function as it is written, filtered to only the lines that match a pattern. Which approach delivers the matching events fastest with the least overhead?
- ASchedule a CloudWatch Logs Insights query every minute that searches the log group for the error pattern and triggers the quarantine Lambda function whenever the query returns one or more matching rows.
- BPut a CloudWatch Logs subscription filter with the error pattern on the log group and set the quarantine Lambda function as its destination, so each matching event is delivered to the function as it is written. Correct
- CCreate a metric filter that counts the error pattern and a CloudWatch alarm that invokes the Lambda function through an Amazon SNS topic when the count crosses one over the alarm evaluation period.
- DEnable CloudWatch cross-account observability so the security account can see the source account's log group, then have an engineer in that account watch a live tail and invoke the function when the pattern appears.
Why A is wrong: Running Logs Insights more often shortens the delay but is still a polling loop bounded by the schedule interval, so it cannot deliver events within seconds and it re-scans the log group on every run, adding cost and lag.
Why B is correct: A subscription filter with a filter pattern and a Lambda destination pushes only the matching log events to the function in near real time as they are ingested, giving the seconds-level reaction the workload needs without any polling or scanning.
Why C is wrong: A metric filter and alarm can trigger automation, but the alarm evaluates over a period and works on counts rather than individual events, so it reacts in minutes and does not hand the matching log line itself to the function.
Why D is wrong: Cross-account observability gives visibility into the log group, but live-tail watching by an engineer is manual and not event-driven, so it cannot reliably quarantine within seconds and does not scale to an automated workload.