ECS tasks stops server while connecting to mongo atlas

1

“message”:“Server selection timed out after 30000 ms”,“reason”:{“type”:“ReplicaSetNoPrimary”,“servers”:{},“stale”:false,“compatible”:true,“heartbeatFrequencyMS”:10000,“localThresholdMS”:15,“setName”:“atlas-uhi03q-shard-0”}

This is error I am receiving when I connect to mongo atlas instance from ECS tasks (EC2 instance running on private subnet). Runs well when I run this application from localhost. I have also enabled VPC peering and IP under network access is open to the world. Cannot figure out the issue. Appreciate some help here.

  • Issue with outbound network connection from ec2 instance. I had created VPC endpoints for AWS related services, but for mongo atlas I had to create NAT gateway. With the registration of NAT gateway and allowing all routes in the routing table established mongo atlas connection from private ec2 instance. VPC peering might work, but as I was on shared cluster in mongo it didn't work for me.

1 個回答
-1

A few things on top of my head:

  • Do you connect with the mongo+srv:// address ? If not, you should and make sure to have open the security group ports on your VPC Private Link (I presume that's what you meant by peering). That way the clients in reply will get both IP address and port to connect to. That's how we do and connection works great
  • Did you create a MongoDB user with your EC2 IAM task role ? If not, I'd recommend that over username/password. Checkout in CloudFormation -> Public Extensions -> 3rd Party -> look for MongoDb::Atlas::AwsIamDatabaseUser. Of course, that's if you use CFN.
profile picture
已回答 2 年前
  • Yes I connect using mongo+srv:// address.. VPC peering is the latest option looks like but didn't work for me, as I am on the shared cluster. I have enabled all HTTP for my alb. What are the security ports I should enable? Can you share any links or elaborate a bit here?

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

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

回答問題指南