I set up connection between Atlas MongoDB and our VPC using AWS Peering. Configuration went smoothly but I do not know how to connect to my cluster from EC2 in our subnet. I do not know how to find IP MongoDB cluster ? When I try generate snippet on Mongodb page it generates something like this:
DNS resolves the cluster’s hostnames to their public IP address rather than their internal IP address if:
DNS hostnames are disabled,
DNS resolution is disabled, and
The user accesses the Atlas cluster from outside a peered VPC.
One method you can follow to try verify if the hostnames are resolving to a private IP is to perform the following from a client within a subnet associated with the VPC peering:
Resolve hostnames from SRV record. Further information here on this from my other topic reply.
ping the hostname(s) resolved from step 1
At step 2, the hostname(s) should resolve to a private IP assuming the VPC peering and DNS configuration are both set up appropriately. (AWS) Clients connecting from outside the VPC peering connection can use the same connection string but will connect over the public internet (assuming their IP is on the Network Access List).
If you’re still having trouble with VPC peering setup, you can try contacting the in-app Atlas chat support however this may only be useful if you’re having issues setting the VPC peering connection up from the Atlas end. There can be some configurations / cases where the DNS configuration on the AWS’s client side (some mentioned above) which cause the SRV record to resolve to public IP addresses rather than internal IP addresses.