aws-billing-and-cost-management

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Billing 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
run_script
tool is available, use it. Otherwise, run the script locally.
Read
references/deterministic-calculations.md
for patterns and examples.
绝不要通过推理在响应中执行数值计算(求和、平均值、百分比、比较、计数、最小/最大值)。 大语言模型的算术运算不可靠,会对成本数据产生错误结果。
必须始终使用脚本或计算器工具 对API调用返回的数据进行任何数学运算。编写Python脚本执行计算并打印结果。如果AWS MCP服务器的
run_script
工具可用,请使用它。否则,在本地运行脚本。
阅读
references/deterministic-calculations.md
获取模式和示例。

Decision Guide

决策指南

QuestionToolReference
What am I spending? Where are costs going up?Cost Explorer
references/cost-explorer.md
How much does a service cost?Price List API
references/pricing-lookup.md
Where can I save money? (start here)Cost Optimization Hub
references/cost-optimization-hub.md
Should I buy Savings Plans?CE SP Recommendations
references/savings-plans.md
Should I buy Reserved Instances?CE RI Recommendations
references/reserved-instances.md
Deep-dive on a specific EC2/Lambda/EBS/RDS rec?Compute Optimizer
references/ec2-rightsizing.md
,
references/lambda-optimization.md
,
references/rds-optimization.md
,
references/ebs-optimization.md
How do I set up budget alerts?Budgets
references/budgets.md
What's causing a cost spike?Cost Anomaly Detection
references/cost-explorer.md
Am I within Free Tier?Free Tier API
references/free-tier.md
How do I reduce my bill?Cost Audit workflow
references/cost-audit.md
How do I query detailed billing data?CUR 2.0 + Athena
references/cur-athena.md
How do I optimize specific services?Per-service patterns
references/service-optimization.md
How do I scope costs to a billing view?Billing ViewsSee Billing Views below
问题工具参考文档
我的支出情况如何?成本增长来自哪里?Cost Explorer
references/cost-explorer.md
某项服务的成本是多少?Price List API
references/pricing-lookup.md
我可以从哪些方面省钱?(从此处开始)Cost Optimization Hub
references/cost-optimization-hub.md
我应该购买Savings Plans吗?CE SP Recommendations
references/savings-plans.md
我应该购买Reserved Instances吗?CE RI Recommendations
references/reserved-instances.md
深入了解特定EC2/Lambda/EBS/RDS的建议?Compute Optimizer
references/ec2-rightsizing.md
,
references/lambda-optimization.md
,
references/rds-optimization.md
,
references/ebs-optimization.md
如何设置预算告警?Budgets
references/budgets.md
成本激增的原因是什么?Cost Anomaly Detection
references/cost-explorer.md
我是否在Free Tier范围内?Free Tier API
references/free-tier.md
如何降低账单金额?成本审计工作流
references/cost-audit.md
如何查询详细账单数据?CUR 2.0 + Athena
references/cur-athena.md
如何优化特定服务?按服务分类的模式
references/service-optimization.md
如何按账单视图划分成本范围?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=SERVICE
Default to
UnblendedCost
. Exclude Credits/Refunds with
--filter '{"Not":{"Dimensions":{"Key":"RECORD_TYPE","Values":["Credit","Refund"]}}}'
. End date is exclusive.
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
references/cost-audit.md
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步工作流:顶级成本驱动因素 → 月度对比 → 优化建议 → 闲置资源 → 承诺覆盖情况 → 按服务快速优化 → 报告。

Get right-sizing recommendations

获取资源规格调整建议

Compute Optimizer requires opt-in first:
aws compute-optimizer update-enrollment-status --status Active
. Then read
references/ec2-rightsizing.md
for EC2 or the relevant resource-specific reference.
Compute Optimizer需要先启用:
aws compute-optimizer update-enrollment-status --status Active
。然后阅读
references/ec2-rightsizing.md
获取EC2相关内容,或参考对应资源的专属文档。

Look up service pricing

查询服务定价

Read
references/pricing-lookup.md
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的服务名称不同。

Billing 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
--billing-view-arn
to supported API calls.
账单视图将成本和使用数据限定为账户账单的特定部分(例如,账单组、自定义视图或默认主视图)。当用户希望通过特定账单视图分析成本时,在支持的API调用中添加
--billing-view-arn
参数。

