user9650710
user9650710

Reputation: 360

How to see public ip address of elastic beanstalk instance for whitelisting mongodb atlas

I am trying to connect to a database hosted on mongo atlas from a service running on elastic beanstalk. I am getting the error:

UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [youmaylike-shard-00-01-necsu.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to youmaylike-shard-00-01-necsu.mongodb.net:27017 closed]

I believe this is happening because I don't have the Ip address of my service whitelisted on atlas. I am unsure of how to get the Ip address for my service, I tried running eb ssh but I'm not sure what it gave me is the correct value

Upvotes: 7

Views: 14771

Answers (3)

rodrigocprates
rodrigocprates

Reputation: 566

From MongoDB Atlas support:

If you have dynamic IP addresses, you have the following options;

  1. You can use the Atlas Public API to dynamically add and remove IPs from your whitelist. For MongoDB Atlas documentation on configuring Atlas API Access, please click here.
  2. You can use VPC Peering (M10+ instances only) to link your Atlas cluster to your existing VPC. For documentation Setting up a VPC peering connection in MongoDB Atlas, please click here.
  3. Or you can set your whitelist to 0.0.0.0/0 to allow the entire Internet into your IP whitelist. For MongoDB Atlas documentation on adding entries to your IP Whitelist, please click here. Please note that adding 0.0.0.0/0 to the cluster’s whitelist as this can expose the cluster to denial of service attacks. Also, please be aware that Heroku uses dynamic IPs, so you will have to add 0.0.0.0/0 to the whitelist when using Heroku to connect to your Atlas Cluster.

See asked question on their FAQ.

Upvotes: 0

Adiii
Adiii

Reputation: 59906

The public IP depend upon the configuration of your Elastic beanstalk instances.

Internet Access:

Instances must have access to the Internet through one of the following methods.

Public Subnet

  • Instances have a public IP address and use an Internet Gateway to access the Internet.

Private Subnet

  • Instances use a NAT device to access the Internet.

So, if it's behind Gateway then you can check here for whitelisting or might this help too

aws ec2 describe-instances --instance-ids i-0c9c9b44b --query 'Reservations[*].Instances[*].PublicIpAddress' --output text

or

curl http://checkip.amazonaws.com

If it's behind NAT then you need to whitelist the NAT Gateway IP.

Goto VPC -> Select NAT Gateways -> Copy the Elastic IP or public IP adress of NAT Gateway and whitelist this IP in atlas side.

Upvotes: 0

Everton Yoshitani
Everton Yoshitani

Reputation: 946

There are multiple ways to get it, below two:

Before using the AWS console or the AWS CLI run eb health and get the intance ID or IDs for your deployment

  1. Using the AWS Console go to EC2 and then Instances find the instance ID or IDs click it and on the pane below the IP will be located at "IPv4 Public IP"

  2. Using the AWS CLI aws ec2 describe-instances --instance-ids <YOUR INSTANCE ID or IDS HERE>

Upvotes: 5

Related Questions