Module Overview
Estimated Time: 3-4 hours | Difficulty: Intermediate | Prerequisites: Core Concepts, Compute
- CloudWatch metrics, logs, and alarms
- X-Ray distributed tracing
- CloudTrail for audit logging
- EventBridge for event-driven automation
- Building observability dashboards
- Alerting and incident response
Observability Pillars
CloudWatch Metrics
Collect and track metrics from AWS services and custom applications.Built-in vs Custom Metrics
Publishing Custom Metrics
CloudWatch Embedded Metric Format (EMF)
CloudWatch Logs
Centralized log management for all AWS services and applications. CloudWatch Logs is often the single biggest line item on an AWS bill that teams do not expect — a service generating 100 GB of logs per day costs roughly $1,500/month in ingestion alone, before storage and queries.Log Architecture
Structured Logging Best Practices
CloudWatch Logs Insights
X-Ray Distributed Tracing
Trace requests across microservices to identify bottlenecks and errors. While metrics tell you “p99 latency is 3 seconds” and logs tell you “this function threw an error,” traces tell you “the request spent 2.5 of those 3 seconds waiting on a DynamoDB call that was throttled.” Traces are the only tool that gives you a request-level view across service boundaries.X-Ray Architecture
Instrumenting Lambda with X-Ray
CloudWatch Alarms
Automated alerts and actions based on metric thresholds.Alarm Architecture
Essential Alarms (Terraform)
CloudTrail (Audit Logging)
Track all API calls for security and compliance.CloudTrail Best Practices
🎯 Interview Questions
Q1: How would you debug a slow API response?
Q1: How would you debug a slow API response?
Systematic approach:
-
X-Ray Trace: Find the specific slow request
- Identify which service/subsegment is slow
- Check annotations for context
-
CloudWatch Metrics: Check historical patterns
- Is this a spike or gradual increase?
- Correlate with CPU, memory, connections
-
CloudWatch Logs: Find related errors
-
Service-specific checks:
- Lambda: Cold starts? Memory sufficient?
- DynamoDB: Throttling? Hot partition?
- RDS: Connection pool exhausted?
Q2: What metrics should you monitor for a web application?
Q2: What metrics should you monitor for a web application?
Essential metrics by layer:Load Balancer:
- RequestCount, TargetResponseTime
- HTTPCode_Target_5XX, HTTPCode_ELB_5XX
- HealthyHostCount, UnhealthyHostCount
- CPUUtilization, MemoryUtilization (custom)
- Lambda: Duration, Errors, Throttles
- CPUUtilization, FreeableMemory
- DatabaseConnections, ReadIOPS, WriteIOPS
- DynamoDB: ThrottledRequests
- Error rate, Latency (p50, p95, p99)
- Requests per second
- Business metrics (orders, signups)
Q3: How do you reduce CloudWatch Logs costs?
Q3: How do you reduce CloudWatch Logs costs?
Cost optimization strategies:
-
Reduce ingestion:
- Filter logs at source (log level INFO not DEBUG)
- Use sampling for high-volume logs
-
Optimize retention:
- Set appropriate retention (7-30 days for most)
- Export to S3 for long-term (cheaper)
-
Use Logs Insights efficiently:
- Narrow time ranges
- Use specific log groups
- Cache common queries
-
Consider alternatives:
- Kinesis Firehose → S3 for high volume
- OpenSearch for complex analysis
Q4: How do you set up alerting for a production system?
Q4: How do you set up alerting for a production system?
Alert hierarchy:
-
Critical (PagerDuty/immediate):
- Service down (health check failures)
- Error rate > 5%
- Latency p99 > 5s
- Security events (root login)
-
Warning (Slack/email):
- Error rate > 1%
- CPU > 80% sustained
- Disk > 85%
- Approaching quotas
-
Informational (dashboard):
- Deployment events
- Scaling events
- Cost anomalies
- Avoid alert fatigue (tune thresholds)
- Use composite alarms
- Include runbook links in alerts
Q5: CloudWatch vs third-party observability tools?
Q5: CloudWatch vs third-party observability tools?
CloudWatch advantages:
- Native integration, no agents for AWS services
- Lower cost for basic use cases
- No data egress charges
- Better visualization and correlation
- APM with code-level insights
- Multi-cloud support
- More powerful querying
- Use CloudWatch for AWS metrics/logs
- Stream to third-party for analysis
- Keep costs balanced
🧪 Hands-On Lab: Build Observability Dashboard
1
Enable X-Ray on Lambda
Add X-Ray SDK and enable active tracing
2
Create CloudWatch Dashboard
Add widgets for key metrics (CPU, errors, latency)
3
Set Up Structured Logging
Implement JSON logging with correlation IDs
4
Create Alarms
Set up CPU, error rate, and latency alarms
5
Configure CloudTrail
Enable multi-region trail with CloudWatch Logs
Next Module
CDN & Edge Services
Master CloudFront, Global Accelerator, and edge computing