AWS Cost Anomaly Detector
Production-ready AWS cost monitoring system built on Cloudflare Workers. Detects spending anomalies (>20% spikes), sends alerts via Slack/email, and provides real-time dashboards.
🎬 Interactive Demo: This dashboard shows sample AWS cost data. In production, it connects to AWS Cost Explorer API via Cloudflare Workers backend with D1 database storage.
📊 Dashboard Features:
View 30-day cost trends, detect anomalies with day-over-day and week-over-week analysis, track spending by AWS service, and configure Slack/email alerts.
Total Spend (30 days)
$1,247.83
Over 30 days
Average Daily
$41.59
Per day average
Peak Daily
$87.42
Jan 15, 2025
Anomalies (7 days)
2
Last 7 days
Demo Actions
Cost Trend (30 days)
Top Services by Cost
| Service | Total Cost | Days Active | % of Total |
|---|---|---|---|
| Amazon EC2 | $523.45 | 30 | 41.9% |
| Amazon RDS | $312.18 | 30 | 25.0% |
| Amazon S3 | $187.92 | 30 | 15.1% |
| AWS Lambda | $124.67 | 28 | 10.0% |
| Amazon CloudFront | $99.61 | 30 | 8.0% |
Recent Anomalies
| Date | Service | Current | Previous | Spike | Type | Status |
|---|---|---|---|---|---|---|
| Jan 15, 2025 | Amazon EC2 | $87.42 | $42.15 | +107.4% | Day-over-Day | Alerted |
| Jan 12, 2025 | AWS Lambda | $12.84 | $5.92 | +116.9% | Week-over-Week | Alerted |
Technical Implementation
Backend Architecture
- Cloudflare Workers: Serverless API deployed on Cloudflare's edge network for low-latency global access
- Hono Framework: Lightweight, fast web framework optimized for Workers runtime
- AWS Cost Explorer API: Fetches daily cost data grouped by service with proper credential management
- D1 Database: SQLite-based serverless database for storing historical cost data and alert configurations
- Anomaly Detection: Compares daily costs against previous day (DoD) and same day last week (WoW) to detect >20% spikes
- Alert System: Supports Slack webhooks and SendGrid email for anomaly notifications
Key Features
- Real-time dashboard with Chart.js visualization
- Demo mode with sample data for testing without AWS credentials
- Hybrid demo/production mode switching
- API key authentication for secure access
- Scheduled daily cost fetching via Cron Triggers
- Top services breakdown with percentage calculations
- Configurable alert thresholds and destinations
API Endpoints
POST /api/keys- Generate API keyGET /api/costs/summary?days=30- Get cost summaryGET /api/costs/trend?days=30- Get daily trend dataPOST /api/costs/fetch- Fetch costs from AWSGET /api/anomalies?days=7- Get detected anomaliesPOST /api/anomalies/detect- Run anomaly detectionPOST /api/alerts/send- Send pending alerts
Overview
Production-ready AWS cost monitoring system that detects spending anomalies and sends alerts. Built on Cloudflare Workers with TypeScript, featuring serverless architecture, D1 database storage, and integration with AWS Cost Explorer API.
Key Features
- Anomaly Detection: Automatically detects >20% spending spikes using day-over-day and week-over-week analysis
- Real-time Dashboard: Interactive Vue.js/Chart.js dashboard showing cost trends, top services, and anomalies
- Alert System: Configurable Slack webhooks and SendGrid email notifications
- Demo Mode: Try the dashboard with sample data before connecting AWS credentials
- Serverless Architecture: Deployed on Cloudflare Workers for global low-latency access
- D1 Database: Historical cost storage with scheduled daily updates