Cursor Rules TemplatesCursor Rules Template

AWS Cost Dashboard Cursor Rules Template for AWS Billing Imports, Anomaly Detection and AI Recommendations

Cursor Rules Template for building a cloud cost optimization dashboard on AWS with billing imports, anomaly detection, and AI recommendations. Includes a copyable .cursorrules block and stack-specific project guidance.

awscursor-rulescursor-rules-templatesaws-cost-dashboardaws-cur-importsanomaly-detectionai-recommendationsbilling-importsCursor AIcloud-cost-management

Target User

Developers and platform engineers building AWS cost optimization dashboards with automated import, anomaly detection, and AI-driven recommendations

Use Cases

  • Import AWS CUR billing data into a data store
  • Detect spend anomalies across accounts and services
  • Provide AI-driven recommendations for cost optimization
  • Expose API endpoints for dashboards and alerts

Markdown Template

AWS Cost Dashboard Cursor Rules Template for AWS Billing Imports, Anomaly Detection and AI Recommendations

.cursorrules
Framework: Python (3.11) + FastAPI
Stack: aws-cost-dashboard, PostgreSQL, SQLAlchemy
Context: AWS CUR imports, daily ETL, anomaly detection, AI-driven recommendations
Version: 1

Framework Role & Context
- You are Cursor AI assisting with building a cloud cost optimization dashboard. You operate in a Python FastAPI environment backed by PostgreSQL. Provide precise, testable rules for data ingestion, validation, and AI-assisted insights.

Code Style and Style Guides
- Follow PEP8 for Python, use type hints, docstrings, and flake8-compatible linting. Ensure endpoints are asynchronous when appropriate and follow RESTful conventions.

Architecture & Directory Rules
- Backend: backend/app with modules api, core, models, services. Data: PostgreSQL with SQLAlchemy ORM. ETL: AWS CUR from S3 to staging, then to analytics tables.

Authentication & Security Rules
- Use JWT-based authentication in API endpoints. Secrets loaded from environment or AWS Secrets Manager. Ensure least-privilege IAM roles for S3 and data access, and TLS everywhere.

Database and ORM patterns
- PostgreSQL with SQLAlchemy ORM models. Migrations via Alembic. Use async sessions where supported. Validate schema at import time and on write.

Testing & Linting Workflows
- pytest for unit/integration tests, pytest-asyncio for async code. Use pre-commit hooks and CI with lint and test jobs.

Prohibited Actions and Anti-patterns
- Do not embed secrets in code. Do not parse CSVs with ad-hoc parsing; use pandas or csv with validation. Do not bypass ORM for reads. Do not hardcode AWS credentials.

Overview

Direct answer: This Cursor Rules Template provides a copy-paste-ready .cursorrules configuration for building an AWS cost optimization dashboard with AWS billing imports, anomaly detection, and AI recommendations. It targets a Python FastAPI backend, PostgreSQL data store, and a lightweight ML pipeline for anomaly scoring and recommendations.

The stack covered includes AWS Cost and Usage Reports (CUR) imports from S3, ETL to a relational store, anomaly detection to surface spend irregularities, and AI-assisted recommendations to guide optimization actions. It enforces secure data access, testability, and a clean project structure designed for production deployments with Cursor AI rules.

When to Use These Cursor Rules

  • When you need end-to-end import of AWS CUR data from S3 into PostgreSQL for dashboards.
  • When anomaly detection should flag unusual spend spikes or drift across accounts/services.
  • When you want AI-generated cost optimization recommendations surfaced to dashboards or alerts.
  • When you require a testable, secure backend with well-defined data models and APIs for cost dashboards.

Copyable .cursorrules Configuration

.cursorrules
Framework: Python (3.11) + FastAPI
Stack: aws-cost-dashboard, PostgreSQL, SQLAlchemy
Context: AWS CUR imports, daily ETL, anomaly detection, AI-driven recommendations
Version: 1

Framework Role & Context
- You are Cursor AI assisting with building a cloud cost optimization dashboard. You operate in a Python FastAPI environment backed by PostgreSQL. Provide precise, testable rules for data ingestion, validation, and AI-assisted insights.

Code Style and Style Guides
- Follow PEP8 for Python, use type hints, docstrings, and flake8-compatible linting. Ensure endpoints are asynchronous when appropriate and follow RESTful conventions.

Architecture & Directory Rules
- Backend: backend/app with modules api, core, models, services. Data: PostgreSQL with SQLAlchemy ORM. ETL: AWS CUR from S3 to staging, then to analytics tables.

