getCostAndUsageComparisons method

Future<GetCostAndUsageComparisonsResponse> getCostAndUsageComparisons({
  1. required DateInterval baselineTimePeriod,
  2. required DateInterval comparisonTimePeriod,
  3. required String metricForComparison,
  4. String? billingViewArn,
  5. Expression? filter,
  6. List<GroupDefinition>? groupBy,
  7. int? maxResults,
  8. String? nextPageToken,
})

Retrieves cost and usage comparisons for your account between two periods within the last 13 months. If you have enabled multi-year data at monthly granularity, you can go back up to 38 months.

May throw BillingViewHealthStatusException. May throw DataUnavailableException. May throw InvalidNextTokenException. May throw LimitExceededException. May throw ResourceNotFoundException.

Parameter baselineTimePeriod : The reference time period for comparison. This time period serves as the baseline against which other cost and usage data will be compared. The interval must start and end on the first day of a month, with a duration of exactly one month.

Parameter comparisonTimePeriod : The comparison time period for analysis. This time period's cost and usage data will be compared against the baseline time period. The interval must start and end on the first day of a month, with a duration of exactly one month.

Parameter metricForComparison : The cost and usage metric to compare. Valid values are AmortizedCost, BlendedCost, NetAmortizedCost, NetUnblendedCost, NormalizedUsageAmount, UnblendedCost, and UsageQuantity.

Parameter billingViewArn : The Amazon Resource Name (ARN) that uniquely identifies a specific billing view. The ARN is used to specify which particular billing view you want to interact with or retrieve information from when making API calls related to Amazon Web Services Billing and Cost Management features. The BillingViewArn can be retrieved by calling the ListBillingViews API.

Parameter groupBy : You can group results using the attributes DIMENSION, TAG, and COST_CATEGORY.

Parameter maxResults : The maximum number of results that are returned for the request.

Parameter nextPageToken : The token to retrieve the next set of paginated results.

Implementation

Future<GetCostAndUsageComparisonsResponse> getCostAndUsageComparisons({
  required DateInterval baselineTimePeriod,
  required DateInterval comparisonTimePeriod,
  required String metricForComparison,
  String? billingViewArn,
  Expression? filter,
  List<GroupDefinition>? groupBy,
  int? maxResults,
  String? nextPageToken,
}) async {
  _s.validateNumRange(
    'maxResults',
    maxResults,
    1,
    2000,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSInsightsIndexService.GetCostAndUsageComparisons'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'BaselineTimePeriod': baselineTimePeriod,
      'ComparisonTimePeriod': comparisonTimePeriod,
      'MetricForComparison': metricForComparison,
      if (billingViewArn != null) 'BillingViewArn': billingViewArn,
      if (filter != null) 'Filter': filter,
      if (groupBy != null) 'GroupBy': groupBy,
      if (maxResults != null) 'MaxResults': maxResults,
      if (nextPageToken != null) 'NextPageToken': nextPageToken,
    },
  );

  return GetCostAndUsageComparisonsResponse.fromJson(jsonResponse.body);
}