I am using ElasticBeanstalk to host a site. I am using MongoAtlas for my MongoDB. I need to white list on Mongo’s side the IP for all EC’s being used by BeanStalk. I was thinking of creating a NatGateway so all traffic from the BeanStalk deployment would use that one IP. I tried testing by creating setting up a stand alone EC2 instance and a Nat GW. I modified the route table for the EC2 instance so any traffic for 1.1.1.1 should go through the Nat GW. When I do any traces to any IP’s it works. However if I try to trace to 1.1.1.1 then it dies with the last responding hop being the nat GW’s IP. What am I doing wrong?
How is the NAT gateway deployed? It needs to be in a subnet where that subnets default route points to an internet gateway, and then the separate subnet / route table can be pointing to the NGW for connectivity.
Your node needs to be in a private subnet with a default route to the NAT GW. Your NAT GW needs to be in a public subnet that has a default route to an IGW.
Why do you need to trace route to 1.1.1.1? It sounds like you knew what to do and it worked, what’s the issue with this 1 trace succeeding?
OP, this is correct. You will have to create a new route table in VPC console and associate it with your NAT gateway subnet. Host subnet route table points at NAT gateway, NAT gateway subnet route table has a default route to an igw-.
My issue then is this. I am using Elastic Bean Stalk. My URL is something like:
http://sit-env.eba-nr2vua9d.us-east-1.elasticbeanstalk.com/
When I go there it loads no issue. If I change the route table for the subnet that is I no longer have access to the ELB. I assume because when it gets a packet it tries route it back out through the NAT GW. How do I configure ELB to use the NAT GW? (In my test I was using EC2 to see if I understood Nat gw’s correctly).
Oh so that means you need DNAT through the NAT gateway for inbound connections? You might look into a reverse proxy or load balancer to put out front of it in that case.
If you absolutely need incoming connections to hit the same public address the server uses to get to the internet, I think you’ll need an instance to handle that for you.
At the risk of sounding shill-ish (im not sales I promise lol) the free or “NATe” edition of my employer’s product would be able to do that no problem. VNS3 if you want to try one from the marketplace.
Edit: wait you already have an ELB, can you put that in the public subnet with your NAT gateway?
Using a NAT will give you a fixed IP, but look at option for Mongo Atlas VPC enpoints:
https://www.mongodb.com/docs/atlas/security-private-endpoint/
The ELB goes in the public subnet and does not use the NAT GW. Your application should live in the private subnet and will use the NAT GW when initiating outbound connections.
From what I have seen in the docs it won’t work for a server less deployment.
But… you’re using beanstalk to host it on ec2?