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!

已提問 2 年前檢視次數 748 次
2 個答案
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
專家
Greg_B
已回答 2 年前
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!

已回答 2 年前
  • Good stuff! And if you really want to thank me, please do consider Accepting my answer so I get my precious 10 points. :-)

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南