I have a number of EC2 instances in 3 availability zones. The application that I'm running on these instances are communicating with multiple third party applications that have a whitelist mechanism. I know that I'm able to communicate to those third party applications by using static IP addresses (Elastic IP) by using a NAT gateway. If I do that then I need to specify a specific route for each third party application to make it work. What I would like to achieve is a static outgoing IP without defining all those routes. So basically by default routing all traffic through the NAT gateway. I tried the following but than I can not access my application anymore. (By the way all those EC2 instances are behind an application LoadBalancer)
subnet routing table:
10.0.0.0/16 -> local
0.0.0.0/0 -> NAT Gateway
NAT Gateway subnet routing table
10.0.0.0/16 -> local
0.0.0.0/0 -> Internet Gateway
It will work if I setup the following routing tables but then I have to setup specific routes for each third party application that my application is communicating with.
subnet routing table:
10.0.0.0/16 -> local
0.0.0.0/0 -> Internet Gateway
ThirdPartyApplicationIp/32 -> NAT Gateway
NAT Gateway subnet routing table
10.0.0.0/16 -> local
0.0.0.0/0 -> Internet Gateway
By defining these route specifically we can have issues when, for example, DNS records get updated and ip addresses change. I know that this will occur because I know some third party applications are using AWS with ELB's as well and IP's of ELB's will changes over time. Besides that is just not very convenient when we have to manage all of these third party applications like this.
Is there a way to solve this so I don't have to define specific routes for each third party application and still are able to access my application through a Application LoadBalancer and respects DNS changes?
Additional problem:
Solving this could also solve the following problem that I'm not having yet but will have in the near future: In the future when our application is communicating with a third party application and that application is connecting the our application as well, then the traffic is routed through the NAT Gateway. Because that is the routing I set up but then it will not work once the third party applications is trying to connection through the application LoadBalancer to our applications because then the traffic should be routed through the Internet Gateway directly instead of routing it through the NAT gateway. But if I do that then I will lose my static IP. Is there way of solving this?
Results from Matt's suggestion: Matt suggestion works but I don't really understand why. So I started played around with that setup to try to find out what the difference is. Because the routing tables are the same, as I did before, and that seemed odd to me. It turns out that if I add one EC2 instance to the private subnet that has a assigned public ip (Making it a public subnet again) the whole routing fails and my ELB would not respond anymore to requests. After deleting that new EC2 instance(with that assigned public ip) it still failed. Only after deleting the Availability Zones in my ELB and adding my private subnets again it works. Now what I don't understand is why just be simply adding a new EC2 instance with a public IP breaks all the routing? (That new EC2 instance is not in de Target Group of the ELB, just sitting idle in the subnet)