Skip to content

get_cost_categories

get_cost_categories(
    time_period: DateInterval,
    *,
    config_overrides: Optional[CostExplorerClientConfig] = None,
    search_string: Optional[SearchString] = None,
    cost_category_name: Optional[CostCategoryName] = None,
    filter: Optional[Expression] = None,
    sort_by: Optional[SortDefinitions] = None,
    billing_view_arn: Optional[BillingViewArn] = None,
    max_results: Optional[MaxResults] = None,
    next_page_token: Optional[NextPageToken] = None,
) -> GetCostCategoriesResponse

Retrieves an array of cost category names and values incurred cost.

If some cost category names and values are not associated with any cost, they will not be returned by this API.

Parameters:

  • search_string (Optional[SearchString], default: None ) –

    The value that you want to search the filter values for.

    If you don't specify a CostCategoryName, SearchString is used to filter cost category names that match the SearchString pattern. If you specify a CostCategoryName, SearchString is used to filter cost category values that match the SearchString pattern.

  • sort_by (Optional[SortDefinitions], default: None ) –

    The value that you sort the data by.

    The key represents the cost and usage metrics. The following values are supported:

    • BlendedCost

    • UnblendedCost

    • AmortizedCost

    • NetAmortizedCost

    • NetUnblendedCost

    • UsageQuantity

    • NormalizedUsageAmount

    The supported key values for the SortOrder value are ASCENDING and DESCENDING.

    When you use the SortBy value, the NextPageToken and SearchString key values aren't supported.

  • 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.

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

    This field is only used when the SortBy value is provided in the request.

    The maximum number of objects that are returned for this request. If MaxResults isn't specified with the SortBy value, the request returns 1000 results as the default value for this parameter.

    For GetCostCategories, MaxResults has an upper quota of 1000.

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

    If the number of objects that are still available for retrieval exceeds the quota, Amazon Web Services returns a NextPageToken value in the response. To retrieve the next batch of objects, provide the NextPageToken from the previous call in your next request.

Raises:

Source code in docs_src/capo_cost_explorer/_services/cost_explorer.py
def get_cost_categories(
    self,
    time_period: "capo_cost_explorer.types.date_interval.DateInterval",
    *,
    config_overrides: Optional[CostExplorerClientConfig] = None,
    search_string: Optional[
        "capo_cost_explorer.types.search_string.SearchString"
    ] = None,
    cost_category_name: Optional[
        "capo_cost_explorer.types.cost_category_name.CostCategoryName"
    ] = None,
    filter: Optional["capo_cost_explorer.types.expression.Expression"] = None,
    sort_by: Optional[
        "capo_cost_explorer.types.sort_definitions.SortDefinitions"
    ] = None,
    billing_view_arn: Optional[
        "capo_cost_explorer.types.billing_view_arn.BillingViewArn"
    ] = None,
    max_results: Optional["capo_cost_explorer.types.max_results.MaxResults"] = None,
    next_page_token: Optional[
        "capo_cost_explorer.types.next_page_token.NextPageToken"
    ] = None,
) -> "capo_cost_explorer.types.get_cost_categories_response.GetCostCategoriesResponse":
    """<p>Retrieves an array of cost category names and values incurred cost.</p> <note> <p>If some cost category names and values are not associated with any cost, they will not be returned by this API.</p> </note>

    Args:
        search_string: <p>The value that you want to search the filter values for.</p> <p>If you don't specify a <code>CostCategoryName</code>, <code>SearchString</code> is used to filter cost category names that match the <code>SearchString</code> pattern. If you specify a <code>CostCategoryName</code>, <code>SearchString</code> is used to filter cost category values that match the <code>SearchString</code> pattern.</p>
        sort_by: <p>The value that you sort the data by.</p> <p>The key represents the cost and usage metrics. The following values are supported:</p> <ul> <li> <p> <code>BlendedCost</code> </p> </li> <li> <p> <code>UnblendedCost</code> </p> </li> <li> <p> <code>AmortizedCost</code> </p> </li> <li> <p> <code>NetAmortizedCost</code> </p> </li> <li> <p> <code>NetUnblendedCost</code> </p> </li> <li> <p> <code>UsageQuantity</code> </p> </li> <li> <p> <code>NormalizedUsageAmount</code> </p> </li> </ul> <p>The supported key values for the <code>SortOrder</code> value are <code>ASCENDING</code> and <code>DESCENDING</code>.</p> <p>When you use the <code>SortBy</code> value, the <code>NextPageToken</code> and <code>SearchString</code> key values aren't supported.</p>
        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>
        max_results: <p>This field is only used when the <code>SortBy</code> value is provided in the request.</p> <p>The maximum number of objects that are returned for this request. If <code>MaxResults</code> isn't specified with the <code>SortBy</code> value, the request returns 1000 results as the default value for this parameter.</p> <p>For <code>GetCostCategories</code>, MaxResults has an upper quota of 1000.</p>
        next_page_token: <p>If the number of objects that are still available for retrieval exceeds the quota, Amazon Web Services returns a NextPageToken value in the response. To retrieve the next batch of objects, provide the NextPageToken from the previous call in your next request.</p>

    Raises:
        capo_cost_explorer.errors.bill_expiration_exception.BillExpirationException: <p>The requested report expired. Update the date interval and try again.</p>
        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.request_changed_exception.RequestChangedException: <p>Your request parameters changed between pages. Try again with the old parameters or without a pagination token.</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_categories_request.GetCostCategoriesRequest]",
    ) -> OperationResponse[
        "capo_cost_explorer.types.get_cost_categories_response.GetCostCategoriesResponse"
    ]:
        import capo_cost_explorer._operations.aws_insights_index_service.get_cost_categories

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("GetCostCategories")
    )
    input_: capo_cost_explorer.types.get_cost_categories_request.GetCostCategoriesRequest = {
        "time_period": time_period
    }
    if search_string is not None:
        input_["search_string"] = search_string
    if cost_category_name is not None:
        input_["cost_category_name"] = cost_category_name
    if filter is not None:
        input_["filter"] = filter
    if sort_by is not None:
        input_["sort_by"] = sort_by
    if billing_view_arn is not None:
        input_["billing_view_arn"] = billing_view_arn
    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