Start the API server:
cd apps/api
python main.pyTest single error:
curl http://localhost:8000/debug/errorTrigger CloudWatch alarm (5+ errors):
curl "http://localhost:8000/debug/spam-errors?count=10"- Method: GET
- Purpose: Generate single ERROR log for CloudWatch metric testing
- Response: HTTP 500 with
{"detail": "Simulated error"} - CloudWatch: Increments
LCopilotErrorCountmetric
curl http://localhost:8000/debug/error- Method: GET
- Purpose: Generate multiple ERROR logs to trigger CloudWatch alarms
- Parameters:
count(default: 5, max: 20) - Response: HTTP 500 with
{"detail": "Generated X errors for testing"} - CloudWatch: Triggers
LCopilot-HighErrorRatealarm when count ≥ 5
# Default (5 errors - triggers alarm)
curl http://localhost:8000/debug/spam-errors
# Custom count (10 errors)
curl "http://localhost:8000/debug/spam-errors?count=10"
# Minimal (3 errors - won't trigger alarm)
curl "http://localhost:8000/debug/spam-errors?count=3"- Method: GET
- Purpose: Generate WARNING level log (separate from errors)
- Response: HTTP 200 with success message
- CloudWatch: Can be tracked with separate WARNING metric filter
curl http://localhost:8000/debug/warning| Endpoint | Log Level | Metric Filter | Metric Name |
|---|---|---|---|
/debug/error |
ERROR | { $.level = "ERROR" } |
LCopilotErrorCount |
/debug/spam-errors |
ERROR | { $.level = "ERROR" } |
LCopilotErrorCount |
/debug/warning |
WARNING | { $.level = "WARNING" } |
LCopilotWarningCount* |
Note: WARNING metric filter needs to be created separately
| Alarm Name | Condition | Trigger Endpoint |
|---|---|---|
LCopilot-HighErrorRate |
≥ 5 errors in 1 minute | /debug/spam-errors (count≥5) |
LCopilot-CriticalErrors |
≥ 1 critical in 1 minute | /debug/critical |
# Generate one error
curl http://localhost:8000/debug/error
# Expected: LCopilotErrorCount += 1
# No alarm (below threshold)# Generate 5+ errors to trigger alarm
curl "http://localhost:8000/debug/spam-errors?count=6"
# Expected:
# - LCopilotErrorCount += 6
# - LCopilot-HighErrorRate alarm triggers
# - SNS notification sent (if configured)# Generate warning (no alarm)
curl http://localhost:8000/debug/warning
# Expected: WARNING level log
# No error count increment# Test multiple types
curl http://localhost:8000/debug/warning
curl http://localhost:8000/debug/error
curl "http://localhost:8000/debug/spam-errors?count=5"
# Expected: Mixed log levels, alarm triggers- Logs appear immediately in console
- Look for
"level": "ERROR"in JSON output
- Location: AWS Console → CloudWatch → Log groups →
lcopilot-backend - Stream:
{hostname}-{environment} - Timing: Logs appear within 1-2 minutes
- Location: AWS Console → CloudWatch → Metrics →
LCopilot/API - Metric:
LCopilotErrorCount - Timing: Metrics update within 1-2 minutes
- Location: AWS Console → CloudWatch → Alarms
- Alarm:
LCopilot-HighErrorRate - Timing: Alarm triggers within 1-2 minutes of threshold breach
- Location: Email inbox (if SNS email subscription configured)
- Subject: Contains "LCopilot-HighErrorRate"
- Timing: Email arrives within 2-3 minutes of alarm trigger
ENVIRONMENT=production # Enables CloudWatch logging
AWS_REGION=eu-north-1 # Your AWS region
AWS_ACCESS_KEY_ID=your-key # CloudWatch access
AWS_SECRET_ACCESS_KEY=your-secret # CloudWatch access- Log group:
lcopilot-backend - Metric filters:
LCopilotErrorFilter,LCopilotCriticalFilter - Alarms:
LCopilot-HighErrorRate,LCopilot-CriticalErrors - SNS topic:
lcopilot-alerts
cd apps/api
python setup_cloudwatch.py- Rate Limiting:
/debug/spam-errorslimited to max 20 errors to prevent log spam - Production Use: These endpoints should be removed or secured in production
- Cost Impact: High volume testing may incur CloudWatch logging costs
- Alarm Fatigue: Repeated testing may trigger multiple SNS notifications
To track WARNING logs separately, create this metric filter:
{
"filterName": "LCopilotWarningFilter",
"filterPattern": "{ $.level = \"WARNING\" }",
"metricTransformations": [
{
"metricName": "LCopilotWarningCount",
"metricNamespace": "LCopilot/API",
"metricValue": "1",
"defaultValue": 0
}
]
}Then track warnings with /debug/warning endpoint! 📊