Simodalstix/aws-fargate-golden-path

GitHub: Simodalstix/aws-fargate-golden-path

一套基于 AWS CDK 的生产级 ECS Fargate 容器平台黄金路径模板,集成了蓝绿部署、全面可观测性和混沌工程能力,帮助平台团队为应用团队提供标准化的基础设施交付路径。

Stars: 0 | Forks: 0

# aws-fargate-golden-path [![CDK](https://img.shields.io/badge/CDK-2.180+-orange.svg)](https://github.com/aws/aws-cdk) [![Python](https://img.shields.io/badge/Python-3.11+-blue.svg)](https://www.python.org/downloads/) [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) [![Build Status](https://img.shields.io/github/actions/workflow/status/Simodalstix/AWS-fargate-golden-path/ci.yml?branch=main)](https://github.com/Simodalstix/AWS-fargate-golden-path/actions) [![Release](https://img.shields.io/github/v/release/Simodalstix/AWS-fargate-golden-path?include_prereleases)](https://github.com/Simodalstix/AWS-fargate-golden-path/releases) 一个生产级的 ECS Fargate 容器平台 — 平台团队提供给应用团队的固定“黄金路径”。[ops-lab](https://github.com/Simodalstix) 平台系列的一部分。 **演示内容:** 不可变容器部署、通过 CodeDeploy 进行的蓝绿流量切换、用于访问的 ECS Exec(无 SSH)、Container Insights 可观测性,以及通过 FIS 进行的混沌工程 — 与 [aws-3tier-platform](https://github.com/Simodalstix/aws-3tier-platform) 中的 EC2 ASG 集群形成直接对比。 ## 架构 ![ECS Fargate Golden Path 架构](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/a841d91e18024853.svg) _架构图使用 AWS 官方图标和 Excalidraw 创建_ **平台组件:** - **共享网络** — 通过 SSM Parameter Store 来自 [aws-ops-networking](https://github.com/Simodalstix/aws-ops-networking) 的 VPC 和子网 - **共享可观测性** — 通过 SSM Parameter Store 来自 [aws-ops-observability](https://github.com/Simodalstix/aws-ops-observability) 的 SNS 告警主题 - **ECS Fargate** — 位于公有子网中的任务具有公有 IP,无 NAT 成本;启用 ECS Exec - **Aurora Serverless v2** — 写入/读取节点位于隔离子网中,通过 Secrets Manager 轮换 - **ALB** — 公有子网,WAF 防护,S3 访问日志,蓝绿目标组 - **CodeDeploy** — 蓝绿流量切换 (canary 10% → 100%),自动回滚 - **可观测性** — Container Insights,连接到共享 SNS 的 CloudWatch 告警,X-Ray 追踪 ## 前置条件 本项目读取自两个已部署的堆栈: | 依赖项 | 使用的 SSM 参数 | |---|---| | [aws-ops-networking](https://github.com/Simodalstix/aws-ops-networking) | `/ops-lab/networking/vpc-id`, `/ops-lab/networking/subnet/public-*`, `/ops-lab/networking/subnet/isolated-*` | | [aws-ops-observability](https://github.com/Simodalstix/aws-ops-observability) | `/ops-lab/shared/sns-topic-arn` | 如果它们尚未运行,请先部署。 ## 快速开始 ``` # 安装依赖 (Poetry) cd infra && poetry install # Bootstrap CDK(仅限首次) poetry run cdk bootstrap # 部署所有 stacks poetry run cdk deploy --all ``` 有关构建、部署和操作的 runbook,请参见 `docs/cli-playbooks/`。 ## 堆栈 | 堆栈 | 用途 | |---|---| | `FargateData-lab` | Aurora Serverless v2,Secrets Manager 凭证,数据库安全组 | | `FargateCompute-lab` | ECR,ECS 集群 + 服务,ALB,WAF,自动扩缩容,KMS,SSM 输出 | | `FargateObservability-lab` | CloudWatch 仪表板,连接到共享 SNS 的告警,日志组 | | `FargateDeployment-lab` | CodeDeploy 应用 + 蓝绿部署组 | | `FargateFIS-lab` | _(默认禁用)_ 故障注入实验 — ECS 任务终止,CPU 压力,Aurora 故障转移 | ## 应用端点 - `GET /` — 应用信息 - `GET /healthz` — ALB 健康检查目标 - `GET /work?ms=250` — 用于负载测试的 CPU 消耗 - `GET /db` — 数据库连接测试 ## 访问 ``` # ECS Exec — 无需 SSH,无需 bastion aws ecs execute-command \ --cluster ops-lab-fargate-cluster-lab \ --task \ --container app \ --interactive \ --command "/bin/sh" ``` ## 与 aws-3tier-platform 的对比 | | aws-3tier-platform (EC2) | aws-fargate-golden-path (Fargate) | |---|---|---| | 计算 | EC2 ASG,可变实例 | Fargate 任务,不可变容器 | | 配置管理 | 通过 SSM 使用 Puppet | 无 — 镜像即配置 | | 访问 | SSM Session Manager | ECS Exec | | 部署 | 滚动 AMI 更新 | CodeDeploy 蓝绿部署 | | 扩缩容 | ASG 策略 | ECS 任务自动扩缩容 | | 成本模型 | 常驻实例 | 按任务秒数计费 | ## 项目结构 ``` aws-fargate-golden-path/ ├── app/ # FastAPI application + Dockerfile ├── infra/ │ ├── app.py # CDK entrypoint │ ├── cdk.json │ ├── pyproject.toml # Poetry dependencies │ ├── stacks/ │ │ ├── data_stack.py # Aurora, Secrets Manager │ │ ├── compute_stack.py # ECS, ECR, ALB, WAF, scaling │ │ ├── observability_stack.py # Alarms, dashboard │ │ ├── deployment_stack.py # CodeDeploy blue/green │ │ └── fis_stack.py # Chaos experiments (disabled by default) │ ├── custom_constructs/ # Alarms, dashboards, WAF, KMS, logging bucket │ └── tests/ ├── docs/ │ ├── cli-playbooks/ │ │ ├── 01-build-and-deploy.md │ │ ├── 02-operations.md │ │ └── 03-observability.md │ └── adr/ ├── ops/ │ ├── runbooks/ │ └── gamedays/ └── diagrams/ ``` ## 测试 ``` cd infra && poetry run pytest tests/ -v ``` ## 成本 实验室配置约为 $50–80/月(Aurora Serverless v2 最小 ACU,无 NAT 网关,2 个 Fargate 任务配置为 512 CPU / 1024 MB)。
标签:API集成, Aurora Serverless, AWS, CDK, CloudWatch, CodeDeploy, DPI, ECS Fargate, Python, SRE, X-Ray, 偏差过滤, 可观测性, 基础设施, 容器平台, 微服务架构, 故障注入模拟器, 无后门, 混沌工程, 生产就绪, 自动化运维, 蓝绿部署, 请求拦截, 逆向工具, 配置错误