- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
GetCostCategoriesCommand
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.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { CostExplorerClient, GetCostCategoriesCommand } from "@aws-sdk/client-cost-explorer"; // ES Modules import
// const { CostExplorerClient, GetCostCategoriesCommand } = require("@aws-sdk/client-cost-explorer"); // CommonJS import
const client = new CostExplorerClient(config);
const input = { // GetCostCategoriesRequest
SearchString: "STRING_VALUE",
TimePeriod: { // DateInterval
Start: "STRING_VALUE", // required
End: "STRING_VALUE", // required
},
CostCategoryName: "STRING_VALUE",
Filter: { // Expression
Or: [ // Expressions
{
Or: [
"<Expression>",
],
And: [
"<Expression>",
],
Not: "<Expression>",
Dimensions: { // DimensionValues
Key: "AZ" || "INSTANCE_TYPE" || "LINKED_ACCOUNT" || "LINKED_ACCOUNT_NAME" || "OPERATION" || "PURCHASE_TYPE" || "REGION" || "SERVICE" || "SERVICE_CODE" || "USAGE_TYPE" || "USAGE_TYPE_GROUP" || "RECORD_TYPE" || "OPERATING_SYSTEM" || "TENANCY" || "SCOPE" || "PLATFORM" || "SUBSCRIPTION_ID" || "LEGAL_ENTITY_NAME" || "DEPLOYMENT_OPTION" || "DATABASE_ENGINE" || "CACHE_ENGINE" || "INSTANCE_TYPE_FAMILY" || "BILLING_ENTITY" || "RESERVATION_ID" || "RESOURCE_ID" || "RIGHTSIZING_TYPE" || "SAVINGS_PLANS_TYPE" || "SAVINGS_PLAN_ARN" || "PAYMENT_OPTION" || "AGREEMENT_END_DATE_TIME_AFTER" || "AGREEMENT_END_DATE_TIME_BEFORE" || "INVOICING_ENTITY" || "ANOMALY_TOTAL_IMPACT_ABSOLUTE" || "ANOMALY_TOTAL_IMPACT_PERCENTAGE",
Values: [ // Values
"STRING_VALUE",
],
MatchOptions: [ // MatchOptions
"EQUALS" || "ABSENT" || "STARTS_WITH" || "ENDS_WITH" || "CONTAINS" || "CASE_SENSITIVE" || "CASE_INSENSITIVE" || "GREATER_THAN_OR_EQUAL",
],
},
Tags: { // TagValues
Key: "STRING_VALUE",
Values: [
"STRING_VALUE",
],
MatchOptions: [
"EQUALS" || "ABSENT" || "STARTS_WITH" || "ENDS_WITH" || "CONTAINS" || "CASE_SENSITIVE" || "CASE_INSENSITIVE" || "GREATER_THAN_OR_EQUAL",
],
},
CostCategories: { // CostCategoryValues
Key: "STRING_VALUE",
Values: [
"STRING_VALUE",
],
MatchOptions: [
"EQUALS" || "ABSENT" || "STARTS_WITH" || "ENDS_WITH" || "CONTAINS" || "CASE_SENSITIVE" || "CASE_INSENSITIVE" || "GREATER_THAN_OR_EQUAL",
],
},
},
],
And: [
"<Expression>",
],
Not: "<Expression>",
Dimensions: {
Key: "AZ" || "INSTANCE_TYPE" || "LINKED_ACCOUNT" || "LINKED_ACCOUNT_NAME" || "OPERATION" || "PURCHASE_TYPE" || "REGION" || "SERVICE" || "SERVICE_CODE" || "USAGE_TYPE" || "USAGE_TYPE_GROUP" || "RECORD_TYPE" || "OPERATING_SYSTEM" || "TENANCY" || "SCOPE" || "PLATFORM" || "SUBSCRIPTION_ID" || "LEGAL_ENTITY_NAME" || "DEPLOYMENT_OPTION" || "DATABASE_ENGINE" || "CACHE_ENGINE" || "INSTANCE_TYPE_FAMILY" || "BILLING_ENTITY" || "RESERVATION_ID" || "RESOURCE_ID" || "RIGHTSIZING_TYPE" || "SAVINGS_PLANS_TYPE" || "SAVINGS_PLAN_ARN" || "PAYMENT_OPTION" || "AGREEMENT_END_DATE_TIME_AFTER" || "AGREEMENT_END_DATE_TIME_BEFORE" || "INVOICING_ENTITY" || "ANOMALY_TOTAL_IMPACT_ABSOLUTE" || "ANOMALY_TOTAL_IMPACT_PERCENTAGE",
Values: [
"STRING_VALUE",
],
MatchOptions: [
"EQUALS" || "ABSENT" || "STARTS_WITH" || "ENDS_WITH" || "CONTAINS" || "CASE_SENSITIVE" || "CASE_INSENSITIVE" || "GREATER_THAN_OR_EQUAL",
],
},
Tags: {
Key: "STRING_VALUE",
Values: [
"STRING_VALUE",
],
MatchOptions: [
"EQUALS" || "ABSENT" || "STARTS_WITH" || "ENDS_WITH" || "CONTAINS" || "CASE_SENSITIVE" || "CASE_INSENSITIVE" || "GREATER_THAN_OR_EQUAL",
],
},
CostCategories: {
Key: "STRING_VALUE",
Values: "<Values>",
MatchOptions: "<MatchOptions>",
},
},
SortBy: [ // SortDefinitions
{ // SortDefinition
Key: "STRING_VALUE", // required
SortOrder: "ASCENDING" || "DESCENDING",
},
],
BillingViewArn: "STRING_VALUE",
MaxResults: Number("int"),
NextPageToken: "STRING_VALUE",
};
const command = new GetCostCategoriesCommand(input);
const response = await client.send(command);
// { // GetCostCategoriesResponse
// NextPageToken: "STRING_VALUE",
// CostCategoryNames: [ // CostCategoryNamesList
// "STRING_VALUE",
// ],
// CostCategoryValues: [ // CostCategoryValuesList
// "STRING_VALUE",
// ],
// ReturnSize: Number("int"), // required
// TotalSize: Number("int"), // required
// };
GetCostCategoriesCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
TimePeriod Required | DateInterval | undefined | The time period of the request. |
BillingViewArn | string | undefined | 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. |
CostCategoryName | string | undefined | The unique name of the Cost Category. |
Filter | Expression | undefined | Use Not all There are two patterns:
For the For the |
MaxResults | number | undefined | This field is only used when the The maximum number of objects that are returned for this request. If For |
NextPageToken | string | undefined | 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. |
SearchString | string | undefined | The value that you want to search the filter values for. If you don't specify a |
SortBy | SortDefinition[] | undefined | The value that you sort the data by. The key represents the cost and usage metrics. The following values are supported:
The supported key values for the When you use the |
GetCostCategoriesCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
ReturnSize Required | number | undefined | The number of objects that are returned. |
TotalSize Required | number | undefined | The total number of objects. |
CostCategoryNames | string[] | undefined | The names of the Cost Categories. |
CostCategoryValues | string[] | undefined | The Cost Category values. If the |
NextPageToken | string | undefined | 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 marker from the prior call in your next request. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
BillExpirationException | client | The requested report expired. Update the date interval and try again. |
DataUnavailableException | client | The requested data is unavailable. |
InvalidNextTokenException | client | The pagination token is invalid. Try again without a pagination token. |
LimitExceededException | client | You made too many calls in a short period of time. Try again later. |
RequestChangedException | client | Your request parameters changed between pages. Try again with the old parameters or without a pagination token. |
ResourceNotFoundException | client | The specified ARN in the request doesn't exist. |
CostExplorerServiceException | Base exception class for all service exceptions from CostExplorer service. |