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;
};

demandé il y a 4 ans333 vues
1 réponse
0

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

répondu il y a 4 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions