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.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则