Package Exports
- @mattkirwan/dynamodb-aggregator
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@mattkirwan/dynamodb-aggregator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
DynamoDB Aggregator
A simple utility module for aggregating dynamodb fields. Currently only aggregates per hour.
Install
npm i --save @mattkirwan/dynamodb-aggregator
Usage
const aggregate = require("@mattkirwan/dynamodb-aggregator")
There is currently only one exported function:
Functions
hourly()
Params
documentClient - AWS.DynamoDB.DocumentClient - An instance of the DocumentClient from aws-sdk
metaData - Object - An object defining the DynamoDB table/keys you would like to operate against. Example below.
data - Object - An object containing the timestamped events with which you would like to aggregate. Example below.
Examples
metaData
let metaData = {
TableName: "aggregate_dev",
PartitionKeyName: "campaign_id",
SortKeyName: "timestamp_3600",
}data
// { PartitionKeyX: { AggregateFieldNameX: [ EventTimestamp, EventTimestamp ] } }
let data = {
// Partition Key
"1234campaign5678": {
// Table Field Name
"total_show": [
// Events (timestamps in ms)
1562157215000,
1562158775000,
1562162375000,
]
},
"5678campaign1234": {
"total_show": [
1562157215000,
1562158775000,
1562162375000,
],
"total_action": [
1562157215000,
1562158775000,
1562162375000,
1562162375000,
]
}
}The above inputs would store the following in DynamoDB:

Use
Returns a Promise.all containing all of the update query responses from the DynamoDB request.
return await aggregate.hourly(documentClient, metaData, data)
.then(r => {
console.log(r)
return
})
.catch(e => {
console.log(e)
return
})Successful response:
{
Attributes: {
total_show: 2,
campaign_id: '5678campaign1234',
timestamp_3600: 1562155200,
total_action: 1
},
ConsumedCapacity: {
TableName: 'aggregate_dev',
CapacityUnits: 1
}
}Tests
It's got a decent amount of unit tests. Run using npm run test.