Pass SNS ARN as a variable to IoT Event Detector Model

0

Hello.

I am using IoT Events to monitor some IoT processes and trigger SMS and email when a threshold is exceeded.

The detector model is generic, it is the same for all processes since everything necessary is passed as an input variable through a rule using IoT Core.

The problem is that the recipients (SNS Topic) vary depending on the device to be monitored, therefore, you must have an Input and a Detector Model according to the SNS Topic to whom the alerts should reach, which is very inefficient.

Is there a way to pass the SNS Topic ARN through an IoT Core rule and thus only have one Input and one Detector Model?

I tried to place as a variable (for example $input.ExampleInput.topic) in the SNS Topic box in the action, which would arrive through the IoT Core rule, but it shows me an error: Invalid ARN used for SNS Topic Publish Action.

Thanks!

1 Answer
0

You're absolutely right, directly passing the SNS Topic ARN through an IoT Core rule and using it in the SNS Topic field of an IoT Events action isn't supported .**

Maybe try this approach:**

1/ Instead of specifying the SNS topic directly in the detector model, introduce a dynamic variable (e.g., $topic) within the model itself. This variable will hold the SNS Topic ARN received from the IoT Core rule.

"sns": { "topicArn": "$topic", // Use the dynamic variable here "messagePayload": "Alert! Metric for device $device exceeded threshold: $metric" }

2/ Update your IoT Core rule to extract the relevant SNS Topic ARN and device ID from the incoming message. Use the sql expression language in the IoT Core rule to filter and extract the desired information. Include the extracted SNS Topic ARN and device ID within the message payload sent to IoT Events. "sql": "SELECT *, EXTRACT(topic_arn FROM message) AS topic, EXTRACT(device_id FROM message) AS device FROM 'your_topic'",

Please note I havn't tried it myself. Give it a try and share the feedback if it works.

profile pictureAWS
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions