Can not connect to Atlas Mongo server from Fargate container without public IP

0

There is AWS Fargate instance that was created without public IP. It is located in the network where everything is allowed by default. No explicit bans. There is a table that routes out default traffic to the internet gateway. But I can not get the mongo atlas server. Resources were downloaded to the container using VPC endpoints.

I receive the following error.

Error inside node js application

[currency.listen] (node:79) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/

Mongo connection URL

mongodb+srv://victor:**************@pet-db.x8n6pl4.mongodb.net/?retryWrites=true&w=majority mongo connection url.

I thought that IGW routing is enough. Under there are network settings. It works with public IP. I am trying to keep everything secure doing everything properly. Could you give me some advice?

Network

Outbound routing

ruleto
10.10.0.0/1local
0.0.0.0/0igw-06fe0dabd17281f51
pl-6da54004vpce-0ef14f2a86cd8de02
### Outbound ACL
Rule numberType
--
100All traffic
*All

Security group

NameSecurity group rule IDIP versionTypeProtocolPort rangeDestinationDescription
-sgr-044001697d4c97b32IPv4All trafficAllAll0.0.0.0/0

Regards, Victor.

profile picture
Victor
已提問 10 個月前檢視次數 721 次
1 個回答
1
已接受的答案

Your ECS Fargate task needs to be attached to a subnet which has a default route to a NAT Gateway.

Then traffic from NAT gateway needs to route to an internet gateway.

Internet gateways only work when resources have public IP addresses and an RFC1918 IP addresses routing will be dropped on the internet.

I have also used MongoDB atlas before which offers connection via VPC peering and private link. That may also be another means to explore long term than over the internet.

profile picture
專家
已回答 10 個月前
profile picture
專家
已審閱 10 個月前
profile pictureAWS
專家
iBehr
已審閱 10 個月前
  • The main idea is that IGW does not work without public IP. I am wondering why. For example, our computers work well inside nested network topologies with routing and gateways without any static IPs.

  • Because you will at some point have a NAT ip address. This could be an edge firewall/router or a proxy server.

    These devices will hide your private IP addresss.

    Think of a IGW as a router. Nothing more. You need a public IP address to route across the internet.

  • I agree every internet provider has at least one public IP. So it does not work without public IP. Routing to IGW it is just a try to get closer to the gates. Thank you.

  • Any issues or questions please reach out again

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南