Hello @Julio_Montes_de_Oca ,
As you are able to connect to cluster even from your EC2 instance so it should not be any network/connectivity issues. Moreover, your URL seems correct and the error seems to come from the driver/application side.
I would recommend you to upgrade your MongoJava-sync-driver v4.7.2 to MongoJava-sync-driver v 4.10.2 as there are a lot of bug fixes, improvements and new features available.
Have you tried below recommended methods provided in the Timeout Error section of Java Sync Connection troubleshooting?
Timeout Error
Sometimes when you send messages through the driver to the server, the messages take a while to respond. When this happens, you might receive an error message similar to one of the following error messages:
Timed out after 30000 ms while waiting for a server that matches >ReadPreferenceServerSelector{readPreference=primary}.No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster descriptionIf you receive one of these errors, try the following methods to resolve the issue.
Set
maxConnectionTimeoutMSThe
maxConnectionTimeoutMSoption indicates the amount of time the Java driver waits for a connection before timing out. The default value is10000. You can increase this value or set it to0if you want the driver to never timeout.Set
maxConnectionLifeTimeandmaxConnectionIdleTimeConsider setting
maxConnectionLifeTimeandmaxConnectionIdleTime. These parameters configure how long a connection can be maintained with a MongoDB instance. For more information about these parameters, see Connection Pool Settings.Check the Number of Connections
You might have too many open connections. The solution to this is described under Error Sending Message.
Install Certificate
If you are using an older version of Java, you might need to manually install some certificates as described under Error Sending Message.