0

I am new to AWS and I have a question. I want to host a website on two EC2 instances. From what I read, if I stop the EC2 instance the public IP will change. In my case, Route 53 should route traffic to load balancer.

How can I configure my load balancer to route the traffic to EC2 instances without changing the IP if I change one of them? In other words, is there a way to have a fixed public IP to my two EC2 instances when they are switched off such that my load balancer routes the traffic to them?

Thanks.

freginold
  • 239
  • 1
  • 7
Ahmed
  • 103
  • 1
  • 4

2 Answers2

2

AWS Load Balancer service can automatically distribute traffic between EC2 instances, containers, and IP addresses. You only have to be sure your route53 record points to the Load Balancer domain endpoint. Once done that, you can safely add/remove instances from the load balancer, no need to manually update/change ip addresses.

  • Thanks dennis so if I stopped my instance there would be no problem right ? – Ahmed Mar 26 '18 at 19:36
  • Load balancers don't use public IP addresses, so it changing makes no difference. If you turn one server off the ELB will route traffic to the working server. If you turn both servers off your website won't work. – Tim Mar 26 '18 at 19:43
0

This is a pretty common scenario. Basically, you need to point your Route53 to your LB - the LB is static, a named endpoint managed by AWS. What's behind the LB isn't relevant as far as your Route53 entry is concerned.

Additionally, if you want to automatically update your LB with your active hosts, you can configure your autoscaling group in EC2 to automatically put new instances on your LB (just make sure you give them enough time to actually start the application they're running).

Route53 will send traffic targeted at your.endpoint.xyz to the dns entry of the LB. The LB will then take that traffic, and distribute it to the active instances it's aware of at any given time.

If the instances behind your LB are terminated, they'll be removed from the LB (and no traffic will be routed to them).

MrDuk
  • 865
  • 2
  • 10
  • 18