how to access mongodb instance outside a VPC
Asked Answered
I

2

9

I followed the AWS quickstart guide for creating a MongoDB cluster. This created a NAT Instance (Public subnet) as well as a single PrimaryReplicaNode instance (internal IP only). I can SSH into the NAT and furthermore, I can SSH into the Primary Replica from the NAT. I've verified that MongoDB is accessible from the command line, but I have to get "through" two servers to get there.

On the other hand, I did a quickstart node.js server on Elastic Beanstalk. I also placed it within the same VPC and security groups as the NAT.

So I've got 3 total instances. 1 Elastic Beanstalk instance running node and 2 EC2 instances running as a MongoDB cluster.

My question is... how do I connect into MongoDB from the Elastic Beanstalk application?

Do I need to give Elastic Beanstalk the same key that I gave the NAT so it could access the internal Primary node? Or do I connect to the NAT's external address from Node.js and then tunnel into the cluster? What exactly needs to connect to what in order to make it serve its purpose?

Any advice would be much appreciated!

Ic answered 9/4, 2017 at 19:26 Comment(2)
Did you find any solution for this?Spinoza
would you provide a diagram of your architecture, vpc configuration inclusing the routing rules between subnets. It seems to be a problem with your VPC.Etoile
I
0

You need to check the configuration of the Security groups assigned to the elasticbeanstalk servers and the mongoDB be sure the rules to allow access in both

Iberia answered 12/9, 2018 at 23:41 Comment(0)
G
0

I would recommend using a CloudFormation template to create everything you need for the new VPC env. Here is a CloudFormation template provided by AWS which handles proper creation of a VPC (public / private subnets, nat gateway configs, security groups, etc). Was a huge help for me personally. https://docs.aws.amazon.com/codebuild/latest/userguide/cloudformation-vpc-template.html

From there you will need to create a new aws EB cluster. I would recommend saving you current config so can could use it to stand up the new env much more easily. But make sure to config the new env with your new VPC. You will still need to due the same for the mongo ec2 instances (make sure they are in the new VPC) and make another security group which has proper configs to access to the aws eb instances within the VPC.

With only one manual security group creation step (for the mongo instances) this is much cleaner and sure fire why to ensure everything is setup correctly from a networking perspective.

Now you just can tell your app to speak directly to your mongodb (using the private dns resolution for the mongo host within the VPC - note: enable dns resolution within the vpc upon creation!)

Hope this helps

Galla answered 21/8, 2019 at 16:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.