Search code examples
amazon-web-servicesaws-sdkaws-billing

AWS - How to obtain Billing Monthly Forecast programmatically


I'm just wondering if it is currently possible to obtain the billing monthly forecast amount using either an SDK or the API.

Looking at the AWS docs it doesn't seem possible. Although I haven't delved into the Cost Explorer API too much, I was wondering if anyone else has been able to obtain this data point?


Solution

  • There is a GetCostAndUsage method in AWS Billing and Cost Management API which returns the cost and usage metrics. This method also accepts the TimePeriod which return the results as per given time frame. Although I didn't test it but you can try to pass future dates in it maybe it will return forecast results. Give it a try

    {
      "TimePeriod": {
        "Start":"2018-06-01",
        "End": "2018-06-30"
      },
      "Granularity": "MONTHLY",
      "Filter": {      
        "Dimensions": {
          "Key": "SERVICE",
          "Values": [
            "Amazon Simple Storage Service"
          ]
        }
      },
      "GroupBy":[
        {
          "Type":"DIMENSION",
          "Key":"SERVICE"
        },
        {
          "Type":"TAG",
          "Key":"Environment"
        }
      ],
       "Metrics":["BlendedCost", "UnblendedCost", "UsageQuantity"]
    }