Dynamically create AWS IoT topic
Asked Answered
T

2

7

Is it possible to create a AWS IoT topic dynamically .

For example, Is it possible to set a RULE where once the message is received, It creates a topic dynamically or through lambda function.

Or is it possible through AWS-SDK

Any suggestion would be helpful

Trustee answered 16/10, 2017 at 9:10 Comment(1)
What have you tried so far to get this working?Eucken
G
13

You don't have to explicitly "create" topics in AWS IoT (MQTT). You would simply subscribe to, or start posting to a topic and if the topic doesn't already exist the IoT service will create it automatically.

Gild answered 16/10, 2017 at 13:55 Comment(1)
The message broker uses topics to route messages from publishing clients to subscribing clients. The forward slash (/) is used to separate topic hierarchy. Ref: docs.aws.amazon.com/iot/latest/developerguide/topics.htmlClaro
V
1

If I got your question, this is how I am doing whit lambdas:

const AWS = require('aws-sdk')
const iotdata = new AWS.IotData({endpoint: xxxxxxxxxx})

const publishMqtt = (params) =>
  new Promise((resolve, reject) =>
  iotdata.publish(params, (err, res) => resolve(res)))


module.exports.publishMQTT = async event => {
...
let someTopic1 = 'foo'
let someTopic2 = 'bar'
...
    var params = {
        topic: `topicTest/${someTopic1}/${someTopic12}`,
        payload: '{"aaa":"bbb"}',
        qos: '0'
    };

    await publishMqtt(params)
...
}
Vharat answered 25/6, 2020 at 14:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.