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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则