Reputation: 49
I have a lambda function working to write measurement data to a Timestream table. The measurements each have a row in the Timestream table as this is the standard in Timestream. In nov 2021, AWS announced the Multi-Measure record functionality for Timestream tables. Because this would make my datastructure a lot simpler, I tried to transform the lambda function to do that.
I have a decoder.js file that takes care of putting a json payload with measurements of several remotely monitored generator sets (objects) in the right data structure before writing them to a Timestream table by the export handler in the index.js file. This is de code of de decoder function that works fine thus far (the runtime is Node.js 14.x):
function decodeMeasurement(payload, objectnr)
{
var output = [];
const dimensions = [{
'Name': "genset_name",
'Value': payload.objects[objectnr].name.toString()
},
{
'Name': 'imei',
'Value': payload.objects[objectnr].imei.toString()
}];
for (var variablenr = 0; variablenr < payload.objects[objectnr].variables.length; variablenr++){
output.push ({
'Dimensions': dimensions,
'MeasureName': payload.objects[objectnr].variables[variablenr].name.toString(),
'MeasureValue': payload.objects[objectnr].variables[variablenr].value.value.toString(),
'MeasureValueType': 'DOUBLE',
'Time': Date.parse(payload.objects[objectnr].variables[variablenr].value.date).toString()
});
}
return (output);
}
I've tried to re-code this into the new MultiMeasurement Record structure, but it failed thusfar.
function decodeMeasurement(payload, objectnr)
{
var output = [];
console.log('The number of variables is:️ ', payload.objects[objectnr].variables.length);
const dimensions = [{
'Name': "genset_name",
'Value': payload.objects[objectnr].name.toString()
},
{
'Name': 'imei',
'Value': payload.objects[objectnr].imei.toString()
}];
for (var variablenr = 0; variablenr < payload.objects[objectnr].variables.length; variablenr++){
output.push ({
'Dimensions': dimensions,
'MeasureName': 'measurementvalues',
'MeasureValueType': 'MULTI',
'MeasureValues':{
'Name': payload.objects[objectnr].variables[variablenr].name.toString(),
'Value': payload.objects[objectnr].variables[variablenr].value.value.toString(),
'Type': 'DOUBLE'},
'Time': Date.parse(payload.objects[objectnr].variables[variablenr].value.date).toString()
});
}
return (output);
}
I can't figure out what's wrong to the new code, I hope to get some tips that could make this work. Thanks!
Upvotes: 2
Views: 1198