AWS Elastic IPs are permanently reserved IP addresses that you can associate with a running EC2 instance, and that persist across reboots and even server changes, so you won’t have to change your DNS whenever your server restarts.
What Are Elastic IPs? How Much Do They Cost?
AWS can’t assign a static reserved IP address to every running EC2 instance. Instead, the machine’s public IP address is, by default, temporary. When you turn the machine off, that address is available for others to use, and you won’t have the same IP when you turn it back on.
This can be a problem, because if you link your domain name to the public IP, your domain name will break whenever you restart your server. You shouldn’t have to change your DNS on every restart, so the solution is an Elastic IP address, which never changes.
When you can associate the Elastic IP to a machine, the public IP for that machine is replaced by the Elastic one. The associated address is attached to the instance itself; If the instance turns off, the elastic IP stays where it is, and reattaches to the instance when it turns back on. If you need to upgrade, switch, or replace your server, you can reassociate the address to a new instance, hence Elastic IP. But, it achieves the same effect as having a static IP address for your server.
Elastic IP is a free service, but you’re limited to five in total (to prevent exhaustion of Amazon’s address pool). And, while they are entirely free to use, they’re actually the only AWS service that costs money if you don’t use it—having an Elastic IP provisioned but not attached to a running machine will cost you $7.50 a month. Make sure your machine isn’t off for extended periods of time, and if you change servers or stop using the IP, make sure to release it so you aren’t charged for letting it sit idle in your account.
If you’re using AWS Load Balancers, you won’t want to use Elastic IPs, as your gateway address (the last endpoint before going out to the internet) is be the Load Balancer itself, which has a static hostname (but not a static IP). The load balancer runs on AWS, and you associate it with instances based on their instance IDs, not the public IP address. But, if you’re using an external CDN service like Fastly, you need to use Elastic IPs, as the gateway IP is the EC2 instance’s public IP.
How to Provision an Elastic IP
Elastic IPs are provisioned just like any other AWS service. You can find them in the EC2 Management Console, under the “Elastic IPs” tab:
Create a new address with the “Allocate new address” button. You can provision an address in Amazon’s address pool (they own all of
184.108.40.206/8, so it’s in that block) or, if you own your own IPv4 block, you can actually use your own address space on AWS.
That’s all that’s required to create an Elastic IP address, but you also need to associate the address with a running instance. Right click the address in the list, and click “Associate Address.” You’ll be asked for the instance ID or network interface of the instance you want to assign the address to.
Associating the Elastic IP will detach the current public IP, so you must switch everything to this new IP.
Working with Elastic IPs from the Command Line
You can allocate a new address with:
aws ec2 allocate-address
Release addresses with:
aws ec2 release-address [allocation-id]
And, list your currently used addresses with:
aws ec2 describe-addresses
If you want to get the allocation ID to associate the address with an instance, pipe it to
aws ec2 describe-addresses | jq '.Addresses.AllocationId'
And, use the
associate-address command to link it:
aws ec2 associate-address \ --allocation-id [string] \ --instance-id [string]
For further information, you can consult the CLI command reference.