meterUsage method
API to emit metering records. For identical requests, the API is idempotent. It simply returns the metering record ID.
MeterUsage is authenticated on the buyer's AWS account using credentials from the EC2 instance, ECS task, or EKS pod.
MeterUsage 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).
May throw InternalServiceErrorException. May throw InvalidProductCodeException. May throw InvalidUsageDimensionException. May throw InvalidTagException. May throw InvalidUsageAllocationsException. May throw InvalidEndpointRegionException. May throw TimestampOutOfBoundsException. May throw DuplicateRequestException. May throw ThrottlingException. May throw CustomerNotEntitledException.
Parameter productCode
:
Product code is used to uniquely identify a product in AWS 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 one hour 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 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,
bool? dryRun,
List<UsageAllocation>? usageAllocations,
int? usageQuantity,
}) async {
ArgumentError.checkNotNull(productCode, 'productCode');
_s.validateStringLength(
'productCode',
productCode,
1,
255,
isRequired: true,
);
ArgumentError.checkNotNull(timestamp, 'timestamp');
ArgumentError.checkNotNull(usageDimension, 'usageDimension');
_s.validateStringLength(
'usageDimension',
usageDimension,
1,
255,
isRequired: true,
);
_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,
if (dryRun != null) 'DryRun': dryRun,
if (usageAllocations != null) 'UsageAllocations': usageAllocations,
if (usageQuantity != null) 'UsageQuantity': usageQuantity,
},
);
return MeterUsageResult.fromJson(jsonResponse.body);
}