5
votes

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

2
What have you tried so far to get this working?ajtrichards

2 Answers

10
votes

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.

0
votes

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)
...
}