Usando AWS re:Post, accetti AWS re:Post Termini di utilizzo

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.

posta 4 mesi fa226 visualizzazioni
1 Risposta
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
ESPERTO
con risposta 4 mesi fa
profile picture
ESPERTO
verificato 4 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande