cost-optimization

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cloud Cost Optimization

云成本优化

Strategies and patterns for optimizing cloud costs across AWS, Azure, and GCP.
覆盖AWS、Azure、GCP三大云平台的云成本优化策略与模式。

Do not use this skill when

本技能不适用场景

  • The task is unrelated to cloud cost optimization
  • You need a different domain or tool outside this scope
  • 任务与云成本优化无关
  • 需要使用本范畴之外的其他领域知识或工具

Instructions

使用说明

  • Clarify goals, constraints, and required inputs.
  • Apply relevant best practices and validate outcomes.
  • Provide actionable steps and verification.
  • If detailed examples are required, open
    resources/implementation-playbook.md
    .
  • 明确目标、约束条件和所需输入
  • 应用相关最佳实践并验证结果
  • 提供可落地的执行步骤和验证方法
  • 若需要详细示例,请打开
    resources/implementation-playbook.md

Purpose

目标

Implement systematic cost optimization strategies to reduce cloud spending while maintaining performance and reliability.
落地系统化的成本优化策略,在保证性能和可靠性的前提下降低云支出。

Use this skill when

本技能适用场景

  • Reduce cloud spending
  • Right-size resources
  • Implement cost governance
  • Optimize multi-cloud costs
  • Meet budget constraints
  • 降低云服务开支
  • 资源规格适配(Right-Sizing)
  • 落地成本治理机制
  • 优化多云部署成本
  • 满足预算约束要求

Cost Optimization Framework

成本优化框架

1. Visibility

1. 可见性

  • Implement cost allocation tags
  • Use cloud cost management tools
  • Set up budget alerts
  • Create cost dashboards
  • 落地成本分配标签
  • 使用云成本管理工具
  • 配置预算告警
  • 搭建成本看板

2. Right-Sizing

2. 资源规格优化(Right-Sizing)

  • Analyze resource utilization
  • Downsize over-provisioned resources
  • Use auto-scaling
  • Remove idle resources
  • 分析资源利用率
  • 下调过度配置资源的规格
  • 使用自动扩缩容
  • 清理闲置资源

3. Pricing Models

3. 定价模式

  • Use reserved capacity
  • Leverage spot/preemptible instances
  • Implement savings plans
  • Use committed use discounts
  • 使用预留容量
  • 利用 spot/抢占式实例
  • 购买 Savings Plans
  • 使用承诺使用折扣

4. Architecture Optimization

4. 架构优化

  • Use managed services
  • Implement caching
  • Optimize data transfer
  • Use lifecycle policies
  • 使用托管服务
  • 落地缓存机制
  • 优化数据传输
  • 使用生命周期策略

AWS Cost Optimization

AWS 成本优化

Reserved Instances

预留实例(Reserved Instances)

Savings: 30-72% vs On-Demand
Term: 1 or 3 years
Payment: All/Partial/No upfront
Flexibility: Standard or Convertible
Savings: 30-72% vs On-Demand
Term: 1 or 3 years
Payment: All/Partial/No upfront
Flexibility: Standard or Convertible

Savings Plans

Savings Plans

Compute Savings Plans: 66% savings
EC2 Instance Savings Plans: 72% savings
Applies to: EC2, Fargate, Lambda
Flexible across: Instance families, regions, OS
Compute Savings Plans: 66% savings
EC2 Instance Savings Plans: 72% savings
Applies to: EC2, Fargate, Lambda
Flexible across: Instance families, regions, OS

Spot Instances

Spot 实例

Savings: Up to 90% vs On-Demand
Best for: Batch jobs, CI/CD, stateless workloads
Risk: 2-minute interruption notice
Strategy: Mix with On-Demand for resilience
Savings: Up to 90% vs On-Demand
Best for: Batch jobs, CI/CD, stateless workloads
Risk: 2-minute interruption notice
Strategy: Mix with On-Demand for resilience

S3 Cost Optimization

S3 成本优化

hcl
resource "aws_s3_bucket_lifecycle_configuration" "example" {
  bucket = aws_s3_bucket.example.id

  rule {
    id     = "transition-to-ia"
    status = "Enabled"

    transition {
      days          = 30
      storage_class = "STANDARD_IA"
    }

    transition {
      days          = 90
      storage_class = "GLACIER"
    }

    expiration {
      days = 365
    }
  }
}
hcl
resource "aws_s3_bucket_lifecycle_configuration" "example" {
  bucket = aws_s3_bucket.example.id

  rule {
    id     = "transition-to-ia"
    status = "Enabled"

    transition {
      days          = 30
      storage_class = "STANDARD_IA"
    }

    transition {
      days          = 90
      storage_class = "GLACIER"
    }

    expiration {
      days = 365
    }
  }
}

