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

preguntada hace 4 años333 visualizaciones
1 Respuesta
0

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

respondido hace 4 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas