MongoTimeoutException on Mongo 4.0 in Atlas with AWS EC2 using 4.1.1 mongo client

JDK: openjdk version “11.0.10” 2021-01-19
Mongoclient version: 4.1.1
Mongo database used in Atlas: 4.0.23
Deployed in: AWS

Please help in understanding what is causing the issue and resolving it.
Below is the exception seen in log as soon as the java application starts:

com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@4f3e65f4. Client view of cluster state is {type=REPLICA_SET, servers=[{, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by { connect timed out}}, {,.....exception={`com.mongodb.MongoSocketOpenException: Exception opening socket`}, caused by { connect timed out}}]
	at com.mongodb.internal.connection.BaseCluster.createTimeoutException(
	at com.mongodb.internal.connection.BaseCluster.selectServer(
	at com.mongodb.internal.connection.AbstractMultiServerCluster.selectServer(
	at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(
	at com.mongodb.client.internal.MongoClientDelegate.createClientSession(
	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(
	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(
	at com.mongodb.client.internal.MongoIterableImpl.execute(
	at com.mongodb.client.internal.MongoIterableImpl.iterator(

This is resolved.
The route tables: Had to use route table with the proper subnet associated, not the one with nat.
The security groups: Had to update outbound rules with CIDR of atlas cluster.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.