aws-billing-and-cost-management
aws/agent-toolkit-for-aws
分析 AWS 成本、寻找节省机会、管理预算、评估节省计划和 预留实例、使用 Compute Optimizer 对 EC2/Lambda/RDS/EBS 进行容量优化、 查询服务定价、使用 Athena 查询 CUR、检测成本异常、 将成本范围限定在计费视图内,以及监控免费套餐的使用情况。 触发条件: AWS 账单、成本分析、降低支出、节省计划、预留实例、 合理配置、预算警报、成本优化、定价、免费额度、成本 异常、CUR、成本审计、计费视图、计费视图 ARN。
...展开全部关于aws-billing-and-cost-management
该工具可分析、优化和管理 AWS 成本,整合了 AWS 成本管理产品中的领域专业知识,包括常见陷阱、正确的 API 使用模式以及优化工作流。它可用于分析支出和成本趋势、设置预算警报、评估节省计划和预留实例、调整 EC2 规格、 Lambda、RDS 和 EBS 资源,通过 Compute Optimizer 查询服务定价、执行成本审计或排查成本突增情况、使用 Athena 查询 CUR 数据、将分析范围限定在特定计费视图内,以及检查免费套餐的使用情况。 核心概念涵盖 Cost Explorer、预算、计费视图、Compute Optimizer、成本优化中心、节省计划和预留实例,以及通过 Athena 查询的 CUR 2.0。 AWS MCP 服务器是进行沙箱执行和审计日志记录的推荐配置,但这些命令也适用于任何具有标准 AWS CLI 访问权限的代理。
需特别强调两条关键规则:在调用 Cost Explorer、预算或节省计划之前,必须先使用工具确定当前日期,因为模型通常会默认使用训练数据的年份,从而导致分析过时数据。 诸如求和、求平均值、计算百分比、比较和计数等数值计算,绝不能依赖响应中的推断结果,而必须始终使用脚本或计算器工具进行计算,因为大型语言模型(LLM)对成本数据的算术运算并不可靠。
决策指南会将每个问题引导至正确的工具和参考文件,而“常见任务”部分则提供了具体的命令。 通过 aws ce get-cost-and-usage 按 SERVICE 分组分析各项服务的成本,默认使用 UnblendedCost,通过 RECORD_TYPE 过滤器排除积分和退款,并将结束日期视为不包含在内。 Compute Optimizer 需要通过 `update-enrollment-status` 并设置状态为 `Active` 来主动启用。“计费视图”部分解释了如何通过在受支持的调用中添加 --billing-view-arn 参数来将成本数据范围限定为特定计费切片,列出了通过 `aws billing list-billing-views` 获取的计费视图,并展示了如何在预算 JSON 中包含 `BillingViewArn`,同时附有一张表格,说明哪些 Cost Explorer API 支持或不支持计费视图 ARN。 故障排除表将诸如因维度键错误导致的 ValidationException、过滤结果为空、按小时数据的 AccessDenied 错误,以及预算必须在 us-east-1 区域运行的要求等错误与其对应的解决方法进行了映射。
常见问题
为什么在调用成本 API 之前必须检查当前日期?
大型语言模型(LLM)通常会默认使用其训练数据中的日期,而非实际的当前日期,从而产生基于过时数据的分析结果——这些结果看似正确,实则有误。在调用任何 Cost Explorer、Budgets 或 Savings Plans 接口之前,必须使用工具确定当前日期。
如何对成本数据进行数值计算?
切勿基于响应内容进行推算。求和、求平均值、百分比计算、比较、计数以及求最小值或最大值等操作,必须始终通过脚本或计算器工具(例如可输出结果的 Python 脚本)进行计算,因为 LLM 对成本数据的运算结果不可靠。
如何将成本分析范围限定在特定的计费视图上?
在受支持的 API 调用中添加 --billing-view-arn 参数,并使用 aws billing list-billing-views 查询可用视图(需要 billing:ListBillingViews 权限)。 支持的调用包括 ce get-cost-and-usage 和 get-cost-forecast,而预留实例和节省计划的覆盖范围及利用率调用则不支持此参数。
Compute Optimizer 需要哪些配置?
首先需要通过运行 `aws compute-optimizer update-enrollment-status` 并将其状态设为 `Active` 来主动注册。若未注册,调用将因“账户未注册”错误而失败。
为什么在 us-east-1 区域外调用 Budgets API 可能会失败?
预算 API 要求使用 us-east-1 区域。故障排除指南建议将预算 API 调用的区域设置为 us-east-1。
所有文件
16个文件references/cost-explorer.md 7.3KB 查看references/cost-audit.md 3.2KB 查看references/cur-athena.md 7.0KB 查看references/deterministic-calculations.md2.5KB 查看 references/ebs-optimization.md 2.7KB 查看 references/ec2-rightsizing.md 3.2KB 查看 references/pricing-lookup.md 3.8KB 查看 references/rds-optimization.md 1.8KB 查看 references/service-optimization.md2.9KB 查看 SKILL.md 8.8KB 查看 references/budgets.md 2.3KB 查看 references/cost-optimization-hub.md 7.1KB 查看 references/free-tier.md1.6KB 查看参考资料/预留实例.md2.3KB 查看参考资料/Lambda 优化.md2.1KB 查看参考资料/节省方案.md3.3 KB 查看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.
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
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.
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.
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.
Decision Guide
| Question | Tool | Reference |
|---|---|---|
| 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 Views | See Billing Views below |
Common Tasks
Analyze costs by service
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.
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.
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.
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.
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.
Discover available billing views
aws billing list-billing-views \ --billing-view-types PRIMARY CUSTOM BILLING_GROUP
Requires billing:ListBillingViews permission.
Use a billing view with Cost Explorer
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:
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
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) |
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
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 filter | Filter value doesn't match exactly | Call GetDimensionValues first to get valid values |
AccessDeniedException on hourly data | Hourly granularity not enabled | Enable in Cost Explorer preferences |
Account not registered on Compute Optimizer | Not opted in | Run update-enrollment-status --status Active |
| Budgets API fails outside us-east-1 | Budgets requires us-east-1 | Set --region us-east-1 |
Cost Explorer Total empty with GroupBy | By design — totals excluded when grouping | Make separate call without GroupBy, or sum grouped results using a script |
AccessDeniedException on list-billing-views | Missing permission | User needs billing:ListBillingViews permissions |
ValidationException with --billing-view-arn | API doesn't support billing views, or malformed ARN | Check 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 deleted | Check HealthStatus.StatusReason in describe-budget output; ensure billing:GetBillingViewData is granted |
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/
所有文件
0 个文件安装 aws-billing-and-cost-management
下载技能文件并将其解压到 .claude/skills/ 目录中。
下载ZIP克隆仓库并复制技能文件到您的项目中。
git clone https://github.com/aws/agent-toolkit-for-aws/blob/main/skills/core-skills/aws-billing-and-cost-management/SKILL.md # Copy SKILL.md to your .claude/skills/ directory
复制





首页
