aws / aws-iot-device-sdk-js

SDK for connecting to AWS IoT from a device using JavaScript/Node.js
Apache License 2.0
964 stars 384 forks source link

AWS IoT SDK Device Publish is Timing out on Lambda Function #321

Closed universidadeglobal closed 4 years ago

universidadeglobal commented 4 years ago

Hi, I am using a aws sdk for nodeJs in my Lambda function to publish to AWS IOT Thing topic. The payload is being published, I can confirm in test client in AWS IoT. But for some reason it is generating a timeout in function. I can configure any timeout value from 3 seconds to 3 minutes, the result is the same. Below my code:


const device = awsIot.device({
            keyPath: './private.pem.key',
            certPath: './certificate.pem.crt',
            caPath: './ca_root.pem',
            clientId: makeid(10),
            host: 'aki0kv5z61fxo-ats.iot.us-east-1.amazonaws.com'
        });
        device
        .on('connect', function() {
          console.log('connect');
          device.publish('$aws/things/portao_automatico/shadow/update', 
              JSON.stringify({
                  state : {
                      desired : {
                          porta : "fechada"
                      }
                  }
          }));
      }); 
bretambrose commented 4 years ago

Hello,

Without knowing much about node/js, it seems possible that having an instantiated device creates one or more recurrent tasks that keep node alive indefinitely and that you'll need to add a callback that shuts down the device on the appropriate event (pub ack maybe, if you're just doing a one-time operation).

What happens when you run your code locally in node?

universidadeglobal commented 4 years ago

@bretambrose Thanks for reply. I have changed my strategy. The objective is to use the code in Amazon Alexa Skill, and I have now tested with AWS SDK instead of AWS IOT SDK and works fine. Thanks a lot.