CLOUD-DEPLOYMENT-AND-OPERATIONS practice question 3 of 15

(Which CloudWatch metric filter includes log events with the word ERROR but excludes log events with the word WARNING?)

Full set: 67 questions
Answer options
A: ?ERROR ?WARN
B: "ERROR" WARN
C: ERROR -WARN Correct answer
D: ERROR WARN
Correct Answer:
C. ERROR -WARN
Explanation

The Amazon CloudWatch Logs filter and pattern syntax uses a space to represent an implicit AND operator, meaning all specified terms must be present. To exclude a term, you prefix it with a hyphen (-). Therefore, the filter ERROR -WARN correctly translates to "find log events that contain the word 'ERROR' AND do NOT contain the word 'WARN'". This precisely matches the requirements of the question.

Why Incorrect

A. ?ERROR ?WARN: The question mark (?) specifies that the preceding term is optional. This filter does not enforce the presence of "ERROR" or the absence of "WARN".
B. "ERROR" WARN: This filter requires log events to contain both the exact term "ERROR" and the term "WARN", which is the opposite of the desired exclusion.
D. ERROR WARN: Similar to option B, this filter requires log events to contain both the term "ERROR" and the term "WARN" due to the implicit AND operator.

References

1. AWS CloudWatch Documentation, "Filter and pattern syntax":

Section on Exclusion: "You can specify a term to exclude from the results by prefixing it with a minus sign (-). For example, the term error -warning returns strings that contain error but that don't contain warning." This directly supports the correct answer C.

Section on Default Operator: "By default, terms in a filter pattern are separated by spaces. All terms must appear in a log event for it to match the filter." This explains why options B and D are incorrect.

Section on Optional Terms: "You can use a question mark to specify that the preceding term is optional. For example, ?error means that the term error is optional." This explains why option A is incorrect.

Source: Amazon Web Services, Inc. (2023). Amazon CloudWatch Logs User Guide. Retrieved from https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html

Scroll to Top