Amazon's new Elastic IP (EIP) addresses allow users to allocate an IP address and assign it to an instance of their choice. What's really cool is that each IP address can be reassigned to a different instance when needed. For example, if the first one failed or if a new one is supposed to take its place.
Before going into an example, let's review how the Elastic IPs work:
- You can allocate up to 5 Elastic IP addresses per account (default).
- Each EIP can be assigned to one instance, in which case it replaces the normal dynamic IP address. Remember, by default, each instance starts with a dynamic IP address.
- Each instance can have only a single external IP address. It starts out with the default dynamic IP address which can be swapped out for an EIP at any time. If the EIP is deassigned (or assigned to a different instance) then a fresh dynamic IP is allocated for the instance. The limitation of designating a single IP at a time is due to the way NAT (Network Address Translation) works. Remember that each instance has an internal IP address and an external (public) one, which is translated to the internal one. If two external IPs were translated to the same internal IP then inbound packets would arrive fine, but sorting out outgoing packets (i.e. determining which external IP address to assign to outgoing packets) would be very difficult. Hence, the limitation of a single external IP address per instance at any given point in time.
- EIPs are free while they are assigned to an instance, but they cost $0.01/hr if they are not assigned. The reason for this charge is due to the fact that the number of IP addresses worldwide is very limited. Perhaps in theory, this charge will help prevent users from hogging unused IP addresses that could be dynamically allocated to other users. Yet, in a weird way there is no additional cost to Amazon for an assigned static IP as opposed to a dynamic IP because while an EIP is assigned to an instance it actually frees-up a dynamic IP.
- Assigning or reassigning an IP to an instance takes a couple of minutes, which is longer than I would have hoped for, but I can imagine that many network devices need to be updated in the infrastructure to make it all happen.
Let's look at a simple example of an application server running Apache and a PHP app, talking to a back-end MySQL database server and how Elastic IPs can improve the process of updating the site. First we allocate an Elastic IP. Suppose we get 18.104.22.168 assigned. Then we set up the DNS in our preferred outsourced DNS service and map our website name to the IP address, e.g. www.rightscale.com -> 22.214.171.124. Having done that, we can launch our web server and database server. Once the web server boots and we have the website running, we assign it the EIP and can soon thereafter point our browser to www.rightscale.com. Here's how this looks:
Now suppose we want to update from our current production release of the website (we called it rel2 in the diagram) to rel3. The power of the cloud is that we don't need to touch our existing web server and risk causing damage during the upgrade process. Instead we launch a second web server (shown in the diagram below as www_rel3) and install the new release on it. We can point a different DNS entry, such as test.rightscale.com, at the default dynamic IP provided for the instance by EC2 and test the site to make sure everything works properly.
Once we're confident in the new test version, we simply reassign the EIP 126.96.36.199 to the www_rel3 instance and shortly thereafter all users accessing the site are now receiving data packets from the new release. Remember, as long as the www_rel2 is available, you can easily swap back and forth between www_rel2 and www_rel3 until you are completely satisfied with the new site. And when you're ready, you can terminate the old www_rel2 instance. See diagram below.
Amazon did a nice job in creating something much more powerful than simply adding "static IPs" to their offering. It is giving us dynamically remappable IP addresses that fit well into the overall cloud computing paradigm that we can use to manage servers better than with traditional hosting solutions.
The RightScale dashboard supports the new Elastic IPs, so all the operations described above are easy to initiate and monitor, even when using the free editions of the RightScale Dashboard. We are now in the process of updating our ServerTemplates so our customers can take full advantage of not only the Elastic IPs but also the new Availability Zones.