5
votes

I'm working on a web application where the user can login with AWS Cognito. After login with the AWS credentials I'm connecting to AWS IoT device like

var device = AwsIot.device({ 
    clientId: clientID, 
    host: host, 
    accessKeyId: credentials.accessKeyId, 
    secretKey: credentials.secretAccessKey, 
    protocol: 'wss', 
    sessionToken: credentials.sessionToken, 
    offlineQueueing: 'false' 
}); 

Then once the user logout from the app using AWS Cognito using

cognitoUser.signOut(); 

Then after logout I want to disconnect the the AWS IoT device as well. Right now I'm seeing even after the logout the device is listening to the events like

device.on('close', function() {}) 
device.on('error', function() {}) 
device.on('offline', function() {}) 

Can someone please specify which function should I call to disconnect the device as well so that it don't listen to these events as well.

I was going through the doc https://github.com/aws/aws-iot-device-sdk-js But I didn't got any specific function for this.

Moreover I used the AWS credential to connect the AWS IoT device, and once I logout from Cognito then the device should have been automatically disconnected as well I think. Please let me know what should be the approach here.

1

1 Answers

4
votes

I got the answer from AWS IOT support team on this.

The AwsIot.device class is a wrapper for the MQTT class with helpers to assist with connecting to AWS endpoints To disconnect your device, you can call device.end(); This will close your connection and invoke device.on('close'). As for Cognito Sign-out. This will not invalidate the session credentials already provided by Cognito which were used to establish the connection. They will continue to be valid until their assume role time expires.