You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Amortized Cost结果差异:Athena CUR查询与AWS Cost Explorer对比

问题:Athena查询CUR分摊成本与Cost Explorer当月数据不一致

背景

过去六个月我一直使用AWS Athena结合Cost and Usage Reports (CUR)查询分摊成本(amortized cost),与启用了分摊成本过滤器的AWS Cost Explorer对比时,过去五个月的数据完全匹配,但当月数据存在差异。

成本对比差异图

我参考相关文档后,使用的Athena查询语句如下:

SELECT
    YEAR(line_item_usage_start_date) AS year,
    MONTH(line_item_usage_start_date) AS month,
    DAY(line_item_usage_start_date) AS day,
    ROUND(SUM(
        CASE
            WHEN (line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN COALESCE(savings_plan_savings_plan_effective_cost, 0)
            WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN COALESCE(savings_plan_total_commitment_to_date - savings_plan_used_commitment, 0)
            WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0
            WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN 0
            WHEN (line_item_line_item_type = 'DiscountedUsage') THEN COALESCE(reservation_effective_cost, 0)
            WHEN (line_item_line_item_type = 'RIFee') THEN COALESCE(reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee, 0) 
            WHEN (line_item_line_item_type = 'Fee') THEN 0
            ELSE COALESCE(line_item_unblended_cost, 0)
        END
    ), 2) AS amortized_cost
FROM "my_cur_report"
WHERE 
    line_item_line_item_type NOT IN ('Credit') AND
    DATE(line_item_usage_start_date) >= DATE('2023-10-01')
    AND DATE(line_item_usage_start_date) <= DATE('2023-10-01')
    AND line_item_usage_account_id = 'my_acc_id'
GROUP BY 1, 2, 3
ORDER BY 1,2, 3;

疑问

请问这是因为当月的分摊(amortization)尚未生效吗?如果是,我该如何获取正确的分摊成本结果?


问题分析与解决思路

核心原因:CUR数据延迟与计算逻辑差异

  1. CUR数据更新延迟:CUR默认按天增量更新,但当月的RI/Savings Plan分摊费用(尤其是未使用部分的摊销)、账单调整项可能尚未完全同步到CUR中。Cost Explorer会实时计算分摊成本,而CUR需要等待账单周期内所有交易、调整项完成后才会生成完整的分摊记录。
  2. 当月分摊计算的时间窗口差异:Cost Explorer在当月会动态更新分摊成本(比如RI未使用部分的每日摊销),而你的Athena查询基于line_item_usage_start_date的当日记录,可能未包含当月后续生成的回溯调整记录(比如月末补录的RI摊销)。

解决办法

1. 等待CUR月度报告完整生成

AWS CUR通常会在账单周期结束后的3-5天内生成完整月度报告,包含所有分摊调整项。若当月未结束,建议在月末后等待几天再查询,此时CUR数据会与Cost Explorer对齐。

2. 优化查询逻辑,覆盖完整分摊维度

当前查询对部分分摊场景处理不全面,建议调整CASE逻辑:

  • 对于SavingsPlanUpfrontFee,需按摊销周期分摊到当月,使用savings_plan_amortized_upfront_fee_for_billing_period字段获取当月应摊销的预付费用,而非直接设为0。
  • 对于Fee类型中的RI预付摊销部分,需包含reservation_amortized_upfront_fee_for_billing_period字段,而非直接排除。
  • 补充处理Refund、Adjustment等可能影响分摊成本的记录类型(按需选择是否包含)。

优化后的查询示例:

SELECT
    YEAR(line_item_usage_start_date) AS year,
    MONTH(line_item_usage_start_date) AS month,
    DAY(line_item_usage_start_date) AS day,
    ROUND(SUM(
        CASE
            -- Savings Plan相关
            WHEN line_item_line_item_type = 'SavingsPlanCoveredUsage' THEN COALESCE(savings_plan_savings_plan_effective_cost, 0)
            WHEN line_item_line_item_type = 'SavingsPlanRecurringFee' THEN COALESCE(savings_plan_total_commitment_to_date - savings_plan_used_commitment, 0)
            WHEN line_item_line_item_type = 'SavingsPlanUpfrontFee' THEN COALESCE(savings_plan_amortized_upfront_fee_for_billing_period, 0)
            WHEN line_item_line_item_type = 'SavingsPlanNegation' THEN 0
            -- RI相关
            WHEN line_item_line_item_type = 'DiscountedUsage' THEN COALESCE(reservation_effective_cost, 0)
            WHEN line_item_line_item_type = 'RIFee' THEN COALESCE(reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee, 0)
            WHEN line_item_line_item_type = 'Fee' THEN COALESCE(reservation_amortized_upfront_fee_for_billing_period, 0)
            -- 常规费用与调整项
            WHEN line_item_line_item_type IN ('Credit', 'Refund') THEN -COALESCE(line_item_unblended_cost, 0)
            ELSE COALESCE(line_item_unblended_cost, 0)
        END
    ), 2) AS amortized_cost
FROM "my_cur_report"
WHERE 
    DATE(line_item_usage_start_date) BETWEEN DATE('2023-10-01') AND DATE('2023-10-31')
    AND line_item_usage_account_id = 'my_acc_id'
GROUP BY 1, 2, 3
ORDER BY 1, 2, 3;

3. 验证CUR报告更新状态

在AWS Cost Management控制台查看CUR报告的生成状态,确认当月报告是否已完成所有增量更新,若仍在生成中则等待更新完成后再查询。

4. 结合Cost Explorer API辅助验证

若需实时获取当月分摊成本,可结合Cost Explorer API(GetCostAndUsage)与Athena查询结果对比,确认差异来源是数据延迟还是查询逻辑问题。

内容的提问来源于stack exchange,提问作者VasanthThoraliKumaran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 19:20:22