選項
首頁首頁 Skill 雲端基礎設施 aws-billing-and-cost-management

aws-billing-and-cost-management

aws/agent-toolkit-for-aws aws/agent-toolkit-for-aws

分析 AWS 成本、尋找節省機會、管理預算、評估「節省方案」和 「預留實例」、透過「運算最佳化工具」為 EC2/Lambda/RDS/EBS 進行容量調整、 查詢服務定價、使用 Athena 查詢 CUR、偵測成本異常、 將成本範圍限定於特定計費檢視,並監控免費方案的使用狀況。 觸發條件: AWS 帳單、成本分析、降低支出、節省方案、預留實例、 適度調整資源規模、預算警示、成本優化、定價、免費使用額、成本 異常、CUR、成本稽核、帳單檢視、帳單檢視 ARN。

...展開全部
16
更新時間 2026-08-25

關於aws-billing-and-cost-management

分析、優化及管理 AWS 成本,整合來自 AWS 成本管理產品的領域專業知識,包括常見陷阱、正確的 API 使用模式以及優化工作流程。此工具可用於分析支出與成本趨勢、設定預算警示、評估節省方案與預留實例、調整 EC2 資源規模、 Lambda、RDS 及 EBS 資源,查詢服務定價、執行成本稽核或調查成本激增狀況、透過 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` 篩選器排除 `Credits` 和 `Refunds`,並將結束日期視為不包含在內。 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 呼叫可能會失敗?

Budgets API 要求使用 us-east-1 區域。故障排除指引建議將 Budgets 呼叫的區域設定為 us-east-1。

所有檔案

16 個檔案 references/cost-explorer.md 7.3 KB 檢視references/cost-audit.md 3.2 KB視 references/cur-athena.md 7.0KB 檢視 references/deterministic-calculations.md2.5KB 檢視 參考資料/ebs-optimization.md 2.7KB 檢視 參考資料/ec2-rightsizing.md 3.2KB 檢視 參考資料/pricing-lookup.md 3.8KB 檢視 參考資料/rds-optimization.md 1.8KB 檢視 參考資料/service-optimization.md2.9KB 檢視 SKILL.md 8.8KB 檢視參考資料/budgets.md 2.3KB 檢視參考資料/cost-optimization-hub.md 7.1KB 檢視參考資料/free-tier.md1.6KB 檢視 參考資料/預留實例.md2.3KB 檢視 參考資料/Lambda 優化.md2.1KB 檢視 參考資料/節省方案.md3.3 KB 檢視
在 GitHub 上查看

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

QuestionToolReference
What am I spending? Where are costs going up?Cost Explorerreferences/cost-explorer.md
How much does a service cost?Price List APIreferences/pricing-lookup.md
Where can I save money? (start here)Cost Optimization Hubreferences/cost-optimization-hub.md
Should I buy Savings Plans?CE SP Recommendationsreferences/savings-plans.md
Should I buy Reserved Instances?CE RI Recommendationsreferences/reserved-instances.md
Deep-dive on a specific EC2/Lambda/EBS/RDS rec?Compute Optimizerreferences/ec2-rightsizing.md, references/lambda-optimization.md, references/rds-optimization.md, references/ebs-optimization.md
How do I set up budget alerts?Budgetsreferences/budgets.md
What's causing a cost spike?Cost Anomaly Detectionreferences/cost-explorer.md
Am I within Free Tier?Free Tier APIreferences/free-tier.md
How do I reduce my bill?Cost Audit workflowreferences/cost-audit.md
How do I query detailed billing data?CUR 2.0 + Athenareferences/cur-athena.md
How do I optimize specific services?Per-service patternsreferences/service-optimization.md
How do I scope costs to a billing view?Billing ViewsSee 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-arnDoes NOT support it
ce get-cost-and-usagece get-reservation-coverage
ce get-cost-and-usage-with-resourcesce get-reservation-utilization
ce get-cost-forecastce get-savings-plans-coverage
ce get-usage-forecastce get-savings-plans-utilization
ce get-dimension-values
ce get-tags
ce get-cost-comparison-drivers
budgets create-budget (in budget JSON)

Troubleshooting

ErrorCauseFix
ValidationException on Cost ExplorerWrong 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 dataHourly granularity not enabledEnable in Cost Explorer preferences
Account not registered on Compute OptimizerNot 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 GroupByBy design — totals excluded when groupingMake separate call without GroupBy, or sum grouped results using a script
AccessDeniedException on list-billing-viewsMissing permissionUser needs billing:ListBillingViews permissions
ValidationException with --billing-view-arnAPI 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 statusBilling view access revoked or view deletedCheck 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

複製 複製
快速設定: 將技能資料夾複製到 .claude/skills/,Claude 會自動偵測並使用該技能

相關技能

Cloudflare Manager
更新時間 2026-06-29
pinecone
更新時間 2026-06-29
azure-setup-guide
更新時間 2026-06-29
sentry-architecture-variants
更新時間 2026-06-29
OR