Search code examples
amazon-web-servicesamazon-ec2ipwebhookselastic-ip

AWS EC2 multi instance exit with a single IP Address


I have an AWS infrastructure as follow:

  • EC2-WS01
  • EC2-WS02
  • Load balancer

These machines run the same code. In front of these machines is there a Load Balancer that distribute the load. So the clients point to the load balancer that forward the requests. One of the services of my app is a webhook service that send to an external server, protected by a firewall, some information every 15 minutes. We had to setup the firewall accepting the request from the two EC2 IP Address. I want to know if is possible make sure that regardless of the instances I have, when I make a request, it is always made by the same ip

Is possible to do that with an Elastic IP or what else?


Solution

  • Your architecture would need to be:

    • Load Balancer in a public subnet
    • Amazon EC2 instances in private subnet(s)
    • A NAT Gateway or NAT Instance in a public subnet, with an Elastic IP address
    • A Route Table on the private subnet(s) that sends Internet-bound traffic via the NAT Gateway/NAT Instance

    The traffic from the Amazon EC2 instances will "come from" the public Elastic IP address associated with the NAT Gateway/NAT Instance.