Thursday, October 23, 2025

AWS - CloudTrail Vs Cloudwatch

AWS CloudTrail vs CloudWatch is a common area of confusion, especially since both are logging and monitoring tools, but they serve very different purposes.

Here’s a clear, side-by-side breakdown from an AWS architecture and security perspective:


AWS CloudTrail vs CloudWatch

FeatureCloudTrailCloudWatch
PurposeAudit and log API activity across AWS servicesMonitor performance, logs, and metrics of applications and AWS resources
Primary Use CaseSecurity auditing, compliance, forensics, user activity trackingSystem performance, operational health, alerting, log analytics
What it CapturesAPI calls (who did what, when, where, from where)Logs, metrics, and events from AWS resources and apps
ScopeAccount-level activity across all regionsResource-level metrics and logs
Data SourceAWS service control plane (e.g., IAM, EC2, S3 APIs)Resource metrics, custom metrics, application logs
Event FormatStructured JSON audit logsMetrics (numbers), logs (unstructured/semi-structured), dashboards
Delivery TargetS3 (by default), CloudWatch Logs (optionally), CloudTrail LakeCloudWatch Console, Logs, Alarms, Dashboards
Real-time Alerts?Not directly (can trigger via CloudWatch)Yes — native alerting with CloudWatch Alarms
RetentionDepends on S3 bucket policy or CloudTrail LakeConfigurable (default 14 days for metrics)
CostFree for basic management events; charges for data events, Insights, LakeCharges for metrics, logs, dashboards, alarms

When to Use Each

Use CaseUse CloudTrailUse CloudWatch
Track who accessed or modified a resource✅ Yes❌ No
Set an alarm when CPU > 80%❌ No✅ Yes
Detect a user disabling MFA or deleting logs✅ Yes❌ No
View S3 read/write object access✅ Yes (with Data Events)❌ Not by default
Get alerted when Lambda errors spike❌ Not natively✅ Yes
Log your application output (stdout, errors)❌ No✅ Yes (CloudWatch Logs)

Analogy

  • CloudTrail is like a security camera recording who did what in your AWS account.

  • CloudWatch is like a dashboard and alarm system monitoring how things are performing, and notifying you when something goes wrong.


How They Work Together

They’re often used together for full observability and security:

  • CloudTrail can send logs to CloudWatch Logs, where you can:

    • Create metric filters

    • Trigger CloudWatch Alarms

    • Integrate with SNS or Lambda for automated responses

Example: You can detect and alert when someone disables CloudTrail logging using a CloudWatch Alarm on a specific API call (StopLogging).


Example Use in Real-World Scenario:

Goal: Detect when an IAM user deletes a security group

  1. CloudTrail logs the API call: DeleteSecurityGroup

  2. This event is sent to CloudWatch Logs via a Trail

  3. A Metric Filter in CloudWatch detects this pattern

  4. A CloudWatch Alarm triggers an SNS notification or Lambda function

No comments:

Post a Comment

CI/CD - Safe DB Changes/Migrations

Safe DB Migrations means updating your database schema without breaking the running application and without downtime . In real systems (A...