- Mais recentes
- Mais votos
- Mais comentários
Hi,
What SDK did you use in your lambda function? Are you using the same client Id as you used in device? The client id should be UUID for each connection.
Thanks,
Fengyi
I did not use any sdk in my lambda function. I update the device over the HTTP endpoint. The client ids should be ok.
For now I cannot reproduce the misbehaviour anymore. It's working fine now and I don't know why because I haven't changed anything.
I'm marking this question as answered.
I want to reopen this issue. I am facing the same issue.
I am trying to do a very simple feature :
javascript(subscribe.js) -> aws iot (mqtt broker)
javascript(publish.js) -> aws iot (mqtt broker)
i am only trying to utilise teh mqtt broker capability of aws, that is , i am trying to use aws iot as an mqtt broker.
from the management console i am able to hold pub/sub.
PFB code for subscribe.js:
var awsIot = require('aws-iot-device-sdk');
//
// Replace the values of '<YourUniqueClientIdentifier>' and '<YourCustomEndpoint>'
// with a unique client identifier and custom host endpoint provided in AWS IoT.
// NOTE: client identifiers must be unique within your AWS account; if a client attempts
// to connect with a client identifier which is already in use, the existing
// connection will be terminated.
//
var device = awsIot.device({
keyPath : 'secret.pem.key',
certPath:'secret.pem.crt',
caPath : 'rootCA.pem',
clientId : 'id121',
host : 'secret.iot.secret.amazonaws.com'
});
//
// Device is an instance returned by mqtt.Client(), see mqtt.js for full
// documentation.
//
device
.on('connect', function() {
console.log('connect');
device.subscribe('topic_2/#');
});
device
.on('message', function(topic, payload) {
console.log('message', topic, payload.toString());
});
/*device
.on('close', function() {
console.log('close');
});
device
.on('reconnect', function() {
console.log('reconnect');
});
device
.on('offline', function() {
console.log('offline');
});
device
.on('error', function(error) {
console.log('error', error);
});*/
PFB code for publish.js:
var awsIot = require('aws-iot-device-sdk');
//
// Replace the values of '<YourUniqueClientIdentifier>' and '<YourCustomEndpoint>'
// with a unique client identifier and custom host endpoint provided in AWS IoT.
// NOTE: client identifiers must be unique within your AWS account; if a client attempts
// to connect with a client identifier which is already in use, the existing
// connection will be terminated.
//
var device = awsIot.device({
keyPath : 'secret.pem.key',
certPath:'secret.pem.crt',
caPath : 'rootCA.pem',
clientId : 'id121',
host : 'secret.iot.secret.amazonaws.com'
});
//
// Device is an instance returned by mqtt.Client(), see mqtt.js for full
// documentation.
//
device
.on('connect', function() {
console.log('connect');
//device.subscribe('topic_2/#');
device.publish('topic_2/2', 'hello');
});
/*
device
.on('message', function(topic, payload) {
console.log('message', topic, payload.toString());
});
device
.on('close', function() {
console.log('close');
});
device
.on('reconnect', function() {
console.log('reconnect');
});
device
.on('offline', function() {
console.log('offline');
});
device
.on('error', function(error) {
console.log('error', error);
});*/
Please help !!
thanks
Aarushi
I'm having the same issue with a similar code. To see that there was never a resolution posted for this is not encouraging.
:-(
The immediate problem is that both clients use the same client ID
clientId : 'id121',
Good luck.
If you want to learn AWS IoT in minutes, check out https://mqttlab.iotsim.io/aws
To address the constant disconnections you are seeing with the MQTT client, try these things out:
- Verify that the MQTT client is using the correct AWS IoT endpoint, certificate and key files. Even a small error could cause connectivity issues.
- Check for any network firewalls or proxies that could be terminating idle connections. AWS IoT uses keepalive to maintain connections but intermediaries may still interfere.
- Monitor the AWS IoT console and CloudWatch metrics for any spikes in errors or throttling that could indirectly impact clients.
- Try reducing the MQTT QoS level, keepalive time or increasing timeout thresholds in the client to make it more robust to temporary disruptions.
- As a test, try running the client directly on an EC2 instance within the same AWS region to bypass any external network variability.
- Review client code for any exceptions or errors during connection or message handling. Debug logs may provide more insight into the disconnect reasons. Proper configuration of TLS, certificates and network accessibility are key for reliable MQTT connectivity.
Conteúdo relevante
- AWS OFICIALAtualizada há 10 meses
- AWS OFICIALAtualizada há 3 anos
- AWS OFICIALAtualizada há 3 anos
- AWS OFICIALAtualizada há 2 anos
I had the same issue and spent hours trying to figure it out. Then I read on github that it was due to missing permission. The error code generated is confusing but if you check the logs you'll see that some permission were missing.
https://github.com/aws/aws-iot-device-sdk-python-v2/discussions/329