I need to publish data from aws lambda via the mqtt protocol using aws iot. I created a lambda function with node.js. code like this
exports.handler = (event, context, callback) => { var awsIot = require('aws-iot-device-sdk'); var device = awsIot.device({ keyPath: 'samplepath/test.pem.key', certPath: 'samplepath/test.crt', caPath: 'samplepath', clientId: 'sampleId', region: 'us-east-1' }); device .on('connect', function () { console.log('connected'); device.publish('test_topic', JSON.stringify({ "test_name": "hello", "test_value": 1001 })); console.log('published successfully'); callback(null, 'item added'); }); }
I received the mqtt message on the subscriber. but lambda produces an error message like this
Task timed out after 10.00 seconds
I used context.succeed () instead of a callback, lambda exited properly. I canβt get any messages on the subscriber.
In both cases, deleted messages are successfully published successfully.
What is the problem with my post code?
source share