No connection to IoT Core in Docker on an EC2

0

Hello, how are you?

I have an application where IoT devices connect to my topic on IoT Core. I created a device on IoT Core to subscribe to the same topic, receive the messages, and send them to my database through my Node.js/backend environment (I perform some operations on these messages before storing them). When I run my entire application in a Docker container in my local environment, everything works fine: the application connects to IoT Core and receives the messages without any issues.

However, when I deploy my application on an EC2 instance and run the same Docker container, with the same files, certificates, etc., the other parts of the API work normally, but the MQTT connection does not. Even with logs, there is no indication of an error. It seems that the connection to IoT Core does not even start.

Something very strange happens: if I leave the application running in the cloud (even with MQTT not working and not receiving messages) and try to start the application on my computer, MQTT starts a process of closing and reconnecting the connection both in the cloud and locally, and this continues until I stop one of the two applications. When I stop the application on my PC, the application on EC2 starts working correctly, receiving the messages from IoT Core and sending them to the database after processing.

I would like to resolve this issue so that the application works correctly whenever I start the Docker container on EC2, without needing this 'workaround' to make it work.

已提问 3 个月前209 查看次数
1 回答
2

Hi. Each connection needs to use a unique client ID. If two clients use the same client ID, each client connection will cause the other client to disconnect with reason DUPLICATE_CLIENTID: https://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html#connect-disconnect.

It seems that the connection to IoT Core does not even start.

You can confirm in the AWS IoT Core console, or in CloudWatch, whether it's connecting or not.

Please also be aware that a single connection to AWS IoT Core is limited to 100 messages per second (or 512KB per second). I don't know how many devices you have, but your architecture won't scale for a large fleet of devices. I recommend you instead consider to use AWS IoT Core rules engine, and a fan-in pattern: https://iotatlas.net/en/implementations/aws/telemetry/fan-in1/. You might consider to use services such as Amazon SQS or Amazon Kinesis Data Streams to store your incoming messages until your application can consume them: https://iotatlas.net/en/best_practices/aws/data_ingest/#decouple-ingest-from-processing-with-queues-and-streams-1

profile pictureAWS
专家
已回答 3 个月前
profile picture
专家
已审核 3 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则