Skip to content

get_cost_and_usage_comparisons

get_cost_and_usage_comparisons(
    baseline_time_period: DateInterval,
    comparison_time_period: DateInterval,
    metric_for_comparison: MetricName,
    *,
    config_overrides: Optional[CostExplorerClientConfig] = None,
    billing_view_arn: Optional[BillingViewArn] = None,
    filter: Optional[Expression] = None,
    group_by: Optional[GroupDefinitions] = None,
    max_results: Optional[CostAndUsageComparisonsMaxResults] = None,
    next_page_token: Optional[NextPageToken] = None,
) -> GetCostAndUsageComparisonsResponse

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.

Parameters:

  • billing_view_arn (Optional[BillingViewArn], default: None ) –

    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.

  • baseline_time_period (DateInterval) –

    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.

  • comparison_time_period (DateInterval) –

    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.

  • metric_for_comparison (MetricName) –

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

  • group_by (Optional[GroupDefinitions], default: None ) –

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

  • max_results (Optional[CostAndUsageComparisonsMaxResults], default: None ) –

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

  • next_page_token (Optional[NextPageToken], default: None ) –

    The token to retrieve the next set of paginated results.

Raises:

Source code in docs_src/capo_cost_explorer/_services/cost_explorer.py
def get_cost_and_usage_comparisons(
    self,
    baseline_time_period: "capo_cost_explorer.types.date_interval.DateInterval",
    comparison_time_period: "capo_cost_explorer.types.date_interval.DateInterval",
    metric_for_comparison: "capo_cost_explorer.types.metric_name.MetricName",
    *,
    config_overrides: Optional[CostExplorerClientConfig] = None,
    billing_view_arn: Optional[
        "capo_cost_explorer.types.billing_view_arn.BillingViewArn"
    ] = None,
    filter: Optional["capo_cost_explorer.types.expression.Expression"] = None,
    group_by: Optional[
        "capo_cost_explorer.types.group_definitions.GroupDefinitions"
    ] = None,
    max_results: Optional[
        "capo_cost_explorer.types.cost_and_usage_comparisons_max_results.CostAndUsageComparisonsMaxResults"
    ] = None,
    next_page_token: Optional[
        "capo_cost_explorer.types.next_page_token.NextPageToken"
    ] = None,
) -> "capo_cost_explorer.types.get_cost_and_usage_comparisons_response.GetCostAndUsageComparisonsResponse":
    """<p>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.</p>

    Args:
        billing_view_arn: <p>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.</p>
        baseline_time_period: <p>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.</p>
        comparison_time_period: <p>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.</p>
        metric_for_comparison: <p>The cost and usage metric to compare. Valid values are <code>AmortizedCost</code>, <code>BlendedCost</code>, <code>NetAmortizedCost</code>, <code>NetUnblendedCost</code>, <code>NormalizedUsageAmount</code>, <code>UnblendedCost</code>, and <code>UsageQuantity</code>.</p>
        group_by: <p>You can group results using the attributes <code>DIMENSION</code>, <code>TAG</code>, and <code>COST_CATEGORY</code>. </p>
        max_results: <p>The maximum number of results that are returned for the request.</p>
        next_page_token: <p>The token to retrieve the next set of paginated results.</p>

    Raises:
        capo_cost_explorer.errors.billing_view_health_status_exception.BillingViewHealthStatusException: <p> The billing view status must be <code>HEALTHY</code> to perform this action. Try again when the status is <code>HEALTHY</code>. </p>
        capo_cost_explorer.errors.data_unavailable_exception.DataUnavailableException: <p>The requested data is unavailable.</p>
        capo_cost_explorer.errors.invalid_next_token_exception.InvalidNextTokenException: <p>The pagination token is invalid. Try again without a pagination token.</p>
        capo_cost_explorer.errors.limit_exceeded_exception.LimitExceededException: <p>You made too many calls in a short period of time. Try again later.</p>
        capo_cost_explorer.errors.resource_not_found_exception.ResourceNotFoundException: <p> The specified ARN in the request doesn't exist. </p>
        capo_cost_explorer.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_cost_explorer.types.get_cost_and_usage_comparisons_request.GetCostAndUsageComparisonsRequest]",
    ) -> OperationResponse[
        "capo_cost_explorer.types.get_cost_and_usage_comparisons_response.GetCostAndUsageComparisonsResponse"
    ]:
        import capo_cost_explorer._operations.aws_insights_index_service.get_cost_and_usage_comparisons

        output, http_response = (
            capo_cost_explorer._operations.aws_insights_index_service.get_cost_and_usage_comparisons.get_cost_and_usage_comparisons(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("GetCostAndUsageComparisons")
    )
    input_: capo_cost_explorer.types.get_cost_and_usage_comparisons_request.GetCostAndUsageComparisonsRequest = {
        "baseline_time_period": baseline_time_period,
        "comparison_time_period": comparison_time_period,
        "metric_for_comparison": metric_for_comparison,
    }
    if billing_view_arn is not None:
        input_["billing_view_arn"] = billing_view_arn
    if filter is not None:
        input_["filter"] = filter
    if group_by is not None:
        input_["group_by"] = group_by
    if max_results is not None:
        input_["max_results"] = max_results
    if next_page_token is not None:
        input_["next_page_token"] = next_page_token

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output