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

Replace eleastic ip access to web app hosted on EC2 instance in aws with load balancer


We have a subdomain under our company domain for our application: myapp.company.com.

Few years ago the following setup was done

  • myapp.company.com points to an elastic IP (done by the company IT)
  • elastic IP targets an public internet facing EC2 instance

Now I'm trying to find a way to switch that setup so it make use of a classic load balancer.

I created an internet facing classic load balancer

  • is in the security group of the VPC in which the instance is
  • targets the instance which is currently reachable through the elastic ip

I'm able visit the web apps on the instance through the load balancer with the public ip defined in the network interface of the load balancer.

After that, I thought a hosted zone would do the trick of routing the calls to myapp.company.com to the load balancer.

So I created a hosted zone

  • domain name when creating the hosted zone: myapp.company.com
  • added an A record which has the load balancer's dns name as alias target

But the load balancer is not used.


Solution

  • If you are going to use Classic Load Balancer, you need to make a note of the string from ELB DNS name (for example, my-load-balancer-1234567890.us-west-2.elb.amazonaws.com). After that, ask your IT support to modify DNS record for myapp.company.com to CNAME which points to ELB:

    myapp.company.com  CNAME  my-load-balancer-1234567890.us-west-2.elb.amazonaws.com
    

    (creating the hosted zone in AWS Route53 will only work after someone (zone owner, so probably IT) delegates authority for your (sub)domain to your AWS name servers, and it is most probably not worth doing just for the sake of one record)