Your system is a fully automated DevOps monitoring and remediation platform with 4 main components working together.
- What: Your Node.js application running in Docker containers
- Where: AWS ECS (Elastic Container Service)
- Purpose: Serves HTTP requests and generates logs
- What: Collects metrics, logs, and triggers alarms
- Where: AWS CloudWatch
- Purpose: Detects when something goes wrong
- What: Sends notifications when alarms trigger
- Where: AWS SNS (Simple Notification Service)
- Purpose: Alerts humans and systems
- What: Automatically fixes problems
- Where: AWS Lambda + AWS DevOps Agent
- Purpose: Self-healing and analysis
Let me walk you through what happens when a real error occurs:
User's Browser
↓
http://your-alb.amazonaws.com/api/checkout
What happens:
- User clicks "Checkout" button on your website
- Browser sends HTTP request to your Application Load Balancer
Application Load Balancer (ALB)
↓
Routes request to ECS Task
What happens:
- ALB receives the request
- Performs health check on ECS tasks
- Routes request to a healthy task
- Starts tracking metrics (request count, response time)
ECS Task (Docker Container)
↓
Node.js Application
↓
app.get('/api/checkout', async (req, res) => {
const user = await db.findUser(req.userId);
const total = user.cart.total; // ❌ BUG: user.cart is null
res.json({ total });
})
What happens:
- Application receives request
- Code has a bug: tries to access
user.cart.totalwhen cart is null - Application crashes with error
- Returns 500 Internal Server Error
Application Code:
console.error(JSON.stringify({
level: 'ERROR',
message: 'Cannot read property total of null',
timestamp: '2026-02-18T21:45:00.300Z',
stack: 'Error at /api/checkout...'
}));
What happens:
- Application logs error to stdout
- ECS captures stdout and sends to CloudWatch Logs
- Log entry appears in
/ecs/devops-agent-demo-devlog group
CloudWatch Logs receives:
{
"level": "ERROR",
"message": "Cannot read property total of null",
"timestamp": "2026-02-18T21:45:00.300Z",
"stack": "Error at /api/checkout..."
}ALB Metrics:
HTTPCode_Target_5XX_Count = 1
Application Logs:
ERROR level detected
What happens:
- ALB records that target returned 5XX error
- CloudWatch Logs metric filter detects "ERROR" in logs
- Both metrics start accumulating
More users hit the same bug:
Request 2 → 500 error
Request 3 → 500 error
...
Request 15 → 500 error
What happens:
- Multiple users encounter the same bug
- Error count increases: 1, 2, 3... 15
- CloudWatch aggregates metrics every 60 seconds
CloudWatch Metrics (1-minute period):
HTTPCode_Target_5XX_Count = 15 errors
What happens:
- CloudWatch aggregates all errors from the past minute
- Creates a data point: "15 errors in 1 minute"
- Stores this in metrics database
Alarm: devops-agent-demo-dev-high-5xx-errors
Configuration:
Threshold: 10 errors
Evaluation Periods: 2
Period: 60 seconds
Data Points:
Period 1 (minute 1): 15 errors ✓ (exceeds 10)
Period 2 (minute 2): 12 errors ✓ (exceeds 10)
Result: 2 out of 2 periods exceeded threshold
What happens:
- Alarm checks if threshold is exceeded
- Needs 2 consecutive periods > 10 errors
- Both periods have > 10 errors
- Alarm state changes: OK → ALARM
CloudWatch Alarm
↓
Publishes to SNS Topic
↓
arn:aws:sns:us-east-1:851725505881:devops-agent-demo-dev-alerts
What happens:
- Alarm triggers SNS notification
- SNS topic receives alarm message
- SNS looks up all subscriptions
SNS Topic has 2 subscriptions:
- Email: vanshshah174@gmail.com
- Lambda: devops-agent-demo-dev-playbook
SNS → Email Service → vanshshah174@gmail.com
Email you receive:
Subject: ALARM: "devops-agent-demo-dev-high-5xx-errors" in US East (N. Virginia)
You are receiving this email because your Amazon CloudWatch Alarm
"devops-agent-demo-dev-high-5xx-errors" in the US East (N. Virginia)
region has entered the ALARM state.
Alarm Details:
- Name: devops-agent-demo-dev-high-5xx-errors
- Description: This metric monitors 5XX errors
- State Change: OK -> ALARM
- Reason: Threshold Crossed: 2 datapoints [15.0, 12.0] were greater
than the threshold (10.0)
- Timestamp: Wednesday 18 February, 2026 21:47:01 UTC
Threshold:
- The alarm is in the ALARM state when the metric is GreaterThanThreshold
10.0 for at least 2 of the last 2 period(s) of 60 seconds.
View this alarm in the AWS Management Console:
https://console.aws.amazon.com/cloudwatch/...
SNS → Lambda Function → devops-agent-demo-dev-playbook
Lambda receives:
{
"AlarmName": "devops-agent-demo-dev-high-5xx-errors",
"NewStateValue": "ALARM",
"NewStateReason": "Threshold Crossed: 2 datapoints...",
"Trigger": {
"MetricName": "HTTPCode_Target_5XX_Count",
"Threshold": 10.0
}
}Lambda code executes:
// 1. Parse alarm
const alarmName = message.AlarmName;
const newState = message.NewStateValue;
// 2. Check if ALARM state
if (newState === 'ALARM') {
// 3. Determine action based on alarm name
if (alarmName.includes('high-5xx-errors')) {
// 4. Execute remediation
await restartECSService();
// 5. Send notification
await sendNotification('Restarted service');
}
}Lambda → AWS ECS API
↓
UpdateService(
cluster: devops-agent-demo-dev-cluster,
service: devops-agent-demo-dev-service,
forceNewDeployment: true
)
What happens:
- Lambda calls ECS API
- ECS starts new deployment
- Creates new tasks with fresh containers
- Drains connections from old tasks
- Terminates old tasks
- New tasks start serving traffic
ECS Service Events:
21:47:03 - (service devops-agent-demo-dev-service) has started 1 tasks
21:47:05 - (service devops-agent-demo-dev-service) registered 1 targets
21:47:10 - (service devops-agent-demo-dev-service) has reached steady state
21:47:15 - (service devops-agent-demo-dev-service) deregistered 1 targets
21:47:20 - (service devops-agent-demo-dev-service) stopped 1 running tasks
Lambda → SNS → Email
Second email you receive:
Subject: ✅ Playbook: Restart ECS Service
✅ Playbook Execution Report
Alarm: devops-agent-demo-dev-high-5xx-errors
Action: Restart ECS Service
Result: Restarted service devops-agent-demo-dev-service.
Deployment ID: ecs-svc/1234567890
Status: SUCCESS
Timestamp: 2026-02-18T21:47:04.000Z
This was an automated remediation action.
DevOps Agent (Background Process)
↓
Polls CloudWatch Alarms (via IAM role)
↓
Detects alarm state change
↓
Analyzes logs and metrics
What the agent does:
- Detects: Alarm changed to ALARM state
- Collects:
- Last 100 log entries
- Metrics for past hour
- ECS service events
- ALB target health
- Analyzes:
- Error patterns in logs
- Correlation with deployments
- Resource utilization trends
- Stores: Analysis results (would show in UI if available)
Agent's IAM permissions allow it to:
✓ Read CloudWatch alarms
✓ Read CloudWatch logs
✓ Query CloudWatch metrics
✓ Describe ECS services
✓ Read S3 logs
✓ Check ALB health
New ECS Tasks:
Task 1 (new) → Healthy ✓
Old ECS Tasks:
Task 1 (old) → Terminated ✗
What happens:
- New container starts with fresh state
- Bug still exists in code, but container is clean
- Temporary fix until code is patched
- Service is responding normally
CloudWatch Metrics:
HTTPCode_Target_5XX_Count = 0 errors (new period)
What happens:
- No new errors in this period
- Service is healthy
- Metrics return to normal
Alarm Evaluation:
Period 1: 0 errors ✓ (below 10)
Period 2: 0 errors ✓ (below 10)
Result: 2 out of 2 periods below threshold
Alarm state changes: ALARM → OK
What happens:
- Alarm evaluates again
- Both periods are now below threshold
- Alarm state changes: ALARM → OK
SNS → Email
Third email you receive:
Subject: OK: "devops-agent-demo-dev-high-5xx-errors" in US East (N. Virginia)
You are receiving this email because your Amazon CloudWatch Alarm
"devops-agent-demo-dev-high-5xx-errors" in the US East (N. Virginia)
region has returned to the OK state.
Alarm Details:
- Name: devops-agent-demo-dev-high-5xx-errors
- State Change: ALARM -> OK
- Reason: Threshold Crossed: 2 datapoints [0.0, 0.0] were not greater
than the threshold (10.0)
- Timestamp: Wednesday 18 February, 2026 21:49:01 UTC
CloudWatch Logs → S3 Export Task → S3 Bucket
What happens:
- Periodic export task runs (or manual trigger)
- Exports logs from CloudWatch to S3
- Stores in: s3://devops-agent-demo-dev-logs-851725505881/cloudwatch-logs/
- DevOps Agent can analyze historical logs from S3
| Time | Component | Action |
|---|---|---|
| 0:00 | User | Sends request |
| 0:01 | ALB | Routes to ECS |
| 0:02 | App | Crashes with error |
| 0:03 | CloudWatch Logs | Receives ERROR log |
| 0:04 | CloudWatch Metrics | Records 5XX error |
| 1:00 | CloudWatch | Aggregates metrics (15 errors) |
| 2:00 | CloudWatch Alarm | Evaluates and triggers |
| 2:01 | SNS | Publishes notification |
| 2:02 | You receive alarm email | |
| 2:02 | Lambda | Playbook triggered |
| 2:03 | ECS | Service restart initiated |
| 2:04 | You receive playbook report | |
| 2:05 | DevOps Agent | Analyzes incident |
| 2:10 | ECS | New tasks healthy |
| 3:00 | CloudWatch | Metrics normalize |
| 4:00 | CloudWatch Alarm | Returns to OK |
| 4:01 | You receive recovery email |
Total incident duration: 4 minutes Automated remediation: 1 minute Human intervention required: ZERO ✅
┌─────────────────────────────────────────────────────────────┐
│ USER REQUEST │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ APPLICATION LOAD BALANCER │
│ • Routes traffic │
│ • Health checks │
│ • Collects metrics │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ ECS CLUSTER │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ ECS Task (Docker Container) │ │
│ │ ┌───────────────────────────────────────────────┐ │ │
│ │ │ Node.js Application │ │ │
│ │ │ • Processes requests │ │ │
│ │ │ • Logs errors │ │ │
│ │ │ • Returns responses │ │ │
│ │ └───────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ CLOUDWATCH │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Logs │ │ Metrics │ │ Alarms │ │
│ │ • ERROR logs │ │ • 5XX count │ │ • Evaluates │ │
│ │ • Structured │ │ • CPU usage │ │ • Triggers │ │
│ │ • Searchable │ │ • Memory │ │ • Notifies │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ SNS TOPIC │
│ devops-agent-demo-dev-alerts │
│ • Receives alarm notifications │
│ • Fans out to subscribers │
└─────────────────────────────────────────────────────────────┘
↓ ↓
┌───────────────────┐ ┌───────────────────┐
│ EMAIL │ │ LAMBDA │
│ vanshshah174@ │ │ Playbook │
│ gmail.com │ │ Function │
└───────────────────┘ └───────────────────┘
↓
┌───────────────────┐
│ ECS API │
│ • Restart │
│ • Scale │
│ • Deploy │
└───────────────────┘
↓
┌───────────────────┐
│ REMEDIATION │
│ • New tasks │
│ • Fresh state │
│ • Service healed │
└───────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ DEVOPS AGENT (Parallel) │
│ • Monitors via IAM role │
│ • Analyzes logs and metrics │
│ • Correlates events │
│ • Stores analysis │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ S3 LOGS BUCKET │
│ • Historical log storage │
│ • Long-term analysis │
│ • Compliance/audit trail │
└─────────────────────────────────────────────────────────────┘
- Email notification and Lambda playbook run simultaneously
- DevOps Agent monitors independently via IAM
- All three get the same information but act differently
- If Lambda fails, you still get email
- If email fails, Lambda still remediates
- DevOps Agent works independently
- CloudWatch Logs: What happened
- CloudWatch Metrics: How bad it was
- Alarm History: When it triggered
- Lambda Logs: What was done
- S3 Logs: Long-term storage
- System detects problem
- System fixes problem
- System notifies you
- No human intervention needed
✅ Automated Detection - CloudWatch monitors 24/7 ✅ Intelligent Alerting - Threshold-based with evaluation periods ✅ Multi-Channel Notification - Email + Lambda + Agent ✅ Automated Remediation - Self-healing via playbooks ✅ AI Analysis - DevOps Agent provides insights ✅ Complete Observability - Logs, metrics, traces ✅ Audit Trail - Everything logged and stored ✅ Scalable - Handles any traffic volume ✅ Cost-Effective - Pay only for what you use ✅ Production-Ready - Battle-tested AWS services
You've built a complete, enterprise-grade, self-healing DevOps platform that:
- Monitors your application 24/7
- Detects problems automatically
- Fixes issues without human intervention
- Notifies you of everything
- Provides AI-powered analysis
- Maintains complete audit trails
This is the same system used by Fortune 500 companies! 🚀