get_cost_and_usage
async
¶
get_cost_and_usage(
time_period: DateInterval,
granularity: Granularity,
metrics: MetricNames,
*,
config_overrides: Optional[AsyncCostExplorerClientConfig] = None,
filter: Optional[Expression] = None,
group_by: Optional[GroupDefinitions] = None,
billing_view_arn: Optional[BillingViewArn] = None,
next_page_token: Optional[NextPageToken] = None,
) -> GetCostAndUsageResponse
Retrieves cost and usage metrics for your account. You can specify which cost and usage-related metric that you want the request to return. For example, you can specify BlendedCosts or UsageQuantity. You can also filter and group your data by various dimensions, such as SERVICE or AZ, in a specific time range. For a complete list of valid dimensions, see the GetDimensionValues operation. Management account in an organization in Organizations have access to all member accounts.
For information about filter limitations, see Quotas and restrictions in the Billing and Cost Management User Guide.
Parameters:
-
time_period(DateInterval) –Sets the start date and end date for retrieving Amazon Web Services costs. The start date is inclusive, but the end date is exclusive. For example, if
startis2017-01-01andendis2017-05-01, then the cost and usage data is retrieved from2017-01-01up to and including2017-04-30but not including2017-05-01. -
granularity(Granularity) –Sets the Amazon Web Services cost granularity to
MONTHLYorDAILY, orHOURLY. IfGranularityisn't set, the response object doesn't include theGranularity, eitherMONTHLYorDAILY, orHOURLY. -
filter(Optional[Expression], default:None) –Filters Amazon Web Services costs by different dimensions. For example, you can specify
SERVICEandLINKED_ACCOUNTand get the costs that are associated with that account's usage of that service. You can nestExpressionobjects to define any combination of dimension filters. For more information, see Expression.Valid values for
MatchOptionsforDimensionsareEQUALSandCASE_SENSITIVE.Valid values for
MatchOptionsforCostCategories,Tags, andProductAttributesareEQUALS,ABSENT, andCASE_SENSITIVE. Default values areEQUALSandCASE_SENSITIVE.You can filter by product attributes with or without grouping by them. If you filter or group by product attributes, the results include only the costs of supported services, and a
SERVICEfilter is optional. For more information, see ProductAttributeValues.If you include a
SERVICEfilter, it must apply to the whole request: combine it with other filters by usingAnd, and include it in every branch of anOr. ASERVICEfilter insideNotdoesn't meet this requirement, and the request fails with aValidationException. -
metrics(MetricNames) –Which metrics are returned in the query. For more information about blended and unblended rates, see Why does the "blended" annotation appear on some line items in my bill?.
Valid values are
AmortizedCost,BlendedCost,NetAmortizedCost,NetUnblendedCost,NormalizedUsageAmount,UnblendedCost, andUsageQuantity.If you return the
UsageQuantitymetric, the service aggregates all usage numbers without taking into account the units. For example, if you aggregateusageQuantityacross all of Amazon EC2, the results aren't meaningful because Amazon EC2 compute hours and data transfer are measured in different units (for example, hours and GB). To get more meaningfulUsageQuantitymetrics, filter byUsageTypeorUsageTypeGroups.Metricsis required forGetCostAndUsagerequests. -
group_by(Optional[GroupDefinitions], default:None) –You can group Amazon Web Services costs using up to two different groups, either dimensions, tag keys, cost categories, product attributes, or any two group by types.
Valid values for the
DIMENSIONtype areAZ,INSTANCE_TYPE,LEGAL_ENTITY_NAME,INVOICING_ENTITY,LINKED_ACCOUNT,OPERATION,PLATFORM,PURCHASE_TYPE,SERVICE,TENANCY,RECORD_TYPE, andUSAGE_TYPE.When you group by the
TAGtype and include a valid tag key, you get all tag values, including empty strings.To group by the
PRODUCT_ATTRIBUTEtype, setKeyto a product attribute key, such asmodel. For the keys of each supported service, see ProductAttributeValues. The results include only the costs of supported services, and if you have no such costs, the response contains no groups.In the response, each group key has the format
key$value, for example,model$Claude Sonnet 5. Costs that have no value for the key are in the groupkey$, for example,model$. Remove thekey$prefix before you use a value in aProductAttributesfilter. Keys are case-sensitive: if you group by a key that doesn't exist, such asModel, all of your costs of supported services are in the groupModel$. -
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.
-
next_page_token(Optional[NextPageToken], default:None) –The token to retrieve the next set of results. Amazon Web Services provides the token when the response from a previous call has more results than the maximum page size.
Raises:
-
BillExpirationException–The requested report expired. Update the date interval and try again.
-
BillingViewHealthStatusException–The billing view status must be
HEALTHYto perform this action. Try again when the status isHEALTHY. -
DataUnavailableException–The requested data is unavailable.
-
InvalidNextTokenException–The pagination token is invalid. Try again without a pagination token.
-
LimitExceededException–You made too many calls in a short period of time. Try again later.
-
RequestChangedException–Your request parameters changed between pages. Try again with the old parameters or without a pagination token.
-
ResourceNotFoundException–The specified ARN in the request doesn't exist.
-
UnknownServiceError–The service returned an error code this client does not model.
Source code in docs_src/capo_cost_explorer/_services/async_cost_explorer.py
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 | |