otmezger
otmezger

Reputation: 10794

aws iot: how to trigger an act rule / lambda only when the message has a different payload than before?

I'm having a lot of inbound messages via mqtt on aws iot. Most of the messages have the same payload, and only change the timestamp.

I need to run a lambda function that stores the data, but I only want to store data points when actually something changed. How can check for this inside the lambda function? Does the lambda function configured under act, triggered by $aws/things/THING-NAME/shadow/update/documents runs before the shadow gets updated or after?

this is the configuration of my rule: enter image description here

thanks

Upvotes: 0

Views: 744

Answers (1)

thomasmichaelwallace
thomasmichaelwallace

Reputation: 8482

The lambda gets triggered after the device shadow has updated.

But importantly the event payload sent to this lambda will contain two keys { previous, current }. The previous and current keys will contain the full device shadow before and after the update respectively.

So to achieve what you want, you can then compare the previous and current to see what values have changed, excluding things like timestamps, etc.

Upvotes: 2

Related Questions