Authentication & Security Rules
- Use JWT-based authentication in API endpoints. Secrets loaded from environment or AWS Secrets Manager. Ensure least-privilege IAM roles for S3 and data access, and TLS everywhere.

Database and ORM patterns
- PostgreSQL with SQLAlchemy ORM models. Migrations via Alembic. Use async sessions where supported. Validate schema at import time and on write.

Testing & Linting Workflows
- pytest for unit/integration tests, pytest-asyncio for async code. Use pre-commit hooks and CI with lint and test jobs.

Prohibited Actions and Anti-patterns
- Do not embed secrets in code. Do not parse CSVs with ad-hoc parsing; use pandas or csv with validation. Do not bypass ORM for reads. Do not hardcode AWS credentials.

Recommended Project Structure

aws-cost-dashboard/
├── backend/
│   ├── app/
│   │   ├── api/
│   │   │   └── routes.py
│   │   │   └── schemas.py
│   │   ├── core/
│   │   │   └── config.py
│   │   ├── models/
│   │   │   └── cost.py
│   │   ├── services/
│   │   │   └── aws_importer.py
│   │   └── main.py
│   ├── tests/
│   │   └── test_cost.py
│   └── requirements.txt
├── ml/
│   └── anomaly_detector.py

Core Engineering Principles

  • Explicit data contracts between stages (import, transform, load, analyze).
  • Idempotent operations for data imports to avoid duplicate records.
  • Clear separation of concerns between data ingestion, analytics, and API layers.
  • Defensive programming with validation, retries, and proper error handling.
  • Test-driven development with automated tests and CI checks.

Code Construction Rules

  • Do not hardcode credentials; fetch from environment or secret manager.
  • Do not mix business logic with API handlers; encapsulate in services.
  • Do not rely on local file paths in production; use S3 or cloud storages for inputs.
  • Do not bypass ORM for reads; use parameterized queries and ORM session management.
  • Do not skip input validation; enforce schema validation on all endpoints and ETL steps.
  • Adopt incremental migrations and versioning for database changes.

Security and Production Rules

  • Least-privilege IAM roles for S3 access and data exports.
  • Encrypt data at rest and in transit; enforce TLS for APIs and connections.
  • Rotate credentials and use secret managers; avoid embedding secrets in code.
  • Implement proper error handling without leaking sensitive details in responses.

Testing Checklist

  • Unit tests for data parsing, validation, and anomaly scoring logic.
  • Integration tests for AWS CUR import pipeline and API endpoints.
  • End-to-end tests simulating daily ETL runs and AI recommendation generation.
  • Static analysis and linting in CI (flake8/ruff) and type checks (mypy).

Common Mistakes to Avoid

  • Ignoring data quality: skip validation on CUR imports.
  • Overfitting anomaly thresholds; prefer adaptive thresholds with retraining hooks.
  • Hardcoding region-specific configurations; assume multi-region usage in production.
  • Weak secrets and improper access control on S3 exports.

Related Cursor rules templates

Explore adjacent Cursor rules templates for similar stacks, workflows, and production constraints.

FAQ

What AWS services are assumed in this Cursor Rules Template?

The template assumes AWS CUR imports from S3, a PostgreSQL data store, and a Python FastAPI backend. It anticipates an analytics layer for dashboards and a lightweight ML-enabled anomaly detector with AI-based recommendations. It also assumes secure access patterns and standard CI/CD practices for production.

Which programming language and framework are used for the backend?

The backend is implemented in Python 3.11 using FastAPI. It uses SQLAlchemy for ORM, and PostgreSQL as the data store. The structure is designed for testability, security, and easy integration with Cursor AI rules.

How does anomaly detection work in this template?

Anomaly detection uses rolling statistics and z-score based flags on daily spend aggregates across accounts and services. It highlights spikes and drift, enabling AI-generated recommendations to mitigate overages and optimize reserved capacity and commitments.

How do I import AWS billing data into the dashboard?

Import is performed via AWS CUR exports stored in S3, validated, transformed, and loaded into PostgreSQL. The workflow includes schema validation, data cleaning, and normalizing fields for consistent dashboard metrics and cost breakdowns.

Can I customize AI recommendations?

Yes. The template supports rule-based recommendations supplemented with lightweight ML. You can tune thresholds, budgets, warning levels, and suggested actions to reflect organizational policies and business goals.