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

asked 4 years ago328 views
1 Answer
0

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

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions