Reputation: 169
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
Upvotes: 7
Views: 2711
Reputation: 5560
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)
...
}
Upvotes: 1
Reputation: 201008
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.
Upvotes: 13