Logo

dev-resources.site

for different kinds of informations.

Quickly and easily filter your Amazon CloudWatch logs using Logs Insights

Published at
1/6/2025
Categories
aws
cloudwatch
logging
data
Author
nick_thompson
Categories
4 categories in total
aws
open
cloudwatch
open
logging
open
data
open
Author
13 person written this
nick_thompson
open
Quickly and easily filter your Amazon CloudWatch logs using Logs Insights

In modern cloud-native applications, monitoring and troubleshooting are critical for ensuring performance, reliability, and security. Amazon CloudWatch an AWS monitoring service, provides a powerful feature known as CloudWatch Logs Insights.

This feature has allowed our teams and developers to quickly and easily search log data, helping them get to the root cause and find actionable insights quickly and efficiently.

What is Amazon CloudWatch Logs Insights?

Amazon CloudWatch Logs Insights is a fully managed service that enables users to explore, query, and filter logs stored in CloudWatch.

It offers an intuitive query language similar to SQL and an interactive interface to simplify log analysis. Perfect for filtering larger logs when you’re debugging an application, troubleshooting an infrastructure issue, or performing security audits. Since our team started using CloudWatch Logs Insights we have been able to make the fault resolution process faster and more precise.

Why use Amazon CloudWatch Logs Insights?

Powerful Query Language

Logs Insights provides a robust, SQL-like query language. With commands like fields, filter, sort, and stats, users can slice and dice logs to uncover patterns, identify anomalies, or pinpoint specific events.

Seamless Integration

Logs Insights integrates seamlessly with other AWS services, including AWS Lambda, Amazon EC2, and Amazon ECS. This makes it easy to analyse logs across a wide range of AWS resources.

On-Demand Scalability

The service is designed to handle log volumes of any size, scaling automatically to meet demand.

Cost-Efficient

CloudWatch Logs Insights is pay-as-you-go. You only pay for the queries you run, based on the amount of data scanned.

Ready to give Logs Insights a go?

Step 1 - Enter the CloudWatch Dashboard

Using an AWS account with sufficient access privilege to access your CloudWatch services log into your AWS Console and search for CloudWatch and click to arrive at the CloudWatch Services console

Step 2 - Select Logs Insights

Under the Logs dropdown on the left hand pane, expand the Logs element and select Logs Insights

Logs Insights Image

Step 3 - Choose your Log Group

Log groups in CloudWatch represent collections of log streams, typically from a single resource type e.g a Lambda function or an EC2 instance

Step 4 - Write and run your Query

In the query editor window, you can write queries to extract specific information from the logs, such as most recent entries, customer data, product id's, error codes etc.

In our example below we are writing a query and selecting the fields we are interested in (timestamp, message etc) and filtering the message field to show all logs with a string match of "level:ERROR" within the last 3 hours and limiting the response to 1000 records.

fields @timestamp, @message, @logStream, @log
| filter @message like /level":"ERROR"/
| sort @timestamp desc
| limit 1000

Query Editor Image

Once happy with your query, simply click the Run Query button and wait for the results.

Step 5 - Analyse Results

If your search query finds any matches, all results will be returned via a timestamped histogram graph and list of matching CloudWatch logs.

From here you can visualise patterns, such as when and how often errors occurred and quickly home in on the exact CloudWatch log to take further action.

Results Image

Step 6 - Save and Share Queries

Once you have crafted the perfect query, why not save it for later or share it with your team! Once you have saved a query it is available for everyone with console access to use.

Some useful queries

List the most recent logs

fields @timestamp, @message, @logStream, @log
| sort @timestamp desc
| limit 20

Filter logs for a specific string

fields @timestamp, @message, @logStream, @log
| filter @message like /[email protected]/
| sort @timestamp desc
| limit 1000

Filter and count logs of matching strings (error levels etc)

fields @timestamp, @message, @logStream, @log
| filter @message like /ERROR/
| stats count() by level

Best Practices for CloudWatch Logs Insights

Structure Your Logs Use structured logging (e.g., JSON) for easier parsing and querying.

Use Filters Efficiently Reduce data scanned by filtering logs at the source level. This speeds up queries and reduces costs.

Monitor Costs Regularly monitor the amount of data scanned by queries to optimise usage and manage expenses.

Automate with APIs Use AWS SDKs or the CLI to automate log analysis and integrate Logs Insights into your CI/CD pipelines.

Combine with CloudWatch Alarms Use Logs Insights in conjunction with CloudWatch Alarms to proactively monitor for specific log patterns or thresholds.

Conclusion

Congratulations on getting started with Amazon CloudWatch Logs Insights. In this article we covered how to access Logs Insights within the console, create our first query and analyse the results.

I hope you and your teams can make use of Logs Insights effectively and start to enhance your monitoring capabilities, resolve issues faster, and make data-driven decisions to optimise your applications and infrastructure.

CloudWatch Logs Insights Official Documentation

CloudWatch Logs Insights Samples

logging Article's
30 articles in total
Favicon
🐹 Golang Integration with Kafka and Uber ZapLog 📨
Favicon
Mastering GoFrame Logging: From Zero to Hero
Favicon
Quickly and easily filter your Amazon CloudWatch logs using Logs Insights
Favicon
Avoiding console.log in Production: Best Practices for Robust Logging
Favicon
Freeware: Java Utility Package (Version 2024.12.08) released
Favicon
Kubernetes DaemonSets: Managing System-Level Components Across Every Node
Favicon
AWS CloudWatch: Implementing Data Protection Policy for Sensitive Log Data!
Favicon
Mastering Python Logging: From Basics to Advanced Techniques
Favicon
Docker Logging Drivers: A Comprehensive Guide for Effective Log Management
Favicon
How to Contact Robinhood Support Without Logging In
Favicon
Best Practices for Effective Logging Strategies
Favicon
How EKF Simplifies Logging
Favicon
Introducing implicit contexts in LogTape 0.7.0
Favicon
Simple Python Logging - and a digression on dependencies, trust, and Copy/pasting code
Favicon
Creating a Robust Logging System in C
Favicon
Understanding Logging in Kubernetes - From Containers to Nodes
Favicon
Making Wooster Talk: A Deep Dive into Structured Logging
Favicon
Logging con Python
Favicon
Freeware: Java Utility Package (Version 2024.10.26) released
Favicon
Is your Java log utility class reporting itself as the source of your logs? Learn how to fix it!
Favicon
Golang: Importância de planejar como exibir logs em aplicações de uso intenso
Favicon
Docker Advance Part 2: Docker Logging
Favicon
System Design 10 - Distributed Logging and Monitoring: Keeping an Eye on Your System’s Every Move
Favicon
Mask logs using logstash logback in java with regex
Favicon
Observability - 5(Logging using EFK)
Favicon
Observability
Favicon
Software Devs Picked These 2 Log Formats
Favicon
Error Handling and Logging in Node.js Applications
Favicon
Logging in Python: Best Practices
Favicon
microlog 6: New feature – Log Topics

Featured ones: