aws ce get-cost-forecast とは

aws ce get-cost-forecast はAWS Cost Explorer APIが過去の実績データを元に算出した、将来のコストの予測値を取得するコマンド。予測の処理自体はAWS側で行われ、CLIはその結果を取得しているだけである。

基本的な使い方

--time-period--metric--granularity は必須パラメータ。

$ aws ce get-cost-forecast \
  --time-period Start=2026-07-13,End=2026-08-01 \
  --metric UNBLENDED_COST \
  --granularity MONTHLY
{
    "Total": {
        "Amount": "123.45",
        "Unit": "USD"
    },
    "ForecastResultsByTime": [
        {
            "TimePeriod": {
                "Start": "2026-07-01",
                "End": "2026-08-01"
            },
            "MeanValue": "123.45"
        }
    ]
}

--time-periodStart は未来予測のため、本日以降の日付を指定する必要がある。過去日付を指定するとバリデーションエラーになる。

An error occurred (ValidationException) when calling the GetCostForecast operation: Earliest supported Start is 2026-07-12

aws ce get-cost-and-usage との違い

【AWS CLI】ce get-cost-and-usageでコストをコマンドラインで確認する と似たコマンドだが、いくつか違いがある。

  • --metrics(複数のメトリクスを指定できるlist)ではなく --metric(単一値のstring)で、1回の呼び出しで指定できるメトリクスは1つのみ
  • --granularityDAILYMONTHLY のみサポートしており、HOURLY を指定するとエラーになる
An error occurred (ValidationException) when calling the GetCostForecast operation: Forecast requests not currently supported for HOURLY

信頼区間つきで予測する

--prediction-interval-level を指定すると、予測値に加えて信頼区間の上限・下限も取得できる。

$ aws ce get-cost-forecast \
  --time-period Start=2026-07-13,End=2026-07-20 \
  --metric UNBLENDED_COST \
  --granularity DAILY \
  --prediction-interval-level 80
{
    "Total": {
        "Amount": "1.23",
        "Unit": "USD"
    },
    "ForecastResultsByTime": [
        {
            "TimePeriod": {
                "Start": "2026-07-13",
                "End": "2026-07-14"
            },
            "MeanValue": "0.15",
            "PredictionIntervalLowerBound": "0.03",
            "PredictionIntervalUpperBound": "0.27"
        },
        ...
    ]
}

過去の使用量が少ないサービスでは PredictionIntervalLowerBound が負の値になることがある。実際のコストがマイナスになるわけではなく、あくまで統計モデル上の信頼区間の下限である。

特定サービスに絞り込む

--filter を指定すると特定サービスの予測に絞り込める。

$ aws ce get-cost-forecast \
  --time-period Start=2026-07-13,End=2026-08-01 \
  --metric UNBLENDED_COST \
  --granularity MONTHLY \
  --filter '{"Dimensions": {"Key": "SERVICE", "Values": ["Amazon Simple Storage Service"]}}'

フィルタの指定方法は aws ce get-cost-and-usage と共通で、SERVICE のほかに LINKED_ACCOUNTREGION などの次元でも絞り込める。