I've a mongodb server hosted outside my VPC. I can access it directly over internet from my local system. I'm unable to connect it from instance in my private subnet. I have a NAT instance which allows All TCP from cidr of my VPC. I'm using this NAT instance in my route with destination 0.0.0.0/0 and this NAT instance as target. Subnet Network ACL allow all traffic inbound and outbound. From the private instance I tried ping google.com and wget www.google.com and both are working so internet access is there. Only connecting to mongodb is failing with connection timeout.
connection attempt failed: SocketException: Error connecting to <mongo endpoint> :: caused by :: Connection timed out
There is another mongodb server hosted on atlas. That is also available over internet to any IP. I'm again able to connect it from my local system and from instances in my default VPC but same connection timeout happens when try to access from instance in private subnet. Security Groups in private instance are as follows
Inbound
ALL TCP - source (vpc cidr)
Outbound
All traffic - desstination 0.0.0.0/0