AWS IoT Timestream Rule Action write: Problem with float and int values

1

Hello,

we have some sensors that send multiple variables (temp, humidity, pressure) through the IoT core writing them to timestream and dynamoDB at the same time using an IoT rule (SQL 2016-03-23).

We are having some problems with rejected values when trying to write those values. Cloudwatch says:

"failedAction": "TimestreamAction",
"errorMessage": "Failed to write records to Timestream. The error received was 'One or more records have been rejected. See RejectedRecords for details. (Service: AmazonTimestreamWrite; Status Code: 419; Error Code: RejectedRecordsException; Request ID: xxx; Proxy: null), Rejected records: [{RecordIndex: 9,
Reason: Measure name already has an assigned measure value type. Each measure name can have only one measure value type and cannot be changed.,}]'. Message arrived on mit/decoded, Action: timestream, Database: sensordata-timestream-db, Table: mit-timestream-table"

The natural type of the values is double and the first write in timestream defined that measurement with the correct type. The problem relies when some of the measurements are with decimal part equal to zero (which can be interpreted as an int), for example 13.0. In this case Timestream detects it as an int instead of double and rejects the measurement.

Reading the documentation and different questions here in re:Post, I saw that a possible solution is to cast the variable as double, but seems not be working. This is how we are casting it:

SELECT 
cast(event.payload_sensordata.Hum_SHT as double) as Hum_SHT
....
FROM ....

Another way we have tested without luck is casting as DECIMAL instead of double.

This is what we are seeing in both tables:

Enter image description here

Any thoughts on how to solve this within the IoT rule?

Thanks!

asked 2 years ago970 views
2 Answers
2

Hi. Per the AWS IoT Core Timestream rule action documentation:

Enter image description here

So you will need to change the SQL version of your rule. This setting is immediately above the SQL statement when you edit the rule.

Alternatively, you can use a Lambda action instead.

profile pictureAWS
EXPERT
answered 2 years ago
0

Thank you very much Greg, it is working like a charm now!

I had seen that documentation, but it completele missunderstood it. I thought the behaviour was only when casting to DECIMAL and as i was casting to duble instead, it didn't make sense to me.

Thank you once again!

answered 2 years ago
  • Good stuff! And if you really want to thank me, please do consider Accepting my answer so I get my precious 10 points. :-)

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions