Monitoring and Logging in AWS
Track, Visualize, and Secure Your Cloud Operations
Modern cloud environments demand visibility and control. AWS offers robust tools to help you monitor applications, infrastructure, and security in real timeβensuring performance, compliance, and rapid issue resolution.
This chapter covers Amazon CloudWatch, AWS CloudTrail, VPC Flow Logs, and Config, with real-world use cases, command-line examples, diagrams, and best practices.
π Section 1: Amazon CloudWatch
π What is Amazon CloudWatch?
Amazon CloudWatch is a fully managed monitoring and observability service for AWS cloud resources and applications.
It enables:
- Real-time metrics
- Logs collection & analysis
- Custom dashboards
- Automated alarms & actions
- Anomaly detection with machine learning
π§± CloudWatch Core Components
Component | Description |
---|---|
Metrics | Numeric data points (CPU, Memory, etc.) |
Alarms | Triggers based on metric thresholds |
Logs | Collect & analyze app/system logs |
Events | Detect state changes & route to actions |
Dashboards | Visualize metrics across services |
Insights | Query logs using powerful search syntax |
Common Use Cases
Use Case | Tools |
---|---|
Alert on high EC2 CPU usage | Alarm + SNS |
Visualize Lambda invocation time | Dashboard |
Analyze 500 errors in app logs | CloudWatch Logs |
Schedule daily snapshot backup | CloudWatch Events (EventBridge) |
Example: Create a CloudWatch Alarm for EC2 CPU
AWS Console:
- Go to CloudWatch β Alarms β Create Alarm
- Choose EC2 β Select Instance β CPUUtilization
- Set threshold:
> 70% for 5 minutes
- Add notification via SNS (email, SMS, Lambda)
AWS CLI:
aws cloudwatch put-metric-alarm \
--alarm-name "HighCPU" \
--metric-name CPUUtilization \
--namespace AWS/EC2 \
--statistic Average \
--period 300 --threshold 70 \
--comparison-operator GreaterThanThreshold \
--dimensions Name=InstanceId,Value=i-1234567890abcdef0 \
--evaluation-periods 1 \
--alarm-actions arn:aws:sns:us-east-1:111122223333:MyTopic
Dashboards β Centralized Visibility
Features:
- Add graphs, number widgets, text, and log visualizations
- Share across accounts
- Build views like βApp Healthβ, βBilling Overviewβ, or βLambda Performanceβ
π Free tier includes 10 custom metrics and 3 dashboards/month.
Advanced CloudWatch Features
- Anomaly Detection: Uses ML to detect unusual metric patterns.
- Metric Math: Combine multiple metrics in formulas.
- Composite Alarms: Combine multiple alarms into logical rules.
Section 2: AWS CloudTrail
π What is AWS CloudTrail?
AWS CloudTrail records every API call made in your AWS account. It tracks who did what, when, and from where.
This is critical for:
- Security audits
- Troubleshooting
- Compliance
- User activity monitoring
π οΈ CloudTrail Key Concepts
Feature | Description |
---|---|
Event | Every API interaction (Console, CLI, SDK) |
Trail | Configured path for capturing events |
Data Events | Fine-grained logging (e.g., S3 object-level) |
Management Events | Account-level operations (CreateUser, LaunchInstance) |
Example Use Case
- Who stopped EC2 at 3 AM?
- Who deleted an S3 bucket?
- What IP was used to update a Lambda function?
Answered via CloudTrail logs, stored in S3.
Enable CloudTrail (Console)
- Go to CloudTrail β Create Trail
- Name:
my-org-trail
- Storage: Select/Create S3 bucket
- Choose event types (Management/Data)
- Optional: Send to CloudWatch Logs
- Enable
π Keep trail enabled in multi-region for complete coverage.
Sample CloudTrail JSON Log Entry
{
"eventTime": "2025-06-22T02:18:00Z",
"eventSource": "ec2.amazonaws.com",
"eventName": "StopInstances",
"userIdentity": {
"type": "IAMUser",
"userName": "admin"
},
"sourceIPAddress": "203.0.113.10",
"requestParameters": {
"instancesSet": {
"items": [{"instanceId": "i-0abc1234567890xyz"}]
}
}
}
Section 3: VPC Flow Logs
π What Are VPC Flow Logs?
VPC Flow Logs capture IP traffic going to and from network interfaces (ENIs) within your VPC.
Use it to:
- Monitor network activity
- Identify bottlenecks
- Investigate security issues
Create a Flow Log
- Open VPC Dashboard β Flow Logs
- Choose VPC/Subnet/ENI
- Destination: CloudWatch Logs or S3
- Choose format (default, custom)
- Create
Sample Log Entry (Simplified):
version account-id interface-id srcaddr dstaddr srcport dstport protocol packets bytes start end action
2 123456789 vpc-eni123 10.0.1.10 10.0.2.12 443 8080 6 4 840 1591130677 1591130737 ACCEPT
π Use tools like Athena or CloudWatch Logs Insights to query large VPC logs.
Section 4: AWS Config
π What is AWS Config?
AWS Config records the configuration state of resources and tracks their changes over time.
Use Cases:
- Compliance auditing
- Drift detection
- Resource history tracking
Example Use Cases:
- Detect if S3 bucket becomes public
- Track who changed a Security Group rule
- Ensure all EC2s are encrypted
β Enable AWS Config:
- Go to AWS Config β Set up
- Choose resources to track (e.g., all)
- Store results in S3
- Create conformance packs to apply policies
β AWS Config integrates with AWS Security Hub and CloudWatch Events.
Monitoring Architecture Diagram
+--------------------+
| CloudWatch |
| (Metrics & Alarms)|
+--------------------+
|
+----------------------+----------------------+
| | |
+---------------+ +----------------+ +----------------+
| CloudTrail | | VPC Flow Logs | | AWS Config |
| (API Activity) | | (Network Logs) | | (Resource State)|
+---------------+ +----------------+ +----------------+
β β β
β CloudWatch Dashboards β Centralized Visibility β
Summary
Tool | Purpose | Key Features |
---|---|---|
CloudWatch | Real-time monitoring | Metrics, Alarms, Logs, Dashboards |
CloudTrail | API activity logging | Security auditing, compliance |
VPC Flow Logs | IP-level network logging | Forensics, visibility |
AWS Config | Resource state tracking | Conformance, drift detection |
π‘ Explore More AWS Tools & Resources
Educational AI Tutor
Get instant AWS-related answers and explanations using AI.
Interview Question Generator
Generate AWS interview questions for practice and preparation.
AWS Practice Quiz
Test your AWS knowledge with timed quizzes and scoring.
AWS Interview Questions
Browse frequently asked AWS interview questions with answers.