An application deployed on Amazon ECS writes JSON-formatted logs to Amazon CloudWatch Logs. A sample log event is shown below:
{
"statusCode": 500,
"errorType": "DatabaseTimeoutException",
"message": "Connection to database timed out."
}
The developer needs to create a CloudWatch Metric Filter to count the occurrences of this specific database timeout error. Which filter pattern should the developer use to match logs where the statusCode is 500 and the errorType is exactly DatabaseTimeoutException?
- { .statusCode = 500 && .errorType = "DatabaseTimeoutException" }Cevap
- B[statusCode = 500, errorType = "DatabaseTimeoutException"]
- C{ .statusCode == 500 && .errorType == "DatabaseTimeoutException" }
- Dfields statusCode, errorType | filter statusCode = 500 and errorType = "DatabaseTimeoutException"
Cevap
The metric filter pattern { .statusCode = 500 && .errorType = "DatabaseTimeoutException" } correctly filters JSON logs.
The correct metric filter pattern utilizes curly braces to specify a JSON log filter. Inside the braces, JSON properties are referenced using JSONPath-like notation starting with $. representing the root. The equality operator is a single = sign, and the logical combination uses &&.
Adım Adım Çözüm
Anahtar Kavram
CloudWatch Logs Metric Filter JSON Syntax