aws-billing-and-cost-management
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBilling and Cost Management
账单与成本管理
Overview
概述
Analyze, optimize, and manage AWS costs. This skill encodes domain expertise from AWS's cost management products — gotchas, correct API usage patterns, and optimization workflows that models frequently get wrong.
分析、优化并管理AWS成本。本技能整合了AWS成本管理产品的领域专业知识——包括常见陷阱、正确的API使用模式,以及模型常出错的优化工作流。
Usage
使用场景
Use this skill when:
- Analyzing AWS spending, cost trends, or cost breakdowns
- Setting up or managing budget alerts
- Evaluating Savings Plans or Reserved Instance purchases
- Right-sizing EC2, Lambda, RDS, or EBS resources
- Looking up AWS service pricing
- Running cost audits or investigating cost spikes
- Querying CUR data with Athena
- Scoping cost analysis to a specific billing view
- Checking Free Tier usage
在以下场景中使用本技能:
- 分析AWS支出、成本趋势或成本细分
- 设置或管理预算告警
- 评估Savings Plans或Reserved Instance的购买方案
- 调整EC2、Lambda、RDS或EBS资源的规格
- 查询AWS服务定价
- 执行成本审计或调查成本激增问题
- 通过Athena查询CUR数据
- 将成本分析限定到特定账单视图
- 检查Free Tier使用情况
Core Concepts
核心概念
- Cost Explorer — query cost/usage data by service, account, tag, or time range
- Budgets — set spending thresholds with alerts; supports billing view scoping
- Billing Views — scope cost data to a subset of billing (custom view, billing group, or primary)
- Compute Optimizer — right-sizing recommendations for EC2, Lambda, EBS, RDS
- Cost Optimization Hub — aggregated savings recommendations across services
- Savings Plans / Reserved Instances — commitment-based discounts
- CUR 2.0 — detailed line-item billing data queryable via Athena
Recommended setup: Use the AWS MCP server for sandboxed execution, audit logging, and enterprise controls. See: https://docs.aws.amazon.com/aws-mcp/
Without AWS MCP: All commands use standard AWS CLI syntax and work with any agent that has CLI access.
- Cost Explorer — 按服务、账户、标签或时间范围查询成本/使用数据
- Budgets — 设置支出阈值并配置告警;支持按账单视图限定范围
- Billing Views — 将成本数据限定为账单的子集(自定义视图、账单组或主视图)
- Compute Optimizer — 针对EC2、Lambda、EBS、RDS的资源规格调整建议
- Cost Optimization Hub — 跨服务的聚合节省建议
- Savings Plans / Reserved Instances — 基于承诺的折扣方案
- CUR 2.0 — 可通过Athena查询的详细分项账单数据
推荐配置: 使用AWS MCP服务器进行沙箱执行、审计日志记录和企业级控制。参考:https://docs.aws.amazon.com/aws-mcp/
无AWS MCP时: 所有命令使用标准AWS CLI语法,适用于任何具备CLI访问权限的Agent。
Critical Rule: Always Check the Current Date
关键规则:始终检查当前日期
Before making ANY Cost Explorer, Budgets, or Savings Plans API call, you MUST determine the current date. Use a tool to get the current date and time — do NOT assume or guess the year. LLMs frequently default to dates from their training data instead of the actual current date, producing analyses of stale data that appear correct but are completely wrong.
在调用任何Cost Explorer、Budgets或Savings Plans API之前,必须确定当前日期。 使用工具获取当前日期和时间——绝不要假设或猜测年份。大语言模型经常默认使用训练数据中的日期而非实际当前日期,导致对过期数据的分析看似正确但完全错误。
Critical Rule: Deterministic Calculations
关键规则:确定性计算
You MUST NEVER perform numerical calculations (sums, averages, percentages, comparisons, counts, min/max) by reasoning in your response. LLM arithmetic is unreliable and produces wrong answers on cost data.
You MUST ALWAYS use a script or calculator tool for any math on data returned from API calls. Write a Python script that performs the calculation and prints the result. If the AWS MCP server's tool is available, use it. Otherwise, run the script locally.
run_scriptRead for patterns and examples.
references/deterministic-calculations.md绝不要通过推理在响应中执行数值计算(求和、平均值、百分比、比较、计数、最小/最大值)。 大语言模型的算术运算不可靠,会对成本数据产生错误结果。
必须始终使用脚本或计算器工具 对API调用返回的数据进行任何数学运算。编写Python脚本执行计算并打印结果。如果AWS MCP服务器的工具可用,请使用它。否则,在本地运行脚本。
run_script阅读获取模式和示例。
references/deterministic-calculations.mdDecision Guide
决策指南
| Question | Tool | Reference |
|---|---|---|
| What am I spending? Where are costs going up? | Cost Explorer | |
| How much does a service cost? | Price List API | |
| Where can I save money? (start here) | Cost Optimization Hub | |
| Should I buy Savings Plans? | CE SP Recommendations | |
| Should I buy Reserved Instances? | CE RI Recommendations | |
| Deep-dive on a specific EC2/Lambda/EBS/RDS rec? | Compute Optimizer | |
| How do I set up budget alerts? | Budgets | |
| What's causing a cost spike? | Cost Anomaly Detection | |
| Am I within Free Tier? | Free Tier API | |
| How do I reduce my bill? | Cost Audit workflow | |
| How do I query detailed billing data? | CUR 2.0 + Athena | |
| How do I optimize specific services? | Per-service patterns | |
| How do I scope costs to a billing view? | Billing Views | See Billing Views below |
| 问题 | 工具 | 参考文档 |
|---|---|---|
| 我的支出情况如何?成本增长来自哪里? | Cost Explorer | |
| 某项服务的成本是多少? | Price List API | |
| 我可以从哪些方面省钱?(从此处开始) | Cost Optimization Hub | |
| 我应该购买Savings Plans吗? | CE SP Recommendations | |
| 我应该购买Reserved Instances吗? | CE RI Recommendations | |
| 深入了解特定EC2/Lambda/EBS/RDS的建议? | Compute Optimizer | |
| 如何设置预算告警? | Budgets | |
| 成本激增的原因是什么? | Cost Anomaly Detection | |
| 我是否在Free Tier范围内? | Free Tier API | |
| 如何降低账单金额? | 成本审计工作流 | |
| 如何查询详细账单数据? | CUR 2.0 + Athena | |
| 如何优化特定服务? | 按服务分类的模式 | |
| 如何按账单视图划分成本范围? | Billing Views | 参见下方的【账单视图】 |
Common Tasks
常见任务
Analyze costs by service
按服务分析成本
bash
aws ce get-cost-and-usage \
--time-period Start=2026-03-01,End=2026-04-01 \
--granularity MONTHLY \
--metrics UnblendedCost \
--group-by Type=DIMENSION,Key=SERVICEDefault to . Exclude Credits/Refunds with . End date is exclusive.
UnblendedCost--filter '{"Not":{"Dimensions":{"Key":"RECORD_TYPE","Values":["Credit","Refund"]}}}'bash
aws ce get-cost-and-usage \
--time-period Start=2026-03-01,End=2026-04-01 \
--granularity MONTHLY \
--metrics UnblendedCost \
--group-by Type=DIMENSION,Key=SERVICE默认使用。可通过排除信用/退款项。结束日期为排他性日期。
UnblendedCost--filter '{"Not":{"Dimensions":{"Key":"RECORD_TYPE","Values":["Credit","Refund"]}}}'Run a cost audit
执行成本审计
Read for the full 7-step workflow: top cost drivers → month-over-month comparison → optimization recommendations → idle resources → commitment coverage → per-service quick wins → report.
references/cost-audit.md阅读获取完整的7步工作流:顶级成本驱动因素 → 月度对比 → 优化建议 → 闲置资源 → 承诺覆盖情况 → 按服务快速优化 → 报告。
references/cost-audit.mdGet right-sizing recommendations
获取资源规格调整建议
Compute Optimizer requires opt-in first: . Then read for EC2 or the relevant resource-specific reference.
aws compute-optimizer update-enrollment-status --status Activereferences/ec2-rightsizing.mdCompute Optimizer需要先启用:。然后阅读获取EC2相关内容,或参考对应资源的专属文档。
aws compute-optimizer update-enrollment-status --status Activereferences/ec2-rightsizing.mdLook up service pricing
查询服务定价
Read for service codes and attribute filters. Common trap: Price List API service codes differ from Cost Explorer service names.
references/pricing-lookup.md阅读获取服务代码和属性筛选器。常见陷阱:Price List API的服务代码与Cost Explorer的服务名称不同。
references/pricing-lookup.mdBilling Views
账单视图
A billing view scopes cost and usage data to a specific slice of an account's billing (e.g., a billing group, custom view, or the default primary view). When the user wants to analyze costs through a particular billing view, add to supported API calls.
--billing-view-arn账单视图将成本和使用数据限定为账户账单的特定部分(例如,账单组、自定义视图或默认主视图)。当用户希望通过特定账单视图分析成本时,在支持的API调用中添加参数。
--billing-view-arnDiscover available billing views
发现可用的账单视图
bash
aws billing list-billing-views \
--billing-view-types PRIMARY CUSTOM BILLING_GROUPRequires permission.
billing:ListBillingViewsbash
aws billing list-billing-views \
--billing-view-types PRIMARY CUSTOM BILLING_GROUP需要权限。
billing:ListBillingViewsUse a billing view with Cost Explorer
在Cost Explorer中使用账单视图
bash
aws ce get-cost-and-usage \
--time-period Start=2026-03-01,End=2026-04-01 \
--granularity MONTHLY \
--metrics UnblendedCost \
--group-by Type=DIMENSION,Key=SERVICE \
--billing-view-arn arn:aws:billing::ACCOUNT_ID:billingview/BILLING_VIEW_IDbash
aws ce get-cost-and-usage \
--time-period Start=2026-03-01,End=2026-04-01 \
--granularity MONTHLY \
--metrics UnblendedCost \
--group-by Type=DIMENSION,Key=SERVICE \
--billing-view-arn arn:aws:billing::ACCOUNT_ID:billingview/BILLING_VIEW_IDCreate a budget scoped to a billing view
创建限定到账单视图的预算
In the JSON, include the field:
--budgetBillingViewArnbash
aws budgets create-budget --account-id ACCOUNT_ID \
--budget '{
"BudgetName": "TeamX-Monthly",
"BudgetLimit": {"Amount": "1000", "Unit": "USD"},
"TimeUnit": "MONTHLY",
"BudgetType": "COST",
"BillingViewArn": "arn:aws:billing::ACCOUNT_ID:billingview/BILLING_VIEW_ID"
}'在的JSON中包含字段:
--budgetBillingViewArnbash
aws budgets create-budget --account-id ACCOUNT_ID \
--budget '{
"BudgetName": "TeamX-Monthly",
"BudgetLimit": {"Amount": "1000", "Unit": "USD"},
"TimeUnit": "MONTHLY",
"BudgetType": "COST",
"BillingViewArn": "arn:aws:billing::ACCOUNT_ID:billingview/BILLING_VIEW_ID"
}'API support for --billing-view-arn
--billing-view-arn支持--billing-view-arn
的API
--billing-view-arnSupports | Does NOT support it |
|---|---|
| |
| |
| |
| |
| |
| |
| |
|
支持 | 不支持该参数 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
|
Troubleshooting
故障排除
| Error | Cause | Fix |
|---|---|---|
| Wrong dimension key (e.g., | Use |
| Empty results with filter | Filter value doesn't match exactly | Call |
| Hourly granularity not enabled | Enable in Cost Explorer preferences |
| Not opted in | Run |
| Budgets API fails outside us-east-1 | Budgets requires us-east-1 | Set |
Cost Explorer | By design — totals excluded when grouping | Make separate call without GroupBy, or sum grouped results using a script |
| Missing permission | User needs |
| API doesn't support billing views, or malformed ARN | Check the API support table above; ARN format is |
Budget shows | Billing view access revoked or view deleted | Check |
| 错误 | 原因 | 修复方案 |
|---|---|---|
Cost Explorer出现 | 维度键错误(例如,使用 | 使用 |
| 使用筛选器后返回空结果 | 筛选值不完全匹配 | 先调用 |
小时级数据出现 | 未启用小时级粒度 | 在Cost Explorer偏好设置中启用 |
Compute Optimizer出现 | 未启用服务 | 运行 |
| us-east-1区域外调用Budgets API失败 | Budgets需要us-east-1区域 | 设置 |
Cost Explorer使用GroupBy时 | 设计如此——分组时不包含总计 | 单独调用不使用GroupBy的接口,或通过脚本对分组结果求和 |
| 缺少权限 | 用户需要 |
使用 | API不支持账单视图,或ARN格式错误 | 查看上方的API支持表;ARN格式为 |
预算显示 | 账单视图权限被撤销或视图已删除 | 在 |
Additional Resources
额外资源
- AWS Cost Management User Guide: https://docs.aws.amazon.com/cost-management/
- AWS Pricing Calculator: https://calculator.aws/
- Compute Optimizer User Guide: https://docs.aws.amazon.com/compute-optimizer/
- Well-Architected Cost Optimization Pillar: https://docs.aws.amazon.com/wellarchitected/latest/cost-optimization-pillar/
- AWS成本管理用户指南:https://docs.aws.amazon.com/cost-management/
- AWS定价计算器:https://calculator.aws/
- Compute Optimizer用户指南:https://docs.aws.amazon.com/compute-optimizer/
- 架构完善框架成本优化支柱:https://docs.aws.amazon.com/wellarchitected/latest/cost-optimization-pillar/