Search code examples
amazon-web-servicesamazon-ec2dnsa-recordselastic-ip

Multiple EC2 instances with Elastic IPs


I currently have one EC2 instance running with an Elastic IP. In my DNS settings, I have an A record pointing to the Elastic IP.

If I wanted to add a second instance, how would I go about doing that? I know how to launch them, and get the data transferred, but what do I do in my AWS console and DNS settings to have more than one instance pointing to the same website?

Thank you in advance!


Solution

  • Are you talking about having 2 EC2 instances serving the same website? If so, that means that you will need to setup a load balancer. AWS makes that pretty easy using Elastic Load Balancing.

    The basic procedure is like this:

    1. In your EC2 control panel, choose "Load Balancers">"Create Load Balancer".
    2. Give the load balancer a descriptive name and set your preferences depending on your setup. You will probably be fine with the defaults (the most likely change will be adding an https port.
    3. Give it a security group (this works just like EC2 server instances)
    4. Configure your ssl settings if you need them.
    5. Point the health check to a page that the load balancer can use to make sure that your server is working properly.
    6. Add your instances to the balancer.

    At this point you're pretty much done. ELBs do not allow you to assign them an elastic IP, as such, you need to change your dns record from an A to a CNAME and point your domain at the ELB dns name.

    There are some more advanced settings you can mess with depending on the exact needs of your application. For instance, if your website relies on sessions that are stored on the individual instances you'll want to enable sticky sessions.