How can i publish to a topic in iot core using lambda function?

0

Hey, i can invoke a lambda function from iot core, but can i trigger a lambda function that can publish to a topic in my iot core endpoint? If i subscribe to this topic in MQTT test client, i should receive the data from the lambda function? Is it possible? Please share the code.

質問済み 1年前1382ビュー
1回答
0

Hi,

You can leverage sdk to publish payloads towards a iot core topic.

See below example (https://repost.aws/questions/QUyQP-7Ki6T2202ZHCZ-qkig/questions/QUyQP-7Ki6T2202ZHCZ-qkig/publish-to-iot-endpoint-of-other-account-iotdata-sdk-nodejs-lambda).

const iotData = new AWS.IotData({
      endpoint: 'xyz.com', // IoTEndpoint
      credentials: remoteCredentials
    });

    const data = await iotData.publish({
      topic: `topicfilter/data/clientId`,
      payload: JSON.stringify({event: 'something'}),
      qos: 1
    }).promise();

Documentation: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/IotData.html

Hope it helps ;)

profile picture
エキスパート
回答済み 1年前
  • hey, can you provide the whole code, and how can i get the credentials and what permission or policies do i need to apply? Thank you so much

  • Updated answer with code reference + documentation ;)

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