- Newest
- Most votes
- Most comments
To group log events using a correlationid in CloudWatch Logs Insights and display the question and its corresponding answer in a single line tabular format, you can use the stats command along with string concatenation. Here's how you can approach this:
-
Open the CloudWatch console and navigate to Logs Insights.
-
Select the log group(s) containing your log events.
-
In the query editor, you can use a query similar to the following:
fields @timestamp, correlationid,
filter @message like /question/ as question,
filter @message like /answer/ as answer
| stats latest(question) as Question, latest(answer) as Answer by correlationid
| sort @timestamp desc
| limit 100
This query does the following:
- It filters the log messages to identify those containing "question" and "answer".
- It uses the
statscommand to group the events by correlationid. - It selects the latest question and answer for each correlationid.
- The results are sorted by timestamp in descending order and limited to 100 rows.
You may need to adjust the filters (e.g., like /question/ and like /answer/) based on the exact format of your log messages.
-
Run the query by clicking the "Run query" button.
-
The results will be displayed in a tabular format, showing the correlationid, Question, and Answer in separate columns.
-
You can further customize the visualization by selecting the "Visualization" tab and choosing an appropriate chart type, such as a table view.
This approach allows you to group related log events based on the common correlationid field and present the question and its corresponding answer together in the results. You can modify the query as needed to include additional fields or apply more specific filters to refine your results.
Sources
Tutorial: Run a query that produces a visualization grouped by log fields - Amazon CloudWatch Logs
Tutorial: Run a query with an aggregation function - Amazon CloudWatch Logs
Relevant content
asked 3 years ago
asked 10 months ago
- AWS OFFICIALUpdated 10 months ago

This is not valid CW Insights syntax: