meterUsage method
As a seller, your software hosted in the buyer's Amazon Web Services account uses this API action to emit metering records directly to Amazon Web Services Marketplace. You must use the following buyer Amazon Web Services account credentials to sign the API request.
-
For Amazon EC2 deployments, your software must use the IAM
role for Amazon EC2 to sign the API call for
MeterUsageAPI operation. -
For Amazon EKS deployments, your software must use IAM
roles for service accounts (IRSA) to sign the API call for the
MeterUsageAPI operation. Using EKS Pod Identity, the node role, or long-term access keys is not supported. -
For Amazon ECS deployments, your software must use Amazon
ECS task IAM role to sign the API call for the
MeterUsageAPI operation. Using the node role or long-term access keys are not supported. -
For Amazon Bedrock AgentCore Runtime deployments, your software
must use the AgentCore
Runtime execution role to sign the API call for the
MeterUsageAPI operation. Long-term access keys are not supported.
MeterUsage requests varies between Amazon
Bedrock AgentCore Runtime and non-Amazon Bedrock AgentCore deployments.
-
For non-Amazon Bedrock AgentCore Runtime deployments, you can only
report usage once per hour for each dimension. For AMI-based products,
this is per dimension and per EC2 instance. For container products, this
is per dimension and per ECS task or EKS pod. You can't modify values
after they're recorded. If you report usage before a current hour ends,
you will be unable to report additional usage until the next hour begins.
The
Timestamprequest parameter is rounded down to the hour and used to enforce this once-per-hour rule for idempotency. For requests that are identical after theTimestampis rounded down, the API is idempotent and returns the metering record ID. -
For Amazon Bedrock AgentCore Runtime deployments, you can report
usage multiple times per hour for the same dimension. You do not need to
aggregate metering records by the hour. You must include an idempotency
token in the
ClientTokenrequest parameter. If using an Amazon SDK or the Amazon Web Services CLI, you must use the latest version which automatically includes an idempotency token in theClientTokenrequest parameter so that the request is processed successfully. TheTimestamprequest parameter is not rounded down to the hour and is not used for duplicate validation. Requests with duplicateTimestampsare aggregated as long as theClientTokenis unique.
You can optionally include multiple usage allocations, to provide customers with usage data split into buckets by tags that you define or allow the customer to define.
For Amazon Web Services Regions that support MeterUsage, see
MeterUsage
Region support for Amazon EC2 and MeterUsage
Region support for Amazon ECS and Amazon EKS.
May throw CustomerNotEntitledException.
May throw DuplicateRequestException.
May throw IdempotencyConflictException.
May throw InternalServiceErrorException.
May throw InvalidEndpointRegionException.
May throw InvalidProductCodeException.
May throw InvalidTagException.
May throw InvalidUsageAllocationsException.
May throw InvalidUsageDimensionException.
May throw ThrottlingException.
May throw TimestampOutOfBoundsException.
Parameter productCode :
Product code is used to uniquely identify a product in Amazon Web Services
Marketplace. The product code should be the same as the one used during
the publishing of a new product.
Parameter timestamp :
Timestamp, in UTC, for which the usage is being reported. Your application
can meter usage for up to six hours in the past. Make sure the
timestamp value is not before the start of the software
usage.
Parameter usageDimension :
It will be one of the fcp dimension name provided during the publishing of
the product.
Parameter clientToken :
Specifies a unique, case-sensitive identifier that you provide to ensure
the idempotency of the request. This lets you safely retry the request
without accidentally performing the same operation a second time. Passing
the same value to a later call to an operation requires that you also pass
the same value for all other parameters. We recommend that you use a UUID type
of value.
If you don't provide this value, then Amazon Web Services generates a random one for you.
If you retry the operation with the same ClientToken, but
with different parameters, the retry fails with an
IdempotencyConflictException error.
Parameter dryRun :
Checks whether you have the permissions required for the action, but does
not make the request. If you have the permissions, the request returns
DryRunOperation; otherwise, it returns
UnauthorizedException. Defaults to false if not
specified.
Parameter usageAllocations :
The set of UsageAllocations to submit.
The sum of all UsageAllocation quantities must equal the
UsageQuantity of the MeterUsage request, and
each UsageAllocation must have a unique set of tags (include
no tags).
Parameter usageQuantity :
Consumption value for the hour. Defaults to 0 if not
specified.
Implementation
Future<MeterUsageResult> meterUsage({
required String productCode,
required DateTime timestamp,
required String usageDimension,
String? clientToken,
bool? dryRun,
List<UsageAllocation>? usageAllocations,
int? usageQuantity,
}) async {
_s.validateNumRange(
'usageQuantity',
usageQuantity,
0,
2147483647,
);
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'AWSMPMeteringService.MeterUsage'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'ProductCode': productCode,
'Timestamp': unixTimestampToJson(timestamp),
'UsageDimension': usageDimension,
'ClientToken': clientToken ?? _s.generateIdempotencyToken(),
if (dryRun != null) 'DryRun': dryRun,
if (usageAllocations != null) 'UsageAllocations': usageAllocations,
if (usageQuantity != null) 'UsageQuantity': usageQuantity,
},
);
return MeterUsageResult.fromJson(jsonResponse.body);
}