Premature Close when using Devices
See original GitHub issueI’m a little new to using AWS IoT, so I was going through the examples trying to get a basic device communicating, but I keep getting a Premature Close error and I can’t really pinpoint why this is happening.
My code is as follows:
const device = awsIot.device({ keyPath: '<full path>/21e89ffb9e-private.pem.key', certPath: '<full path>/21e89ffb9e-certificate.pem.crt', caPath: '<full path>/rds-ca-2015-root.pem', clientId: 'Database_Handler', host: 'a30u0mm8b3ldbd-ats.iot.us-east-2.amazonaws.com' });
And the error I keep getting is:
Error: premature close at onclosenexttick (<full path>/node_modules/end-of-stream/index.js:54:86) at processTicksAndRejections (internal/process/task_queues.js:79:11) Emitted 'error' event on DeviceClient instance at: at MqttClient.<anonymous> (<full path>/node_modules/aws-iot-device-sdk/deviceindex.js:772:15) at MqttClient.emit (events.js:333:22) at TLSSocket.f (<full path>/node_modules/once/once.js:25:25) at onclosenexttick (<full path>/node_modules/end-of-stream/index.js:54:73) at processTicksAndRejections (internal/process/task_queues.js:79:11)
This is taken pretty much directly from the device-example.js file in the repository, the only significant difference is that I’m not using the command line process, but from what I understood that was something that could be omitted.
I noticed an Issue with the same problem that was closed, but there wasn’t a solution in the thread, so I was hoping to get some clarification here by opening a new one. Thank you for the help.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (2 by maintainers)

Top Related StackOverflow Question
I had this issue, and it turned out I had forgotten to attach a policy to the certificate.
I am getting the same error. The policy is attached to my certificate. I execute the process and it connects to AWS IoT and it remains like this for at least a week and it suddenly disconnects.