IOT Core rules to map timestamp to timestream

0

I'm trying out IoT core. I have data going into a topic, and a rule is being triggered to write that data to timescale. The input data is JSON and it contains a field 'timestamp' at the top level, it's a standard ISO8660 string.

The part I'm having trouble with is understanding how to set up the Rule to tell timestream to get the time from a property of my json rather than the default ${timestamp()}. Since my data is an ISO8660 string I know I need to parse it, so I can

SELECT
   fields.rms0 as rms0,
   fields.rms1 as rms2,
   parse_time(timestamp) as ts
}

but adding it as 'ts' doesn't do what I want. What do I put in the rule box, ${ts} is my first guess, but I don't want ts to also end up as a metric, and I'm not sure how to prevent that.

For reference, my input format is this:

{
   measurement: "something",
   timestamp: "2022-01-01T00:00:00Z",
   fields: {
        "rms0": 1.23456,
       /* more fields */
   },
   tags: {
       /* some other stuff */
   }
}
profile picture
wz2b
gefragt vor 2 Jahren1074 Aufrufe
1 Antwort
1
Akzeptierte Antwort

Hi. You should use the time_to_epoch() function in the Timestamp value of the Rule Action. In your case:

${time_to_epoch(timestamp,"yyyy-MM-dd'T'HH:mm:ss'Z'")}

Please see the discussion of time_to_epoch() here: https://docs.aws.amazon.com/iot/latest/developerguide/timestream-rule-action.html

I don't want ts to also end up as a metric, and I'm not sure how to prevent that.

Please change your rule query statement to:

SELECT fields.rms0 as rms0, fields.rms1 as rms1 FROM 'foo/bar'
profile pictureAWS
EXPERTE
Greg_B
beantwortet vor 2 Jahren
profile picture
EXPERTE
überprüft vor einem Monat
  • So you are saying it will pull the attribute named 'timestamp' out of my JSON even though it's not part of the SELECT?

  • I am indeed saying that. And I tested it before saying that. :-)

  • Thank you very much. It works great!!!

  • Thankyou for posting this, but what do I put as the Timestamp unit ?

  • time_to_epoch() returns the epoch time in milliseconds.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen