deploying-on-aws
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAWS Patterns
AWS架构模式
Purpose
用途
This skill provides decision frameworks and implementation patterns for Amazon Web Services. Navigate AWS's 200+ services through proven selection criteria, architectural patterns, and Well-Architected Framework principles. Focus on practical service selection, cost-aware design, and modern 2025 patterns including Lambda SnapStart, EventBridge Pipes, and S3 Express One Zone.
Use this skill when designing AWS solutions, selecting services for specific workloads, implementing serverless or container architectures, or optimizing existing AWS infrastructure for cost, performance, and reliability.
本技能为Amazon Web Services(AWS)提供决策框架与实施模式。通过经过验证的选型标准、架构模式和AWS Well-Architected Framework原则,帮助你在AWS的200+项服务中进行选型。重点关注实用的服务选型、成本感知设计,以及2025年的现代模式,包括Lambda SnapStart、EventBridge Pipes和S3 Express One Zone。
当你设计AWS解决方案、为特定工作负载选择服务、实施无服务器或容器架构,或者针对成本、性能和可靠性优化现有AWS基础设施时,可使用本技能。
When to Use This Skill
适用场景
Invoke this skill when:
- Choosing between Lambda, Fargate, ECS, EKS, or EC2 for compute workloads
- Selecting database services (RDS, Aurora, DynamoDB) based on access patterns
- Designing VPC architecture for multi-tier applications
- Implementing serverless patterns with API Gateway and Lambda
- Building container-based microservices on ECS or EKS
- Applying AWS Well-Architected Framework to designs
- Optimizing AWS costs while maintaining performance
- Implementing security best practices (IAM, KMS, encryption)
在以下场景中调用本技能:
- 为计算工作负载在Lambda、Fargate、ECS、EKS或EC2之间做选择
- 根据访问模式选择数据库服务(RDS、Aurora、DynamoDB)
- 为多层应用设计VPC架构
- 使用API Gateway和Lambda实施无服务器模式
- 在ECS或EKS上构建基于容器的微服务
- 将AWS Well-Architected Framework应用于设计方案
- 在保持性能的同时优化AWS成本
- 实施安全最佳实践(IAM、KMS、加密)
Core Service Selection Frameworks
核心服务选型框架
Compute Service Selection
计算服务选型
Decision Flow:
Execution Duration:
<15 minutes → Evaluate Lambda
>15 minutes → Evaluate containers or VMs
Event-Driven/Scheduled:
YES → Lambda (serverless)
NO → Consider traffic patterns
Containerized:
YES → Need Kubernetes?
YES → EKS
NO → ECS (Fargate or EC2)
NO → Evaluate EC2 or containerize first
Special Requirements:
GPU/Windows/BYOL licensing → EC2
Predictable high traffic → EC2 or ECS on EC2 (cost optimization)
Variable traffic → Lambda or FargateQuick Reference:
| Workload | Primary Choice | Cost Model | Key Benefit |
|---|---|---|---|
| API Backend | Lambda + API Gateway | Pay per request | Auto-scale, no servers |
| Microservices | ECS on Fargate | Pay for runtime | Simple operations |
| Kubernetes Apps | EKS | $73/mo + compute | Portability, ecosystem |
| Batch Jobs | Lambda or Fargate Spot | Request/spot pricing | Cost efficiency |
| Long-Running | EC2 Reserved Instances | 30-60% savings | Predictable cost |
For detailed service comparisons including cost examples, performance characteristics, and use case guidance, see .
references/compute-services.md决策流程:
执行时长:
<15分钟 → 评估Lambda
>15分钟 → 评估容器或虚拟机
事件驱动/定时任务:
是 → Lambda(无服务器)
否 → 考虑流量模式
容器化:
是 → 是否需要Kubernetes?
是 → EKS
否 → ECS(Fargate或EC2)
否 → 评估EC2或先进行容器化
特殊需求:
GPU/Windows/BYOL许可 → EC2
可预测的高流量 → EC2或ECS on EC2(成本优化)
可变流量 → Lambda或Fargate速查表:
| 工作负载 | 首选方案 | 计费模式 | 核心优势 |
|---|---|---|---|
| API后端 | Lambda + API Gateway | 按请求付费 | 自动扩缩容,无需管理服务器 |
| 微服务 | ECS on Fargate | 按运行时长付费 | 运维简单 |
| Kubernetes应用 | EKS | 73美元/月 + 计算资源费用 | 可移植性,生态完善 |
| 批处理任务 | Lambda或Fargate Spot | 请求/竞价实例定价 | 成本高效 |
| 长期运行任务 | EC2预留实例 | 节省30-60%成本 | 成本可预测 |
如需包含成本示例、性能特征和用例指导的详细服务对比,请查看。
references/compute-services.mdDatabase Service Selection
数据库服务选型
Decision Matrix by Access Pattern:
| Access Pattern | Data Model | Primary Choice | Key Criteria |
|---|---|---|---|
| Transactional (OLTP) | Relational | Aurora | Performance + HA |
| Simple CRUD | Relational | RDS PostgreSQL | Cost vs. features |
| Key-Value Lookups | NoSQL | DynamoDB | Serverless scale |
| Document Storage | JSON/BSON | DynamoDB | Flexibility vs. MongoDB compat |
| Caching | In-Memory | ElastiCache Redis | Speed + durability |
| Analytics (OLAP) | Columnar | Redshift/Athena | Dedicated vs. serverless |
| Time-Series | Timestamped | Timestream | Purpose-built |
Query Complexity Guide:
- Simple Key-Value: DynamoDB (single-digit ms latency)
- Moderate Joins (2-3 tables): Aurora or RDS (cost vs. performance)
- Complex Analytics: Redshift (dedicated) or Athena (serverless, query S3)
- Real-Time Streams: DynamoDB Streams + Lambda
For storage class selection, cost comparisons, and migration patterns, see .
references/database-services.md按访问模式划分的决策矩阵:
| 访问模式 | 数据模型 | 首选方案 | 核心标准 |
|---|---|---|---|
| 事务型(OLTP) | 关系型 | Aurora | 性能 + 高可用 |
| 简单CRUD | 关系型 | RDS PostgreSQL | 成本 vs. 功能 |
| 键值查询 | NoSQL | DynamoDB | 无服务器扩缩容 |
| 文档存储 | JSON/BSON | DynamoDB | 灵活性 vs. MongoDB兼容性 |
| 缓存 | 内存型 | ElastiCache Redis | 速度 + 持久性 |
| 分析型(OLAP) | 列存 | Redshift/Athena | 专用 vs. 无服务器 |
| 时序数据 | 带时间戳 | Timestream | 专为时序场景构建 |
查询复杂度指南:
- 简单键值查询: DynamoDB(单位数毫秒延迟)
- 中等关联查询(2-3张表): Aurora或RDS(成本 vs. 性能)
- 复杂分析: Redshift(专用)或Athena(无服务器,查询S3数据)
- 实时流处理: DynamoDB Streams + Lambda
如需存储类选型、成本对比和迁移模式,请查看。
references/database-services.mdStorage Service Selection
存储服务选型
Primary Decision Tree:
Data Type:
Objects (files, media) → S3 + lifecycle policies
Blocks (databases, boot volumes) → EBS
Shared Files (cross-instance) → Evaluate protocol
File Protocol Required:
NFS (Linux) → EFS
SMB (Windows) → FSx for Windows
High-Performance HPC → FSx for Lustre
Multi-Protocol + Enterprise → FSx for NetApp ONTAPCost Comparison (1TB/month):
| Service | Monthly Cost | Access Pattern |
|---|---|---|
| S3 Standard | $23 | Frequent access |
| S3 Standard-IA | $12.50 | Infrequent (>30 days) |
| S3 Glacier Instant | $4 | Archive, instant retrieval |
| EBS gp3 | $80 | Block storage |
| EFS Standard | $300 | Shared files, frequent |
| EFS IA | $25 | Shared files, infrequent |
Recommendation: Use S3 for 80%+ of storage needs. Use EFS/FSx only when shared file access is required.
For S3 storage classes, EBS volume types, and lifecycle policy examples, see .
references/storage-services.md核心决策树:
数据类型:
对象(文件、媒体) → S3 + 生命周期策略
块存储(数据库、启动卷) → EBS
共享文件(跨实例访问) → 评估协议
所需文件协议:
NFS(Linux) → EFS
SMB(Windows) → FSx for Windows
高性能HPC → FSx for Lustre
多协议 + 企业级 → FSx for NetApp ONTAP成本对比(1TB/月):
| 服务 | 月度成本 | 访问模式 |
|---|---|---|
| S3 Standard | 23美元 | 频繁访问 |
| S3 Standard-IA | 12.50美元 | 不频繁访问(>30天) |
| S3 Glacier Instant | 4美元 | 归档,即时检索 |
| EBS gp3 | 80美元 | 块存储 |
| EFS Standard | 300美元 | 共享文件,频繁访问 |
| EFS IA | 25美元 | 共享文件,不频繁访问 |
建议: 80%以上的存储需求使用S3。仅当需要共享文件访问时,才使用EFS/FSx。
如需S3存储类、EBS卷类型和生命周期策略示例,请查看。
references/storage-services.mdServerless Architecture Patterns
无服务器架构模式
Pattern 1: REST API (Lambda + API Gateway + DynamoDB)
模式1:REST API(Lambda + API Gateway + DynamoDB)
Architecture:
Client → API Gateway (HTTP API) → Lambda → DynamoDB
↓
S3 (file uploads)Use When:
- Building RESTful APIs with CRUD operations
- Variable or unpredictable traffic
- Minimal operational overhead desired
- Pay-per-request cost model acceptable
Cost Estimate (1M requests/month):
- API Gateway: $3.50
- Lambda: $3.53
- DynamoDB: ~$7.50
- Total: ~$15/month (vs. Fargate ~$35+, EC2 ~$50+)
Key Components:
- API Gateway HTTP API (cheaper than REST API)
- Lambda with appropriate memory allocation (1024MB typically optimal)
- DynamoDB on-demand billing (for variable traffic)
- CloudWatch Logs for debugging
See and for complete implementations.
examples/cdk/serverless-api/examples/terraform/serverless-api/架构:
客户端 → API Gateway (HTTP API) → Lambda → DynamoDB
↓
S3(文件上传)适用场景:
- 构建带CRUD操作的RESTful API
- 流量可变或不可预测
- 希望最小化运维开销
- 接受按请求付费的计费模式
成本估算(每月100万次请求):
- API Gateway: 3.50美元
- Lambda: 3.53美元
- DynamoDB: ~7.50美元
- 总计: ~15美元/月(对比Fargate ~35美元+/月,EC2 ~50美元+/月)
核心组件:
- API Gateway HTTP API(比REST API更便宜)
- 配置合适内存的Lambda(通常1024MB为最优)
- 按需计费的DynamoDB(适用于可变流量)
- 用于调试的CloudWatch Logs
完整实现请查看和。
examples/cdk/serverless-api/examples/terraform/serverless-api/Pattern 2: Event-Driven Processing (EventBridge + Lambda + SQS)
模式2:事件驱动处理(EventBridge + Lambda + SQS)
Architecture:
S3 Upload → EventBridge Rule → Lambda (process) → DynamoDB (metadata)
↓
SQS (downstream tasks)Use When:
- Asynchronous file processing
- Decoupled microservices communication
- Fan-out patterns (one event, multiple consumers)
- Need retry logic and dead-letter queues
Key Features (2025):
- EventBridge Pipes: Simplified source → filter → enrichment → target
- Lambda Response Streaming: Stream responses up to 20MB
- Step Functions Distributed Map: Process millions of items in parallel
See for additional patterns including Step Functions orchestration, API Gateway WebSockets, and Lambda SnapStart configuration.
references/serverless-patterns.md架构:
S3上传 → EventBridge规则 → Lambda(处理) → DynamoDB(元数据)
↓
SQS(下游任务)适用场景:
- 异步文件处理
- 解耦的微服务通信
- 扇出模式(一个事件,多个消费者)
- 需要重试逻辑和死信队列
2025年核心特性:
- EventBridge Pipes: 简化的源→过滤→增强→目标流程
- Lambda响应流: 支持流式传输最大20MB的响应
- Step Functions分布式映射: 并行处理数百万条数据
更多模式(包括Step Functions编排、API Gateway WebSockets和Lambda SnapStart配置)请查看。
references/serverless-patterns.mdContainer Architecture Patterns
容器架构模式
Pattern 1: ECS on Fargate (Serverless Containers)
模式1:ECS on Fargate(无服务器容器)
Architecture:
ALB → ECS Service (Fargate tasks) → RDS Aurora
↓
ElastiCache RedisUse When:
- Containerized applications without cluster management
- Variable traffic with auto-scaling
- Avoid EC2 instance management
- Docker-based deployment
Key Components:
- Application Load Balancer (path-based routing)
- ECS Cluster with Fargate launch type
- Task definitions (CPU, memory, container image)
- Auto-scaling based on CPU/memory or custom metrics
- Service Connect for built-in service mesh (2025 feature)
Cost Model (2 vCPU, 4GB RAM, 24/7):
- Fargate: ~$70/month
- ALB: ~$20/month
- RDS Aurora db.t3.medium: ~$50/month
- Total: ~$140/month
架构:
ALB → ECS服务(Fargate任务) → RDS Aurora
↓
ElastiCache Redis适用场景:
- 无需集群管理的容器化应用
- 可变流量,支持自动扩缩容
- 希望避免EC2实例管理
- 基于Docker的部署
核心组件:
- 应用负载均衡器(ALB,基于路径的路由)
- 使用Fargate启动类型的ECS集群
- 任务定义(CPU、内存、容器镜像)
- 基于CPU/内存或自定义指标的自动扩缩容
- 内置服务网格的Service Connect(2025年特性)
计费模式(2 vCPU,4GB内存,7*24小时运行):
- Fargate: ~70美元/月
- ALB: ~20美元/月
- RDS Aurora db.t3.medium: ~50美元/月
- 总计: ~140美元/月
Pattern 2: EKS (Kubernetes on AWS)
模式2:EKS(AWS上的Kubernetes)
Use When:
- Kubernetes expertise exists in team
- Multi-cloud or hybrid cloud strategy
- Need Kubernetes ecosystem (Helm, Operators, Istio)
- Complex workload orchestration requirements
Key Features (2025):
- EKS Auto Mode: Fully managed node lifecycle
- EKS Pod Identities: Simplified IAM (replaces IRSA)
- EKS Hybrid Nodes: Run on-premises nodes
Cost Considerations:
- EKS control plane: $73/month per cluster
- Worker nodes: Fargate or EC2 pricing
- Use EKS on Fargate for simplicity, EC2 for cost optimization
For ECS task definitions, EKS cluster setup with CDK/Terraform, and service mesh patterns, see .
references/container-patterns.md适用场景:
- 团队具备Kubernetes专业知识
- 多云或混合云战略
- 需要Kubernetes生态系统(Helm、Operators、Istio)
- 复杂工作负载编排需求
2025年核心特性:
- EKS自动模式: 全托管节点生命周期
- EKS Pod身份: 简化的IAM(替代IRSA)
- EKS混合节点: 支持运行本地节点
成本考量:
- EKS控制平面:73美元/月/集群
- 工作节点:Fargate或EC2定价
- 追求简单性选EKS on Fargate,追求成本优化选EC2
ECS任务定义、使用CDK/Terraform搭建EKS集群以及服务网格模式,请查看。
references/container-patterns.mdNetworking Essentials
网络基础
VPC Architecture
VPC架构
Standard 3-Tier Pattern:
VPC: 10.0.0.0/16
Per Availability Zone (deploy across 3 AZs):
Public Subnet: 10.0.X.0/24 (ALB, NAT Gateway)
Private Subnet: 10.0.1X.0/24 (ECS, Lambda, app tier)
Database Subnet: 10.0.2X.0/24 (RDS, Aurora, isolated)Best Practices:
- Use /16 for VPC CIDR (65,536 IPs for growth)
- Use /24 for subnet CIDRs (256 IPs, 251 usable)
- Deploy across minimum 2 AZs (3 recommended) for high availability
- Use Security Groups (stateful) for instance-level firewall
- Enable VPC Flow Logs for troubleshooting
标准三层模式:
VPC: 10.0.0.0/16
每个可用区(跨3个可用区部署):
公有子网: 10.0.X.0/24 (ALB, NAT网关)
私有子网: 10.0.1X.0/24 (ECS, Lambda, 应用层)
数据库子网: 10.0.2X.0/24 (RDS, Aurora, 隔离环境)最佳实践:
- VPC CIDR使用/16(65,536个IP,预留扩展空间)
- 子网CIDR使用/24(256个IP,251个可用)
- 至少跨2个可用区部署(推荐3个)以实现高可用
- 使用安全组(有状态)作为实例级防火墙
- 启用VPC流日志用于故障排查
Load Balancing
负载均衡
Service Selection:
| Load Balancer | Protocol | Use Case | Key Feature |
|---|---|---|---|
| ALB | HTTP/HTTPS | Web apps, APIs | Path/host routing, Lambda targets |
| NLB | TCP/UDP | High performance | Static IP, ultra-low latency |
| GWLB | Layer 3 | Security appliances | Inline inspection |
ALB Features:
- Path-based routing: → backend,
/api→ frontend/web - Host-based routing: ,
api.example.comweb.example.com - WebSocket and gRPC support
- Integration with Lambda (serverless backends)
For CloudFront CDN patterns, Route 53 routing policies, and VPC peering configurations, see .
references/networking.md服务选型:
| 负载均衡器 | 协议 | 适用场景 | 核心特性 |
|---|---|---|---|
| ALB | HTTP/HTTPS | Web应用、API | 路径/主机路由,Lambda目标 |
| NLB | TCP/UDP | 高性能场景 | 静态IP,超低延迟 |
| GWLB | 三层 | 安全设备 | 内联检查 |
ALB特性:
- 基于路径的路由:→ 后端,
/api→ 前端/web - 基于主机的路由:,
api.example.comweb.example.com - 支持WebSocket和gRPC
- 与Lambda(无服务器后端)集成
CloudFront CDN模式、Route 53路由策略和VPC对等配置,请查看。
references/networking.mdSecurity Best Practices
安全最佳实践
IAM Principles
IAM原则
Least Privilege Pattern:
json
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::my-bucket/uploads/*"
}]
}Core Practices:
- Use IAM roles (not users) for applications
- Implement least privilege (grant minimum permissions needed)
- Enable MFA for privileged users
- Use IAM Access Analyzer to validate policies
- Leverage AWS Organizations SCPs for guardrails
最小权限模式:
json
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::my-bucket/uploads/*"
}]
}核心实践:
- 为应用使用IAM角色(而非用户)
- 实施最小权限原则(仅授予所需的最小权限)
- 为特权用户启用MFA
- 使用IAM Access Analyzer验证策略
- 利用AWS Organizations SCP作为防护措施
Data Protection
数据保护
Encryption Requirements:
| Service | At-Rest Encryption | In-Transit Encryption |
|---|---|---|
| S3 | SSE-S3 or SSE-KMS | HTTPS (TLS 1.2+) |
| EBS | KMS encryption | N/A (within instance) |
| RDS/Aurora | KMS encryption | TLS connections |
| DynamoDB | KMS encryption | HTTPS API |
Secrets Management:
- Secrets Manager: Database credentials with automatic rotation
- Parameter Store: Application configuration (free tier available)
- KMS: Encryption key management (customer-managed keys)
For WAF rules, GuardDuty configuration, and network security patterns, see .
references/security.md加密要求:
| 服务 | 静态加密 | 传输中加密 |
|---|---|---|
| S3 | SSE-S3或SSE-KMS | HTTPS(TLS 1.2+) |
| EBS | KMS加密 | 不适用(实例内部) |
| RDS/Aurora | KMS加密 | TLS连接 |
| DynamoDB | KMS加密 | HTTPS API |
密钥管理:
- Secrets Manager: 自动轮转的数据库凭证
- Parameter Store: 应用配置(提供免费层)
- KMS: 加密密钥管理(客户托管密钥)
WAF规则、GuardDuty配置和网络安全模式,请查看。
references/security.mdAWS Well-Architected Framework
AWS Well-Architected Framework
Six Pillars Overview
六大支柱概述
1. Operational Excellence
- Infrastructure as code (CDK, Terraform, CloudFormation)
- Automated deployments (CI/CD pipelines)
- Observability (CloudWatch Logs, Metrics, X-Ray)
- Runbooks and playbooks for common operations
2. Security
- Strong identity foundation (IAM roles and policies)
- Defense in depth (Security Groups, NACLs, WAF)
- Data protection (encryption at rest and in transit)
- Detective controls (CloudTrail, GuardDuty, Security Hub)
3. Reliability
- Multi-AZ deployments (RDS Multi-AZ, Aurora replicas)
- Auto-scaling (EC2 ASG, ECS Service Auto Scaling)
- Backup and recovery (automated snapshots, cross-region)
- Chaos engineering (Fault Injection Simulator)
4. Performance Efficiency
- Right-size resources (use Compute Optimizer)
- Use managed services (reduce operational overhead)
- Caching strategies (CloudFront, ElastiCache, DAX)
- Monitor and optimize continuously
5. Cost Optimization
- Right-sizing compute (match capacity to demand)
- Pricing models (Reserved Instances, Savings Plans, Spot)
- Storage optimization (S3 Intelligent-Tiering, lifecycle policies)
- Cost monitoring (Cost Explorer, Budgets, Trusted Advisor)
6. Sustainability (Added 2024)
- Use Graviton processors (60% less energy, 25% better performance)
- Optimize workload placement (renewable energy regions)
- Storage efficiency (delete unused data, compression)
- Software optimization (efficient code, async processing)
For detailed pillar implementation guides, architectural review checklists, and Well-Architected Tool integration, see .
references/well-architected.md1. 运营卓越
- 基础设施即代码(CDK、Terraform、CloudFormation)
- 自动化部署(CI/CD流水线)
- 可观测性(CloudWatch日志、指标、X-Ray)
- 常见运维场景的运行手册
2. 安全性
- 坚实的身份基础(IAM角色和策略)
- 纵深防御(安全组、NACL、WAF)
- 数据保护(静态和传输中加密)
- 检测控制(CloudTrail、GuardDuty、Security Hub)
3. 可靠性
- 多可用区部署(RDS多可用区、Aurora副本)
- 自动扩缩容(EC2 Auto Scaling组、ECS服务自动扩缩容)
- 备份与恢复(自动快照、跨区域备份)
- 混沌工程(故障注入模拟器)
4. 性能效率
- 合理调整资源大小(使用Compute Optimizer)
- 使用托管服务(减少运维开销)
- 缓存策略(CloudFront、ElastiCache、DAX)
- 持续监控与优化
5. 成本优化
- 合理调整计算资源大小(匹配容量与需求)
- 定价模式(预留实例、Savings Plans、竞价实例)
- 存储优化(S3智能分层、生命周期策略)
- 成本监控(Cost Explorer、预算、Trusted Advisor)
6. 可持续性(2024年新增)
- 使用Graviton处理器(能耗降低60%,性能提升25%)
- 优化工作负载部署位置(可再生能源区域)
- 存储效率(删除未使用数据、压缩)
- 软件优化(高效代码、异步处理)
详细的支柱实施指南、架构审查清单和Well-Architected工具集成,请查看。
references/well-architected.mdInfrastructure as Code
基础设施即代码
Tool Selection
工具选型
AWS CDK (Cloud Development Kit):
- Languages: TypeScript, Python, Java, C#, Go
- Best For: AWS-native workloads, type-safe infrastructure
- Key Benefit: High-level constructs, synthesizes to CloudFormation
- Example:
examples/cdk/serverless-api/
Terraform:
- Language: HCL (HashiCorp Configuration Language)
- Best For: Multi-cloud environments
- Key Benefit: Largest ecosystem, mature state management
- Example:
examples/terraform/serverless-api/
CloudFormation:
- Language: YAML or JSON
- Best For: Native AWS integration, no additional tools
- Key Benefit: AWS service support on day 1
- Example:
examples/cloudformation/lambda-api.yaml
AWS CDK(云开发工具包):
- 支持语言: TypeScript、Python、Java、C#、Go
- 最佳适用场景: AWS原生工作负载,类型安全的基础设施
- 核心优势: 高级构造,可生成为CloudFormation模板
- 示例:
examples/cdk/serverless-api/
Terraform:
- 语言: HCL(HashiCorp配置语言)
- 最佳适用场景: 多云环境
- 核心优势: 生态最完善,成熟的状态管理
- 示例:
examples/terraform/serverless-api/
CloudFormation:
- 语言: YAML或JSON
- 最佳适用场景: 原生AWS集成,无需额外工具
- 核心优势: 新AWS服务首发支持
- 示例:
examples/cloudformation/lambda-api.yaml
CDK Quick Start
CDK快速开始
bash
undefinedbash
undefinedInstall CDK CLI
安装CDK CLI
npm install -g aws-cdk
npm install -g aws-cdk
Initialize new project
初始化新项目
cdk init app --language=typescript
npm install
cdk init app --language=typescript
npm install
Deploy infrastructure
部署基础设施
cdk bootstrap # One-time setup
cdk deploy
undefinedcdk bootstrap # 一次性设置
cdk deploy
undefinedTerraform Quick Start
Terraform快速开始
bash
undefinedbash
undefinedInstall Terraform
安装Terraform
brew install terraform # macOS
brew install terraform # macOS
Initialize project
初始化项目
terraform init
terraform init
Preview changes
预览变更
terraform plan
terraform plan
Apply changes
应用变更
terraform apply
For complete working examples with VPC networking, multi-tier applications, and event-driven architectures, see the `examples/` directory.terraform apply
包含VPC网络、多层应用和事件驱动架构的完整可运行示例,请查看`examples/`目录。Cost Optimization Strategies
成本优化策略
Compute Cost Optimization
计算成本优化
Right-Sizing:
- Use AWS Compute Optimizer for EC2/Lambda recommendations
- Monitor CloudWatch metrics (CPU, memory utilization)
- Start conservatively, scale based on actual usage
Pricing Models:
| Model | Commitment | Savings | Best For |
|---|---|---|---|
| On-Demand | None | 0% | Variable workloads |
| Savings Plans | 1-3 years | 30-40% | Flexible compute |
| Reserved Instances | 1-3 years | 30-60% | Predictable workloads |
| Spot Instances | None | 60-90% | Fault-tolerant tasks |
Graviton Advantage:
- Graviton3 instances: 25% better performance vs. Graviton2
- 60% less energy consumption
- Available: EC2, Lambda, Fargate, RDS, ElastiCache
合理调整资源大小:
- 使用AWS Compute Optimizer获取EC2/Lambda建议
- 监控CloudWatch指标(CPU、内存利用率)
- 保守起步,根据实际使用情况扩缩容
定价模式:
| 模式 | 承诺期限 | 节省比例 | 最佳适用场景 |
|---|---|---|---|
| 按需实例 | 无 | 0% | 可变工作负载 |
| Savings Plans | 1-3年 | 30-40% | 灵活计算资源 |
| 预留实例 | 1-3年 | 30-60% | 可预测工作负载 |
| 竞价实例 | 无 | 60-90% | 容错型任务 |
Graviton优势:
- Graviton3实例:性能比Graviton2提升25%
- 能耗降低60%
- 适用范围:EC2、Lambda、Fargate、RDS、ElastiCache
Storage Cost Optimization
存储成本优化
S3 Lifecycle Policies:
Day 0-30: S3 Standard ($0.023/GB)
Day 30-90: S3 Standard-IA ($0.0125/GB)
Day 90-365: S3 Glacier Instant ($0.004/GB)
Day 365+: S3 Deep Archive ($0.00099/GB)EBS Optimization:
- Use gp3 volumes (20% cheaper than gp2, configurable IOPS)
- Delete unused snapshots
- Archive old snapshots (75% cheaper)
Monitoring:
- Enable AWS Cost Explorer (free)
- Set up AWS Budgets with alerts
- Use Cost Allocation Tags for attribution
- Review Trusted Advisor cost checks
S3生命周期策略:
第0-30天: S3 Standard ($0.023/GB)
第30-90天: S3 Standard-IA ($0.0125/GB)
第90-365天: S3 Glacier Instant ($0.004/GB)
第365天以上: S3 Deep Archive ($0.00099/GB)EBS优化:
- 使用gp3卷(比gp2便宜20%,IOPS可配置)
- 删除未使用的快照
- 归档旧快照(成本降低75%)
监控:
- 启用AWS Cost Explorer(免费)
- 设置带告警的AWS预算
- 使用成本分配标签进行成本归因
- 查看Trusted Advisor的成本检查建议
Common Patterns and Examples
常见模式与示例
Serverless Three-Tier Application
无服务器三层应用
CloudFront (CDN)
→ S3 (React frontend)
→ API Gateway (REST API)
→ Lambda (business logic)
→ DynamoDB (data)
→ S3 (file storage)Complete CDK implementation:
Complete Terraform implementation:
examples/cdk/three-tier-app/examples/terraform/three-tier-app/CloudFront(CDN)
→ S3(React前端)
→ API Gateway(REST API)
→ Lambda(业务逻辑)
→ DynamoDB(数据存储)
→ S3(文件存储)完整CDK实现:
完整Terraform实现:
examples/cdk/three-tier-app/examples/terraform/three-tier-app/Containerized Microservices
容器化微服务
Route 53 (DNS)
→ CloudFront (CDN)
→ ALB (load balancer)
→ ECS Fargate (services)
→ RDS Aurora (database)
→ ElastiCache Redis (cache)Complete implementation:
examples/cdk/ecs-fargate/Route 53(DNS)
→ CloudFront(CDN)
→ ALB(负载均衡器)
→ ECS Fargate(服务)
→ RDS Aurora(数据库)
→ ElastiCache Redis(缓存)完整实现:
examples/cdk/ecs-fargate/Event-Driven Data Pipeline
事件驱动数据流水线
S3 Upload
→ EventBridge Rule
→ Lambda (transform)
→ Kinesis Firehose
→ S3 Data Lake
→ Athena (query)Complete implementation:
examples/cdk/event-driven/S3上传
→ EventBridge规则
→ Lambda(转换)
→ Kinesis Firehose
→ S3数据湖
→ Athena(查询)完整实现:
examples/cdk/event-driven/Integration with Other Skills
与其他技能的集成
Related Skills
相关技能
- infrastructure-as-code - Multi-cloud IaC concepts, CDK and Terraform patterns
- kubernetes-operations - EKS cluster operations, kubectl, Helm charts
- building-ci-pipelines - CodePipeline, CodeBuild, GitHub Actions → AWS
- secret-management - Secrets Manager rotation, Parameter Store hierarchies
- observability - CloudWatch advanced queries, X-Ray distributed tracing
- security-hardening - IAM policy best practices, security automation
- disaster-recovery - Multi-region strategies, backup automation
- infrastructure-as-code - 多云IaC概念,CDK和Terraform模式
- kubernetes-operations - EKS集群运维,kubectl,Helm图表
- building-ci-pipelines - CodePipeline、CodeBuild、GitHub Actions → AWS集成
- secret-management - Secrets Manager轮转,Parameter Store层级
- observability - CloudWatch高级查询,X-Ray分布式追踪
- security-hardening - IAM策略最佳实践,安全自动化
- disaster-recovery - 跨区域策略,备份自动化
Cross-Skill Patterns
跨技能模式
EKS + kubernetes-operations:
- Use this skill for EKS cluster provisioning (CDK/Terraform)
- Use kubernetes-operations for kubectl, Helm, application deployment
Secrets Management:
- Use this skill for Secrets Manager/Parameter Store setup
- Use secret-management skill for rotation policies, access patterns
CI/CD Integration:
- Use this skill for CodePipeline infrastructure
- Use building-ci-pipelines skill for pipeline configuration
EKS + kubernetes-operations:
- 使用本技能进行EKS集群配置(CDK/Terraform)
- 使用kubernetes-operations技能进行kubectl、Helm、应用部署
密钥管理:
- 使用本技能进行Secrets Manager/Parameter Store设置
- 使用secret-management技能配置轮转策略、访问模式
CI/CD集成:
- 使用本技能搭建CodePipeline基础设施
- 使用building-ci-pipelines技能配置流水线
Reference Documentation
参考文档
Detailed Guides
详细指南
- Compute Services: - Lambda, Fargate, ECS, EKS, EC2 deep dive
references/compute-services.md - Database Services: - RDS, Aurora, DynamoDB, ElastiCache comparison
references/database-services.md - Storage Services: - S3 classes, EBS types, EFS/FSx selection
references/storage-services.md - Networking: - VPC design, load balancing, CloudFront, Route 53
references/networking.md - Security: - IAM patterns, KMS, Secrets Manager, WAF
references/security.md - Serverless Patterns: - Advanced Lambda, Step Functions, EventBridge
references/serverless-patterns.md - Container Patterns: - ECS Service Connect, EKS Pod Identities
references/container-patterns.md - Well-Architected: - Six pillars implementation guide
references/well-architected.md
- 计算服务: - Lambda、Fargate、ECS、EKS、EC2深度解析
references/compute-services.md - 数据库服务: - RDS、Aurora、DynamoDB、ElastiCache对比
references/database-services.md - 存储服务: - S3存储类、EBS类型、EFS/FSx选型
references/storage-services.md - 网络: - VPC设计、负载均衡、CloudFront、Route 53
references/networking.md - 安全: - IAM模式、KMS、Secrets Manager、WAF
references/security.md - 无服务器模式: - 高级Lambda、Step Functions、EventBridge
references/serverless-patterns.md - 容器模式: - ECS Service Connect、EKS Pod身份
references/container-patterns.md - Well-Architected: - 六大支柱实施指南
references/well-architected.md
Working Examples
可运行示例
- CDK Examples: - TypeScript implementations
examples/cdk/ - Terraform Examples: - HCL implementations
examples/terraform/ - CloudFormation Examples: - YAML templates
examples/cloudformation/
- CDK示例: - TypeScript实现
examples/cdk/ - Terraform示例: - HCL实现
examples/terraform/ - CloudFormation示例: - YAML模板
examples/cloudformation/
Utility Scripts
实用脚本
- Cost Estimation: - Estimate infrastructure costs
scripts/cost-estimate.sh - Resource Audit: - Audit AWS resources
scripts/resource-audit.sh - Security Check: - Basic security validation
scripts/security-check.sh
- 成本估算: - 估算基础设施成本
scripts/cost-estimate.sh - 资源审计: - 审计AWS资源
scripts/resource-audit.sh - 安全检查: - 基础安全验证
scripts/security-check.sh
AWS Service Updates (2025)
AWS服务更新(2025)
Recent Innovations to Consider:
- Lambda SnapStart: Near-instant cold starts for Java functions
- Lambda Response Streaming: Stream responses up to 20MB
- EventBridge Pipes: Simplified event processing (source → filter → enrichment → target)
- S3 Express One Zone: 10x faster S3, single-digit millisecond latency
- ECS Service Connect: Built-in service mesh for ECS
- EKS Auto Mode: Fully managed Kubernetes node lifecycle
- EKS Pod Identities: Simplified IAM for pods (replaces IRSA)
- Aurora Limitless Database: Horizontal write scaling beyond single-writer limit
- DynamoDB Standard-IA: Infrequent access tables at 60% cost savings
- RDS Blue/Green Deployments: Zero-downtime version upgrades
需关注的近期创新:
- Lambda SnapStart: Java函数近乎瞬时冷启动
- Lambda响应流: 支持流式传输最大20MB的响应
- EventBridge Pipes: 简化的事件处理(源→过滤→增强→目标)
- S3 Express One Zone: 速度提升10倍的S3,单位数毫秒延迟
- ECS Service Connect: ECS内置服务网格
- EKS自动模式: 全托管Kubernetes节点生命周期
- EKS Pod身份: 简化的Pod IAM(替代IRSA)
- Aurora无限数据库: 突破单写节点限制的水平写扩缩容
- DynamoDB Standard-IA: 不频繁访问表,成本节省60%
- RDS蓝绿部署: 零停机版本升级
Quick Decision Checklist
快速决策清单
Before choosing a service, answer:
- Traffic Pattern: Predictable or variable? (affects compute choice)
- Data Model: Relational, key-value, document, or graph? (affects database choice)
- Access Pattern: Frequent, infrequent, or archive? (affects storage class)
- Latency Requirements: Milliseconds, seconds, or minutes acceptable?
- Scaling Needs: Vertical (bigger instances) or horizontal (more instances)?
- Operational Overhead: Prefer managed services or need control?
- Cost Sensitivity: Optimize for cost, performance, or balance?
- Compliance Requirements: Data residency, encryption, audit logging needed?
Then consult the relevant decision framework in this skill or detailed references.
选择服务前,请回答:
- 流量模式: 可预测还是可变?(影响计算服务选择)
- 数据模型: 关系型、键值、文档还是图?(影响数据库选择)
- 访问模式: 频繁、不频繁还是归档?(影响存储类选择)
- 延迟要求: 可接受毫秒、秒还是分钟级延迟?
- 扩缩容需求: 垂直(更大实例)还是水平(更多实例)?
- 运维开销: 偏好托管服务还是需要控制权?
- 成本敏感度: 优先优化成本、性能还是平衡两者?
- 合规要求: 是否需要数据驻留、加密、审计日志?
然后参考本技能中的相关决策框架或详细参考文档。
Getting Started
快速上手
For New AWS Projects:
- Define architecture using Well-Architected Framework pillars
- Choose compute service using decision tree (Lambda/Fargate/ECS/EKS/EC2)
- Select database based on access patterns and data model
- Design VPC with 3-tier subnet architecture
- Implement IaC using CDK or Terraform (see examples/)
- Apply security best practices (IAM, encryption, logging)
- Set up monitoring and cost tracking
For Existing AWS Projects:
- Run AWS Trusted Advisor for recommendations
- Review Well-Architected Framework pillars
- Optimize costs (right-size, Reserved Instances, storage lifecycle)
- Migrate to modern services (EC2 → Fargate, RDS → Aurora)
- Improve security posture (enable GuardDuty, implement least privilege)
- Automate with IaC (reverse-engineer to Terraform or CDK)
针对新AWS项目:
- 使用Well-Architected Framework支柱定义架构
- 使用决策树选择计算服务(Lambda/Fargate/ECS/EKS/EC2)
- 根据访问模式和数据模型选择数据库
- 设计带三层子网的VPC
- 使用CDK或Terraform实施IaC(查看examples/)
- 应用安全最佳实践(IAM、加密、日志)
- 设置监控和成本追踪
针对现有AWS项目:
- 运行AWS Trusted Advisor获取建议
- 回顾Well-Architected Framework支柱
- 优化成本(合理调整资源大小、预留实例、存储生命周期)
- 迁移到现代服务(EC2 → Fargate,RDS → Aurora)
- 提升安全态势(启用GuardDuty,实施最小权限)
- 使用IaC自动化(反向生成为Terraform或CDK)