AppMonetization / Client / get_metric_usage
get_metric_usage¶
- AppMonetization.Client.get_metric_usage(**kwargs)¶
Returns a user’s raw per-metric usage over a caller-supplied window. Usage is aggregated by event time with each metric’s aggregation function: summed or counted, or the largest value for a MAX metric, in the environment the scope selects (the live app or its sandbox). It returns usage only: it does not resolve the user’s plan, apply quota, or attribute usage to a plan. Combine it with GetSubscriptionHistory to compute charges for each plan the user was on, or compare it against a plan’s allowance to make an entitlement decision.
Usage is read at hour resolution: startedAt is floored to its hour and endedAt is rounded up to the next hour boundary, so the window read can be wider than the requested one.
Paginated over the app’s metric set: one page of per-metric usage per call, continued with nextToken. The window is fixed across a pagination sequence.
See also: AWS API Documentation
Request Syntax
response = client.get_metric_usage( appId='string', userId='string', startedAt=datetime(2015, 1, 1), endedAt=datetime(2015, 1, 1), scope='sandbox'|'live', maxResults=123, nextToken='string' )
- Parameters:
appId (string) –
[REQUIRED]
The ID of the app.
userId (string) –
[REQUIRED]
The end user whose usage is read. Do not include personally identifiable or otherwise sensitive data in this value.
startedAt (datetime) –
[REQUIRED]
Inclusive start of the reporting window (half-open [startedAt, endedAt)).
endedAt (datetime) –
[REQUIRED]
Exclusive end of the reporting window. Must be after startedAt; the window may span at most 744 hours (31 days, the longest monthly billing period). Must not be in the future beyond a small clock-skew allowance.
scope (string) –
[REQUIRED]
Required. The environment: live or sandbox. sandbox reads the app’s isolated test environment. Usage is kept separately per environment.
maxResults (integer) – Maximum number of per-metric usage entries to return in this page (1-25, default 25).
nextToken (string) – Opaque continuation token from a prior response. The window (startedAt/endedAt) must be unchanged across a pagination sequence.
- Return type:
dict
- Returns:
Response Syntax
{ 'usage': [ { 'metricId': 'string', 'quantity': 'string' }, ], 'nextToken': 'string' }
Response Structure
(dict) –
Output for GetMetricUsage.
usage (list) –
One entry per metric in this page, carrying its usage over the window. A metric with no events in the window is returned with usage = 0.
(dict) –
A single metric’s raw usage over the window.
metricId (string) –
The metric this usage is for.
quantity (string) –
The metric’s usage over the window, as a plain decimal string (for example, “1500” or “12.5”). For a SUM or COUNT metric this is the total; for a MAX metric it is the largest value recorded. Within a fixed window the value can only grow, as late-arriving events are counted.
nextToken (string) –
Opaque continuation token. Present when more metrics remain; pass it back (with the same window) to read the next page. Absent on the last page.
Exceptions
AppMonetization.Client.exceptions.AccessDeniedExceptionAppMonetization.Client.exceptions.ValidationExceptionAppMonetization.Client.exceptions.InternalServerExceptionAppMonetization.Client.exceptions.ResourceNotFoundExceptionAppMonetization.Client.exceptions.ThrottlingException