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

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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