
AWS Logging, Monitoring & Auditing with AWS CloudWatch and CloudTrail!
CloudWatch and CloudTrail provide the tools necessary to implement the observability, empowering you to monitor, troubleshoot, and audit your applications in the cloud. Let’s explore each of these services and some of the valuable features they offer.
- CloudWatch is a logging, monitoring, and alerting service.
- CloudTrail is an auditing service that records events within your AWS accounts.
- Primary Purpose: Logging, Monitoring and Alarming
- Common Use Cases:
- Setting up alarms for critical metrics, like CPU utilization, memory, or API latency.
- Visualizing metrics over time using CloudWatch dashboards.
- Aggregating logs for troubleshooting and analysis using CloudWatch Logs.
- Log Collection and Management: CloudWatch Log Groups store and organize logs from various AWS services and custom application logs. For example, you can create a log group to track application logs or system-level metrics from EC2 instances.
- Alarms and Notifications: CloudWatch can trigger alarms based on metric thresholds, enabling you to monitor key performance indicators (KPIs) and take automated actions, such as scaling an application or sending an alert if a service experiences issues.
- CloudWatch Logs Insights: This interactive query tool helps you analyze log data to identify trends and diagnose problems, offering queries by source, region, IP, and more for in-depth visibility.
- From AWS Console, navigate to the CloudWatch service and select Log Groups
- Select Create Log Group and then specify a name for the Log group, example: /aws/lambda/customLogGroupGB
- Configure retention setting to specify how long the logs should be stored.
- You have option from 1 day to Never expire (many options in days, weeks, months and years!)
- Update Lambda function config to use this custom log group
- You don't need to use custom log group as Lambda will create a default log group /aws/lambda/functionName format.
- Review the log
- Delete the log group ( to avoid incurring cost )
- Primary Purpose: Auditing and compliance
- Common Use Cases:
- Capturing account activity for compliance and security audits.
- Monitoring user actions to detect unusual activity.
- Storing logs in Amazon S3 for long-term retention or analysis with other tools.
- Logging of Management Events and Data Events: CloudTrail distinguishes between management events (such as creating or modifying resources) and data events (specific actions taken on resources, like accessing an S3 bucket).
- Example: Creating a Lambda function is logged as a management event, while invoking that function is considered a data event.
- Default Logging for Management Events: By default, CloudTrail retains management events for the past 90 days.
- You can also create a trail to log these events to an S3 bucket for long-term storage and set up alerts on specific events.