Azure Cost Optimization

Azure 成本优化

Reserved VM Instances

预留VM实例(Reserved VM Instances)

  • 1 or 3 year terms
  • Up to 72% savings
  • Flexible sizing
  • Exchangeable
  • 1年或3年期限
  • 最高可省72%成本
  • 灵活调整规格
  • 支持兑换

Azure Hybrid Benefit

Azure 混合权益(Azure Hybrid Benefit)

  • Use existing Windows Server licenses
  • Up to 80% savings with RI
  • Available for Windows and SQL Server
  • 使用已有的Windows Server许可证
  • 搭配预留实例最高可省80%成本
  • 适用于Windows和SQL Server

Azure Advisor Recommendations

Azure Advisor 建议

  • Right-size VMs
  • Delete unused resources
  • Use reserved capacity
  • Optimize storage
  • 优化VM规格
  • 删除未使用资源
  • 使用预留容量
  • 优化存储

GCP Cost Optimization

GCP 成本优化

Committed Use Discounts

承诺使用折扣(Committed Use Discounts)

  • 1 or 3 year commitment
  • Up to 57% savings
  • Applies to vCPUs and memory
  • Resource-based or spend-based
  • 1年或3年承诺期
  • 最高可省57%成本
  • 适用于vCPU和内存
  • 基于资源或基于支出两种模式

Sustained Use Discounts

持续使用折扣(Sustained Use Discounts)

  • Automatic discounts
  • Up to 30% for running instances
  • No commitment required
  • Applies to Compute Engine, GKE
  • 自动折扣
  • 运行中的实例最高可享30%折扣
  • 无需预先承诺
  • 适用于Compute Engine、GKE

Preemptible VMs

抢占式VM(Preemptible VMs)

  • Up to 80% savings
  • 24-hour maximum runtime
  • Best for batch workloads
  • 最高可省80%成本
  • 最长运行24小时
  • 最适合批处理工作负载

Tagging Strategy

标签策略

AWS Tagging

AWS 标签配置

hcl
locals {
  common_tags = {
    Environment = "production"
    Project     = "my-project"
    CostCenter  = "engineering"
    Owner       = "team@example.com"
    ManagedBy   = "terraform"
  }
}

resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t3.medium"

  tags = merge(
    local.common_tags,
    {
      Name = "web-server"
    }
  )
}
Reference: See
references/tagging-standards.md
hcl
locals {
  common_tags = {
    Environment = "production"
    Project     = "my-project"
    CostCenter  = "engineering"
    Owner       = "team@example.com"
    ManagedBy   = "terraform"
  }
}

resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t3.medium"

  tags = merge(
    local.common_tags,
    {
      Name = "web-server"
    }
  )
}
参考: 查看
references/tagging-standards.md

Cost Monitoring

成本监控

Budget Alerts

预算告警

hcl
undefined
hcl
undefined

AWS Budget

AWS Budget

resource "aws_budgets_budget" "monthly" { name = "monthly-budget" budget_type = "COST" limit_amount = "1000" limit_unit = "USD" time_period_start = "2024-01-01_00:00" time_unit = "MONTHLY"
notification { comparison_operator = "GREATER_THAN" threshold = 80 threshold_type = "PERCENTAGE" notification_type = "ACTUAL" subscriber_email_addresses = ["team@example.com"] } }
undefined
resource "aws_budgets_budget" "monthly" { name = "monthly-budget" budget_type = "COST" limit_amount = "1000" limit_unit = "USD" time_period_start = "2024-01-01_00:00" time_unit = "MONTHLY"
notification { comparison_operator = "GREATER_THAN" threshold = 80 threshold_type = "PERCENTAGE" notification_type = "ACTUAL" subscriber_email_addresses = ["team@example.com"] } }
undefined

Cost Anomaly Detection

成本异常检测

  • AWS Cost Anomaly Detection
  • Azure Cost Management alerts
  • GCP Budget alerts
  • AWS Cost Anomaly Detection
  • Azure Cost Management 告警
  • GCP 预算告警

Architecture Patterns

架构模式

Pattern 1: Serverless First

