AWS.IotData.publish callback is not called

0

Hello
I have a Lambda function that uses AWS.IotData.publish to send some data to my MQTT client
There are no errors when the function executes but the MQTT client that subscribes to the topic never receives the message and there is no indication in the log that the message was sent. Any ideas what may be wrong?
Here is the function (simplified)
Interestingly, if there is an error in parameters the callback is called and the error is printed.
But when there are no errors the console message is not printed and the packet does not go out.

var AWS = require('aws-sdk');

exports.handler = async (event) => {
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
var iotdata = new AWS.IotData({endpoint: 'xxxxxxx-iot.us-west-2.amazonaws.com',apiVersion: '2015-05-28'});

var params = {  
    topic: 'mytopic/1234' ,  
    payload: 'somedata',  
    qos: 0  
};  
  

iotdata.publish(params, function(err, data) {
if(err){
console.log("Error on MQTT publish: " + err);
}
else{
console.log("Success, I guess.");
}
});

return response;
};

已提問 4 年前檢視次數 333 次
1 個回答
0

Got it.
When I removed the keyword async from the handler declaration the message in the callback was printed.

已回答 4 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南