AgentSkillsCN

aws-cost-optimization

评估AWS成本,并生成可落地的优化建议。涵盖EC2、S3、RDS、Lambda、ECS/EKS以及数据传输等服务。在分析AWS支出、合理调整资源规模、选择定价模式(RI/节省计划/Spot实例)、实施标签策略、设置预算预警,或审计基础设施中的成本浪费时使用。

SKILL.md
--- frontmatter
name: aws-cost-optimization
description: Evaluate AWS costs and generate actionable optimization suggestions. Covers EC2, S3, RDS, Lambda, ECS/EKS, and data transfer. Use when analyzing AWS spending, right-sizing resources, choosing pricing models (RI/Savings Plans/Spot), implementing tagging strategies, setting budget alerts, or auditing infrastructure for cost waste.

AWS Cost Optimization

Evaluate current AWS costs and produce actionable optimization suggestions across compute, storage, networking, and managed services.

Do not use this skill when

  • The task targets Azure, GCP, or a non-AWS provider
  • The task is about general application performance without a cost dimension

Instructions

  1. Identify the AWS services in scope (EC2, S3, RDS, Lambda, etc.).
  2. Apply the Cost Optimization Framework top-to-bottom: Visibility → Right-Sizing → Pricing → Architecture.
  3. For each service, check the Service-Specific Quick Reference below.
  4. Generate a prioritized list of suggestions with estimated savings.
  5. For Terraform/CLI/boto3 implementation details, open references/implementation-playbook.md.

Cost Optimization Framework

1. Visibility — Know What You Spend

ActionTool / Service
Cost allocation tags on every resourceAWS Tag Editor, Tag Policies
Monthly/daily spend dashboardsCost Explorer, QuickSight
Budget alerts at 50 %, 80 %, 100 %AWS Budgets
Anomaly detectionAWS Cost Anomaly Detection
Per-team / per-env cost breakdownCost Categories, Linked Accounts

2. Right-Sizing — Stop Over-Provisioning

SignalAction
CPU < 20 % sustainedDownsize instance family or switch to Graviton
Memory < 30 % sustainedUse memory-optimized → general purpose
EBS IOPS < provisionedSwitch gp3 / reduce provisioned IOPS
Idle resource (EIP, ELB, NAT, EBS)Delete or stop
Lambda memory > 2× neededRun aws lambda get-function-configuration and tune

Use AWS Compute Optimizer and Trusted Advisor for automated right-sizing recommendations.

3. Pricing Models — Pay Less Per Unit

ModelSavingsBest ForCommitment
On-Demand0 %Spiky, unpredictableNone
Savings Plans (Compute)up to 66 %Steady compute (EC2, Fargate, Lambda)1 or 3 yr
Savings Plans (EC2 Instance)up to 72 %Known instance family & region1 or 3 yr
Reserved Instances (Standard)up to 72 %Steady-state, known type1 or 3 yr
Reserved Instances (Convertible)up to 54 %Steady-state, flexible type1 or 3 yr
Spot Instancesup to 90 %Fault-tolerant batch, CI/CD, HPCNone (2-min notice)

Decision heuristic:

  1. Steady 24/7 → Savings Plan or RI
  2. Batch / stateless → Spot with On-Demand fallback
  3. Unknown workload → start On-Demand, analyze with Cost Explorer, then commit

4. Architecture — Spend Smarter

PatternWhy
Serverless FirstZero idle cost; Lambda, Step Functions, EventBridge
Graviton (ARM) instances20-40 % cheaper at same performance
Multi-tier S3 storageAuto-transition hot → IA → Glacier → Deep Archive
Caching (ElastiCache, CloudFront)Reduce origin hits and data transfer
VPC EndpointsEliminate NAT Gateway data processing charges
Regional consolidationReduce cross-region transfer costs

Service-Specific Quick Reference

