get_cost_and_usage_with_resources
async
¶
get_cost_and_usage_with_resources(
time_period: DateInterval,
granularity: Granularity,
filter: Expression,
*,
config_overrides: Optional[AsyncCostExplorerClientConfig] = None,
metrics: Optional[MetricNames] = None,
group_by: Optional[GroupDefinitions] = None,
billing_view_arn: Optional[BillingViewArn] = None,
next_page_token: Optional[NextPageToken] = None,
) -> GetCostAndUsageWithResourcesResponse
Retrieves cost and usage metrics with resources for your account. You can specify which cost and usage-related metric, such as BlendedCosts or UsageQuantity, that you want the request to return. 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.
Hourly granularity is only available for EC2-Instances (Elastic Compute Cloud) resource-level data. All other resource-level data is available at daily granularity.
This is an opt-in only feature. You can enable this feature from the Cost Explorer Settings page. For information about how to access the Settings page, see Controlling Access for Cost Explorer in the Billing and Cost Management User Guide.
Parameters:
-
time_period(DateInterval) –Sets the start and end dates for retrieving Amazon Web Services costs. The range must be within the last 14 days (the start date cannot be earlier than 14 days ago). 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
MONTHLY,DAILY, orHOURLY. IfGranularityisn't set, the response object doesn't include theGranularity,MONTHLY,DAILY, orHOURLY. -
filter(Expression) –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.The
GetCostAndUsageWithResourcesoperation requires that you either group by or filter by aResourceId. It requires the Expression"SERVICE = Amazon Elastic Compute Cloud - Compute"in the filter.Valid values for
MatchOptionsforDimensionsareEQUALSandCASE_SENSITIVE.Valid values for
MatchOptionsforCostCategories,Tags, andProductAttributesareEQUALS,ABSENT, andCASE_SENSITIVE. Default values areEQUALSandCASE_SENSITIVE.If you filter or group by product attributes, the
SERVICEfilter rules are the same as for GetCostAndUsage. -
metrics(Optional[MetricNames], default:None) –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 the units into account. 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, hour or GB). To get more meaningfulUsageQuantitymetrics, filter byUsageTypeorUsageTypeGroups.Metricsis required forGetCostAndUsageWithResourcesrequests. -
group_by(Optional[GroupDefinitions], default:None) –You can group Amazon Web Services costs using up to two different groups:
DIMENSION,TAG,COST_CATEGORY, andPRODUCT_ATTRIBUTE.PRODUCT_ATTRIBUTEgroups work the same way as in GetCostAndUsage. APRODUCT_ATTRIBUTEgroup or aProductAttributesfilter doesn't meet the requirement to group by or filter by aResourceId. -
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
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 | |