What would be best way to achieve such thing:

I have limited amount of elastic ips, and I have bunch on EC2 instances to launch small apps.

I have an idea to have load-balancer or an EC2 instance that could route traffic to any other EC2 instances.

For example there would be 3 instances:

  • Instance 1 (ec2-00-00-0-01.eu-west-2.compute.amazonaws.com)
  • Instance 2 (ec2-00-00-0-02.eu-west-2.compute.amazonaws.com)
  • Instance 3 (ec2-00-00-0-03.eu-west-2.compute.amazonaws.com)

I would want to use Public IPv4 DNS of these instances.

So for example how could I have single place that could route traffic based on domain name.

EC2 instance (nginx reverse proxy) or A load-balancer in AWS would listen for requests of domains:

  • instance1.com (would route traffic to ec2-00-00-0-01)
  • instance2.com (would route traffic to ec2-00-00-0-02)
  • instance3.com (would route traffic to ec2-00-00-0-03)

What would be your approach to handle such scenario?

1 Answer 1


Do your applications need to be address by IP? Are they standard http(s)? If appropriate just set up an ALB, use the domain names provided, and don't bother with static IPs.

Two things I'm not sure you know:

  • Within a VPC only private IPs are used. NAT to public IPs is done at the internet gateway. i.e. the load balancer connects to the instances using their private IP, which never changes

  • When you use a load balancer you put the CNAME into DNS, rather than the IP address. Basically IP addresses become irrelevant if you use a load balancer.

  • They are standard HTTP / HTTPS web apps. The one issue I have is that in case of reboot - IP of the EC2 will change? And then I will need to update IP for the domain name it points to?
    – LuckyLuke
    Commented Nov 9, 2022 at 9:08
  • 1
    When behind a load balancer, the IP address of the EC2 instance(s) is irrelevant. This is because the domain points to the load balancer, not to your instance(s). Commented Nov 9, 2022 at 14:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .