I don't want to log all requests that are analyzed by my web ACL but I do want to log the blocked requests. How can I do this in AWS WAF?
Use AWS WAF logs filtering to filter out log entries based on rule actions or labels generated by rules while evaluating requests. Logs filtering helps you to save Amazon Kinesis Data Firehose and storage costs by publishing only the logs that you select. For example, you can log only blocked requests.
For Region, select the AWS Region where you created your web ACL. Note: Select Global if your web ACL is set up for Amazon CloudFront.
Select your web ACL.
Choose Logging and Metrics.
For Filter logs, choose Add filter.
Add one or more filter conditions. Then, select the criteria to either Match all of the filter conditions or Match at least one of the filter conditions.
For Filter conditions, select either Rule Action on request or Request has label.
For Rule Action, filter based on action taken by rule, such as, Allow, Block, Count, or CAPTCHA.
For Request has label, filter based on the label added to AWS WAF while evaluating requests.
For Filter behavior, choose either Keep in logs or Drop from logs.
Choose the Default logging behavior.
Log only blocked requests
To log only the blocked requests by AWS WAF, select the filtering based on Rule Action and action as Block.
The Block action is a terminating action for AWS WAF. AWS WAF log filters check the terminating rule action of the AWS WAF log entry. If the action is Block, then the log entry is filtered and added to the log.
Log the Count requests from a rule group
How the rule in a rule group is set determines whether the logs are filtered or not filtered:
When the action for a rule in a rule group is set to Count, the logs for the request matching against this rule don't contain a Count action for this rule. Instead, the AWS WAF logs show this rule under the excludedRules fields, which aren't checked when the AWS WAF logs are filtered for Count action. This means that these requests aren't be filtered by the log filtering for Count action.
The request matching against a rule in a rule group where the rule group action is Override to Count is logged. For these requests, the AWS WAF log contains a Count action in the nonTerminatingMatchingRules field that is checked when filtering the Count action in AWS WAF logs.
Note:EXCLUDED_AS_COUNT is a valid action type for log filtering. This option can be configured using the PutLoggingConfiguration API.