CostQ 是一个基于 AWS Bedrock AgentCore 的智能云成本分析和优化平台。
┌─────────────────────────────────────────────────────────────┐
│ Route 53 → CloudFront → ELB → EKS (Frontend + Backend) │
│ ↓ │
│ AgentCore Runtime (Agent) │
│ ↓ │
│ AgentCore Gateway → MCP Servers │
└─────────────────────────────────────────────────────────────┘
- 框架: React 18 + TypeScript
- 构建工具: Vite
- UI 库: Ant Design 5
- 状态管理: Zustand
- 国际化: 支持中文、英文、日文
- 框架: FastAPI (Python 3.13)
- 数据库: PostgreSQL
- 认证: JWT
- 通信: SSE (Server-Sent Events) 流式通信
- 容器化: Docker 多阶段构建
- 编排: Kubernetes (EKS)
- CI/CD: GitHub Actions
- 云平台: AWS
- 🤖 AI 智能对话: 基于 Claude 3.5 Sonnet 的成本分析助手
- 💰 成本分析: AWS/GCP 云成本分析和优化建议
- 📊 RI/SP 分析: Reserved Instance 和 Savings Plans 推荐
- ⚡ 实时流式输出: SSE 流式通信,实时展示分析结果
- 🔐 多租户支持: 企业级多租户架构
- 📈 告警管理: 自定义成本告警和通知
- 🌍 多云支持: AWS 和 GCP 账号管理
- Node.js 20+
- Python 3.13+
- Docker
- kubectl (部署到 Kubernetes 时)
# 后端依赖
pip install -r requirements.txt
# 前端依赖
cd frontend
npm install创建 .env 文件:
# 数据库
RDS_SECRET_NAME=costq/rds/postgresql-dev
# AgentCore
AGENTCORE_RUNTIME_ARN=arn:aws:bedrock:ap-northeast-1:xxx:agentcore-runtime/xxx
# AWS
AWS_PROFILE=your-profile
AWS_REGION=ap-northeast-1# 启动后端
./start.sh
# 启动前端(新终端)
cd frontend
npm run dev# 构建并推送到 ECR
./deployment/scripts/01-build-and-push.sh# 部署应用
./deployment/scripts/02-deploy-app.sh <image-tag>costq-web/
├── frontend/ # React 前端
│ ├── src/
│ │ ├── components/ # UI 组件
│ │ ├── contexts/ # React Context
│ │ ├── services/ # API 客户端
│ │ ├── stores/ # Zustand 状态管理
│ │ └── types/ # TypeScript 类型定义
│ └── package.json
│
├── backend/ # FastAPI 后端
│ ├── api/ # API 端点
│ ├── config/ # 配置管理
│ ├── models/ # 数据模型
│ ├── services/ # 业务逻辑
│ └── main.py
│
├── deployment/ # 部署配置
│ ├── k8s/ # Kubernetes 配置
│ └── scripts/ # 部署脚本
│
├── Dockerfile # 多阶段构建
├── requirements.txt # Python 依赖
└── pyproject.toml # 项目配置
| 变量名 | 说明 |
|---|---|
AGENTCORE_RUNTIME_ARN |
AgentCore Runtime ARN |
RDS_SECRET_NAME |
数据库密钥名称 |
ENCRYPTION_KEY |
Fernet 加密密钥 |
| 变量名 | 默认值 | 说明 |
|---|---|---|
BEDROCK_MODEL_ID |
us.anthropic.claude-sonnet-4-20250514-v1:0 |
Bedrock 模型 ID |
AWS_REGION |
ap-northeast-1 |
AWS 区域 |
LOG_LEVEL |
INFO |
日志级别 |
启动后端后,访问:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- 集群: costq-eks-cluster
- Namespace: costq-fastapi
- Ingress: ALB + Route 53
- 域名: https://costq.cloudminos.jp
- App 容器: FastAPI (端口 8000)
- Nginx 容器: 静态文件服务 (端口 80)
- 清单文件: deployment/k8s/marketplace-metering-cronjob.yaml
- 作用: 每小时执行一次 AWS Marketplace metering job
- 执行入口:
python -m backend.jobs.marketplace_metering_job --fail-on-error - 默认调度:
Asia/Tokyo时区每小时第 15 分钟 - CloudFormation 主链路模式:
- 若 SNS + metering 由 CloudFormation/Lambda 负责,请不要部署该 CronJob
- 同时配置
MARKETPLACE_ENABLE_WEB_SNS_HANDLER=false - 同时配置
MARKETPLACE_ENABLE_WEB_METERING_API=false
部署:
kubectl apply -f deployment/k8s/marketplace-metering-cronjob.yaml查看状态:
kubectl get cronjob marketplace-metering -n costq-fastapi
kubectl get jobs -n costq-fastapi -l component=marketplace-metering
kubectl logs -n costq-fastapi job/<job-name>- 应用日志:
/aws/eks/costq-fastapi/app - Nginx 日志:
/aws/eks/costq-fastapi/nginx
- 后端:
GET /health - 探针: Liveness + Readiness Probe
- Python: Ruff + Black
- TypeScript: ESLint + Prettier
- 提交信息: Conventional Commits
# 后端测试
pytest
# 前端测试
cd frontend
npm test- costq-agents - Agent 代码
- costq-mcp-servers - MCP Servers
Private - All Rights Reserved
- 项目: CostQ
- GitHub: https://github.com/tonygitworld/costq-web