EC2

  • Use Graviton (c7g, m7g, r7g) for 20-40 % cost reduction.
  • Mix Spot + On-Demand via Capacity-Optimized allocation in ASGs.
  • Enable auto-scaling with target tracking (CPU 60-70 %).
  • Schedule dev/staging instances off-hours with Instance Scheduler.

S3

Storage ClassUse Casevs Standard
StandardFrequently accessedbaseline
Standard-IAAccessed < 1×/month–45 %
One Zone-IANon-critical, infrequent–60 %
Glacier Instant RetrievalQuarterly access, ms retrieval–68 %
Glacier Flexible RetrievalAnnual access, hours retrieval–78 %
Deep ArchiveCompliance / 7-yr retention–95 %

Implement S3 Intelligent-Tiering when access patterns are unpredictable. Use S3 Lifecycle rules for deterministic transitions (see playbook).

RDS / Aurora

EnvironmentRecommended Tier
Developmentdb.t4g.microdb.t4g.small
Stagingdb.t4g.mediumdb.t4g.large
Productiondb.r7g.xlarge + read replicas
  • Use Aurora Serverless v2 for variable traffic.
  • Enable RDS Reserved Instances for production.
  • Use Aurora I/O-Optimized if I/O costs > 25 % of total DB cost.

Lambda

  • Right-size memory with AWS Lambda Power Tuning.
  • Use Graviton2 (arm64 architecture) for ~34 % cost reduction.
  • Enable Provisioned Concurrency only when cold-start SLA < 100 ms.
  • Prefer Step Functions over chained Lambdas to avoid idle billing.

ECS / EKS

  • Use Fargate Spot for fault-tolerant tasks (up to 70 % savings).
  • Use Compute Savings Plans for steady Fargate workloads.
  • For EKS: enable Karpenter for intelligent node provisioning.
  • Right-size task/pod CPU and memory with Container Insights.

Data Transfer

PathCostMitigation
Same AZFreeCo-locate services
Cross-AZ$0.01/GB each wayUse AZ-aware routing
Internet egress$0.09/GB first 10 TBCloudFront ($0.085/GB), S3 Transfer Acceleration
Cross-region$0.02/GBConsolidate regions; use Global Accelerator
NAT Gateway processing$0.045/GBVPC Endpoints for S3/DynamoDB

Tagging Strategy (Mandatory)

Every AWS resource MUST have these tags:

Tag KeyExamplePurpose
EnvironmentproductionFilter by env
ProjectnavigatorCost allocation
CostCenterengineeringChargeback
Ownerteam@example.comAccountability
ManagedByterraformAudit

Enforce via AWS Organizations Tag Policies and SCP deny rules.


Cost Evaluation Workflow

When asked to evaluate costs, follow this sequence:

  1. Inventory: List services, instance types, storage volumes, and data flows.
  2. Tag audit: Check for missing cost-allocation tags.
  3. Utilization check: Review CloudWatch metrics (CPU, memory, IOPS, network).
  4. Pricing check: Compare current pricing model vs optimal (RI/SP/Spot).
  5. Architecture review: Identify unnecessary data transfer, missing caching, idle resources.
  6. Report: Produce a table of findings with:
    • Resource / Service
    • Current monthly cost (estimated or from Cost Explorer)
    • Suggested action
    • Estimated savings (% and $)
    • Effort (low / medium / high)
    • Risk (low / medium / high)

Tools

  • AWS Cost Explorer — Spend trends, forecasting, RI/SP recommendations
  • AWS Compute Optimizer — EC2, EBS, Lambda right-sizing
  • AWS Trusted Advisor — Idle resources, under-utilized instances
  • AWS Cost Anomaly Detection — ML-based spend anomaly alerts
  • AWS Budgets — Threshold alerts and auto-actions
  • Kubecost — Kubernetes cost allocation (EKS)

Implementation Details

For Terraform, AWS CLI, and boto3 code examples, see implementation-playbook.md.

Related Skills

  • aws-serverless — Serverless architecture patterns (Lambda, API Gateway, DynamoDB)
  • production-dockerfile — Containerization best practices