How can I identify the sender of a shadow update that's been forwarded?

0

I set up a rule in my IoT service that examines shadow update requests coming in from my devices by monitoring the topic with the reserved name for shadow updates, namely, $aws/things/+/shadow/update. When it notices certain kinds of updates that we consider exceptional, the rule forwards the message to an SQS queue. We plan to have a server running on an EC2 instance that monitors this queue so it can take appropriate action.

The problem I'm having is that when the EC2 instance receives the message from the queue, all it gets is the JSON containing the desired state as requested by the device. But there is nothing in this message that includes the name or identity of the device that sent it. I need that information to take action.

One solution might be to have the device itself include its own name in the shadow state, but I don't really like this idea. Ideally, I'd like to somehow have the rule append the device name to the message (or just append the name of the topic which includes the device name). I don't see any obvious way for rules to send modified messages or append information this way. Is it a viable solution?

If not, what's the recommended approach?

Thanks, Frank

Frank
已提問 2 年前檢視次數 237 次
1 個回答
1
已接受的答案

You can use the SELECT clause to modify the message: https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-select.html

In this case, you probably want to use the topic() function: https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html

Something like: SELECT *, topic(3) as thing FROM $aws/things/+/shadow/update

profile pictureAWS
專家
Greg_B
已回答 2 年前
  • This worked great, thanks.

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

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

回答問題指南