Discover available billing views

发现可用的账单视图

bash
aws billing list-billing-views \
  --billing-view-types PRIMARY CUSTOM BILLING_GROUP
Requires
billing:ListBillingViews
permission.
bash
aws billing list-billing-views \
  --billing-view-types PRIMARY CUSTOM BILLING_GROUP
需要
billing:ListBillingViews
权限。

Use 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_ID
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_ID

Create a budget scoped to a billing view

创建限定到账单视图的预算

In the
--budget
JSON, include the
BillingViewArn
field:
bash
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"
  }'
--budget
的JSON中包含
BillingViewArn
字段:
bash
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
的API

Supports
--billing-view-arn
Does NOT support it
ce get-cost-and-usage
ce get-reservation-coverage
ce get-cost-and-usage-with-resources
ce get-reservation-utilization
ce get-cost-forecast
ce get-savings-plans-coverage
ce get-usage-forecast
ce get-savings-plans-utilization
ce get-dimension-values
ce get-tags
ce get-cost-comparison-drivers
budgets create-budget
(in budget JSON)
支持
--billing-view-arn
不支持该参数
ce get-cost-and-usage
ce get-reservation-coverage
ce get-cost-and-usage-with-resources
ce get-reservation-utilization
ce get-cost-forecast
ce get-savings-plans-coverage
ce get-usage-forecast
ce get-savings-plans-utilization
ce get-dimension-values
ce get-tags
ce get-cost-comparison-drivers
budgets create-budget
(在budget JSON中)

Troubleshooting

故障排除

ErrorCauseFix
ValidationException
on Cost Explorer
Wrong dimension key (e.g.,
CHARGE_TYPE
instead of
RECORD_TYPE
)
Use
RECORD_TYPE
for charge type filtering
Empty results with filterFilter value doesn't match exactlyCall
GetDimensionValues
first to get valid values
AccessDeniedException
on hourly data
Hourly granularity not enabledEnable in Cost Explorer preferences
Account not registered
on Compute Optimizer
Not opted inRun
update-enrollment-status --status Active
Budgets API fails outside us-east-1Budgets requires us-east-1Set
--region us-east-1
Cost Explorer
Total
empty with GroupBy
By design — totals excluded when groupingMake separate call without GroupBy, or sum grouped results using a script
AccessDeniedException
on
list-billing-views
Missing permissionUser needs
billing:ListBillingViews
permissions
ValidationException
with
--billing-view-arn
API doesn't support billing views, or malformed ARNCheck the API support table above; ARN format is
arn:aws:billing::ACCOUNT_ID:billingview/VIEW_ID
Budget shows
UNHEALTHY
health status
Billing view access revoked or view deletedCheck
HealthStatus.StatusReason
in
describe-budget
output; ensure
billing:GetBillingViewData
is granted
错误原因修复方案
Cost Explorer出现
ValidationException
维度键错误(例如,使用
CHARGE_TYPE
而非
RECORD_TYPE
使用
RECORD_TYPE
进行费用类型筛选
使用筛选器后返回空结果筛选值不完全匹配先调用
GetDimensionValues
获取有效值
小时级数据出现
AccessDeniedException
未启用小时级粒度在Cost Explorer偏好设置中启用
Compute Optimizer出现
Account not registered
未启用服务运行
update-enrollment-status --status Active
us-east-1区域外调用Budgets API失败Budgets需要us-east-1区域设置
--region us-east-1
Cost Explorer使用GroupBy时
Total
为空
设计如此——分组时不包含总计单独调用不使用GroupBy的接口,或通过脚本对分组结果求和
list-billing-views
出现
AccessDeniedException
缺少权限用户需要
billing:ListBillingViews
权限
使用
--billing-view-arn
出现
ValidationException
API不支持账单视图,或ARN格式错误查看上方的API支持表;ARN格式为
arn:aws:billing::ACCOUNT_ID:billingview/VIEW_ID
预算显示
UNHEALTHY
健康状态
账单视图权限被撤销或视图已删除
describe-budget
输出中查看
HealthStatus.StatusReason
;确保已授予
billing:GetBillingViewData
权限

Additional Resources

额外资源