模式1:Serverless 优先

  • Use Lambda/Functions for event-driven
  • Pay only for execution time
  • Auto-scaling included
  • No idle costs
  • 使用Lambda/云函数处理事件驱动场景
  • 仅按执行时长付费
  • 自带自动扩缩容能力
  • 无闲置成本

Pattern 2: Right-Sized Databases

模式2:规格适配的数据库

Development: t3.small RDS
Staging: t3.large RDS
Production: r6g.2xlarge RDS with read replicas
Development: t3.small RDS
Staging: t3.large RDS
Production: r6g.2xlarge RDS with read replicas

Pattern 3: Multi-Tier Storage

模式3:多层存储

Hot data: S3 Standard
Warm data: S3 Standard-IA (30 days)
Cold data: S3 Glacier (90 days)
Archive: S3 Deep Archive (365 days)
Hot data: S3 Standard
Warm data: S3 Standard-IA (30 days)
Cold data: S3 Glacier (90 days)
Archive: S3 Deep Archive (365 days)

Pattern 4: Auto-Scaling

模式4:自动扩缩容

hcl
resource "aws_autoscaling_policy" "scale_up" {
  name                   = "scale-up"
  scaling_adjustment     = 2
  adjustment_type        = "ChangeInCapacity"
  cooldown              = 300
  autoscaling_group_name = aws_autoscaling_group.main.name
}

resource "aws_cloudwatch_metric_alarm" "cpu_high" {
  alarm_name          = "cpu-high"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods  = "2"
  metric_name         = "CPUUtilization"
  namespace           = "AWS/EC2"
  period              = "60"
  statistic           = "Average"
  threshold           = "80"
  alarm_actions       = [aws_autoscaling_policy.scale_up.arn]
}
hcl
resource "aws_autoscaling_policy" "scale_up" {
  name                   = "scale-up"
  scaling_adjustment     = 2
  adjustment_type        = "ChangeInCapacity"
  cooldown              = 300
  autoscaling_group_name = aws_autoscaling_group.main.name
}

resource "aws_cloudwatch_metric_alarm" "cpu_high" {
  alarm_name          = "cpu-high"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods  = "2"
  metric_name         = "CPUUtilization"
  namespace           = "AWS/EC2"
  period              = "60"
  statistic           = "Average"
  threshold           = "80"
  alarm_actions       = [aws_autoscaling_policy.scale_up.arn]
}

Cost Optimization Checklist

成本优化检查清单

  • Implement cost allocation tags
  • Delete unused resources (EBS, EIPs, snapshots)
  • Right-size instances based on utilization
  • Use reserved capacity for steady workloads
  • Implement auto-scaling
  • Optimize storage classes
  • Use lifecycle policies
  • Enable cost anomaly detection
  • Set budget alerts
  • Review costs weekly
  • Use spot/preemptible instances
  • Optimize data transfer costs
  • Implement caching layers
  • Use managed services
  • Monitor and optimize continuously
  • 落地成本分配标签
  • 删除未使用资源(EBS、EIP、快照)
  • 基于利用率调整实例规格
  • 为稳定负载使用预留容量
  • 配置自动扩缩容
  • 优化存储层级
  • 使用生命周期策略
  • 开启成本异常检测
  • 配置预算告警
  • 每周复盘成本情况
  • 使用spot/抢占式实例
  • 优化数据传输成本
  • 落地缓存层
  • 使用托管服务
  • 持续监控和优化

Tools

工具

  • AWS: Cost Explorer, Cost Anomaly Detection, Compute Optimizer
  • Azure: Cost Management, Advisor
  • GCP: Cost Management, Recommender
  • Multi-cloud: CloudHealth, Cloudability, Kubecost
  • AWS: Cost Explorer、Cost Anomaly Detection、Compute Optimizer
  • Azure: Cost Management、Advisor
  • GCP: Cost Management、Recommender
  • 多云通用: CloudHealth、Cloudability、Kubecost

Reference Files

参考文件

  • references/tagging-standards.md
    - Tagging conventions
  • assets/cost-analysis-template.xlsx
    - Cost analysis spreadsheet
  • references/tagging-standards.md
    - 标签规范
  • assets/cost-analysis-template.xlsx
    - 成本分析表格模板

Related Skills

相关技能

  • terraform-module-library
    - For resource provisioning
  • multi-cloud-architecture
    - For cloud selection
  • terraform-module-library
    - 用于资源编排
  • multi-cloud-architecture
    - 用于云平台选型