Implement AWS MeterUsage
- Dominant language
- JavaScript
- Stars
- 400
- Forks
- 89
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 146
Description
## Introduction
As part of the AWS Marketplace onboarding process, we need to implement metered usage for FlowForge Cloud.
## Description
Create a function to call the BatchMeterUsage API, including the necessary request parameters such as ProductCode and UsageRecords when a user wants to purchase a Node-RED instance. The billing overview page should work normally, even without Stripe being active.
## Example code (see [AWS docu](https://docs.aws.amazon.com/marketplacemetering/latest/APIReference/API_BatchMeterUsage.html))
```javascript
const AWS = require('aws-sdk');
const marketplaceMetering = new AWS.MarketplaceMetering();
const productCode = 'your-product-code';
async function submitMeterUsage(customerIdentifier, dimension, quantity) {
const usageRecords = [
{
CustomerIdentifier: customerIdentifier,
Dimension: dimension,
Quantity: quantity,
Timestamp: Math.floor(Date.now() / 1000),
},
];
const params = {
ProductCode: productCode,
UsageRecords: usageRecords,
};
try {
const response = await marketplaceMetering.batchMeterUsage(params).promise();
console.log('BatchMeterUsage Response:', response);
if (response.UnprocessedRecords.length > 0) {
console.error('Unprocessed Records:', response.UnprocessedRecords);
// Handle unprocessed records, possibly by retrying the request.
}
} catch (error) {
console.error('Error submitting meter usage:', error);
// Handle specific errors, such as InvalidProductCodeException or ThrottlingException.
}
}
// Example usage
submitMeterUsage('example-customer-identifier', 'Node-RED-Size', 1);
```
### Epic/Story
https://github.com/flowforge/flowforge/issues/1927
Contributor guide
Assessment
This issue has not been assessed yet.