title: How to handle disconnect event in AWS IOT?
body: <p>I'm doing real-time update in my web application. The application connects to AWS IOT using <a href="https://github.com/aws/aws-iot-device-sdk-js" rel="nofollow noreferrer">aws-iot-device-sdk</a>:</p>
  
  <pre><code>const client = awsIot.device({
      region: awsConfig.region,
      protocol: 'wss',
      accessKeyId: &lt;accessKey&gt;,
      secretKey: &lt;secretKey&gt;,
      sessionToken: &lt;sessionToken&gt;,
      port: 443,
      host: &lt;iotEndpoint&gt;
  });
  
  client.on('connect', res =&gt; {
      // ok
  });
  </code></pre>
  
  <p>Then I send request to my API for creating a record in database table which contains IOT topic id. Then application subcribes to this topic id:</p>
  
  <pre><code>client.subscribe(topicId)
  </code></pre>
  
  <p>I want to delete records in database when client disconnects from IOT. How should I do that? I see that there is a <a href="http://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html" rel="nofollow noreferrer">disconnect event</a> in IOT. But I don't understand how to handle this event in AWS lambda.</p>