Logo

dev-resources.site

for different kinds of informations.

AWS CloudWatch Logging and Live Tail!

Published at
11/18/2024
Categories
aws
cloudwatch
observability
lambda
Author
bhatiagirish
Author
12 person written this
bhatiagirish
open
AWS CloudWatch Logging and Live Tail!

In the previous articles, I explained the use of CloudWatch and CloudTrail for logging, monitoring, alarming, and auditing. I also covered how to create aggregated logs in CloudWatch using a custom log group.

If you missed it, be sure to check out the articles linked below before continuing.

Link: AWS Logging, Monitoring & Auditing with AWS CloudWatch and CloudTrail!
Link: AWS Lambda Log Aggregation Using CloudWatch Custom Log Group & Logs Insights!

In this article, I’ll introduce another useful feature: CloudWatch Live Tail, which lets you view live logs as they’re generated!

If you’re a Linux user, you’re likely familiar with the tail command for viewing live logs. CloudWatch’s live tail feature works similarly, allowing you to monitor logs in real time as your functions are executed.

In this example, I’ll demonstrate how to set up live tail logging in AWS CloudWatch. We’ll invoke a Lambda function and analyze its logs live as they’re published to the log stream.

This feature is incredibly helpful for various use cases, including debugging issues, monitoring deployments, command center oversight, identifying performance issues, and more.

Let's look at the architecture diagram!

Architecture Diagram

Let's see the steps to create this solution using AWS CloudWatch live tail and Lambda logging.

Few points about CloudWatch Live Tail

  • CloudWatch Live Tail provides options to refine and target specific log data:
  • Use Highlight to flag events that match your specified terms (up to 5 terms).
  • Use Filter to limit the events displayed in the session.
  • You can select up to 10 log groups to include in the live tail session .

Note: CloudWatch Live Tail is charged on a per-minute basis during the session, making it a flexible, on-demand solution for troubleshooting and monitoring.

Review the CloudWatch Log Group

For this CloudWatch Logs live tail demonstration, I will use the log group /aws/lambda/MeetingNotesSummarizer. This log group is already in place for an existing Lambda function, and all logs generated by this function are stored here. This setup allows us to monitor and analyze the log data produced by this Lambda function in real time.

Review the Lambda Function Description

The Lambda function we’re using is pre-configured with logging capabilities. This function supports a Generative AI use case and includes guardrails to ensure data security and compliance. For example, if Personally Identifiable Information (PII) is detected in the data processed by this function, a guardrail log entry will be generated in the CloudWatch log group to flag the occurrence. This helps maintain data safety by providing insights into sensitive data handling during AI operations.

Configure a Live Tail

Let's configure a live tail. I will use the GUARDRAIL_INTERVENED as the highlighted term.

I will also filter on 'GUARDRAIL_INTERVENED' to get the live tail whenever guardrail is applied for the Generative AI use case in this function.

Live tail configuration

Apply the filter and start the live tail session!

Invoke the Lambda Function

To validate the policy configuration, Let's invoke a lambda function to write to the logs.

I am using a GenAI app created by me to invoke the lambda in the backend. This App uses multiple AWS services including API Gateway, Lambda, Bedrock and others.

GenAI App

Monitor the Live tail for highlighted and Filtered logs

When lambda function is invoked, logs will be created and live tail will show it as well!

tailresults

Cleanup - Delete Log Group, End the live tail session

If you don't need the log group, make sure to delete it and end the live tail session.

Conclusion

In this article, I have demonstrated how to implement a live tail for CloudWatch logs. Logging and monitoring are essential components of observability, and mastering different techniques can greatly enhance your skills in this area.

With this setup, you are now equipped to monitor live tails from CloudWatch log groups effectively!

Thank you for reading!

Click here to watch the YouTube video for this solution:

https://www.youtube.com/watch?v=cE9aT_JRujM

π’’π’Ύπ“‡π’Ύπ“ˆπ’½ ℬ𝒽𝒢𝓉𝒾𝒢
𝘈𝘞𝘚 𝘊𝘦𝘳𝘡π˜ͺ𝘧π˜ͺ𝘦π˜₯ 𝘚𝘰𝘭𝘢𝘡π˜ͺ𝘰𝘯 𝘈𝘳𝘀𝘩π˜ͺ𝘡𝘦𝘀𝘡 & π˜‹π˜¦π˜·π˜¦π˜­π˜°π˜±π˜¦π˜³ 𝘈𝘴𝘴𝘰𝘀π˜ͺ𝘒𝘡𝘦
𝘊𝘭𝘰𝘢π˜₯ π˜›π˜¦π˜€π˜©π˜―π˜°π˜­π˜°π˜¨π˜Ί 𝘌𝘯𝘡𝘩𝘢𝘴π˜ͺ𝘒𝘴𝘡

cloudwatch Article's
30 articles in total
Favicon
Monitoring AWS Infrastructure: Building a Real-Time Observability Dashboard with Amazon CloudWatch and Prometheus
Favicon
A Simple Guide to AWS Monitoring Tools
Favicon
Config AWS Cloudwatch Application Signals Transaction Search with CDK
Favicon
Quickly and easily filter your Amazon CloudWatch logs using Logs Insights
Favicon
Forward logs to Cloudwatch for an EC2 instance running a custom Linux AMI
Favicon
AWS CloudWatch: Implementing Data Protection Policy for Sensitive Log Data!
Favicon
Config AWS Cloudwatch Application Signals for NodeJs Lambda with CDK
Favicon
AWS CloudWatch Logging and Live Tail using AWS CLI!
Favicon
AWS CloudWatch Logging and Live Tail using Python/Boto3 SDK!
Favicon
A Beginner’s Guide to Amazon CloudWatch: Monitoring Your Cloud Like a Pro
Favicon
Automatização de Reboots de InstÒncias EC2 com CloudWatch, EventBridge e Lambda
Favicon
Streaming of Desktop Applications Securely on Web Browser Using Amazon AppStream 2.0
Favicon
How to Use Send AWS CloudWatch Metrics to GreptimeCloud by GrafanaΒ Alloy
Favicon
AWS CloudWatch Logging and Live Tail!
Favicon
Understanding Logging in Kubernetes - From Containers to Nodes
Favicon
AWS CloudWatch Observability Solutions: Game-Changer or Just a Glossy Wrapper? Honest First Impressions!
Favicon
AWS Lambda Log Aggregation Using CloudWatch Custom Log Group & Logs Insights!
Favicon
AWS Logging, Monitoring & Auditing with AWS CloudWatch and CloudTrail!
Favicon
Amazon CloudWatch Internet Monitor from Amazon Network Load balancer
Favicon
AWS Monitoring - Part 1: AWS CloudWatch
Favicon
AWS Database Migration Service now includes enhanced monitoring dashboard for your DMS tasks
Favicon
CloudWatch CPU Utilization Monitoring with SNS Alert
Favicon
VPC Flow Logs Setup
Favicon
Transfer of Data Across Accounts from S3 to S3 Using AWS DataSync
Favicon
Real-Time Incident Recovery with Event-Driven Microservices Architecture and Early Monitoring
Favicon
Implementing SLO Error Budget Monitoring with AWS Services Only
Favicon
Gerenciamento de alta latΓͺncia com AWS CloudWatch e AWS Systems Manager
Favicon
Creating Recommended Alarms for Amazon OpenSearch Service with Terraform
Favicon
Automate EC2 Instance Management with AWS Lambda
Favicon
Deep Dive on AWS Clean Rooms with Integration to AWS Glue

Featured ones: