Every server on the cloud can have multiple IP addresses - public and private
The public IP address is what’s used when attempting to connect to the instance via ssh or instance connect
When starting a server, we’re gonna receive a private and, optionally, public IP addresses e.g 10.0.0.1 and 55.125.54.33. The public IP address is especially important because if we want to interact with the server in any way, we need to know its public IP address or at least the domain name pointing to it.
Let’s say you’re creating a side project but you had to take a break so you stopped the server and came back after few weeks. When restarting the server, you’ll notice that the public IP address had changed.
Considering how important the public IP can be, we can use Elastic IP (EIP) to prevent it from changing. This AWS service allows us to request a pool of IP addresses that we want to have for ourselves to manage. You can find it in EC2 dashboard’s sidebar under Network & Security
.
Pricing
AWS offers a free tier so for the first EIP per instance we only have to pay the “inactivity” fee. Meaning, EIP will cost you money only if it’s assigned to an instance which is stopped or unattached. In the example below, we defined a scenario in which the Elastic IP address is assigned to an EC2 instance fo 730 hours or the entire month. That EC2 instance will also be inactive/stopped for 365 hours.
For each subsequent EIP we will have to pay for using it as well, at the same rate as when the EC2 instance is stopped.
Just by increasing the number of EIP per instance to two, the cost quadrupled. That is because we’re now being charged full price for the second IP address - when the EC2 instance is running. On top of it the amount of time EIPs are not being used (instance is stopped) has doubled due to increased number of addresses resulting in such drastic price change.