Problem description: Elastic IPs are free of charge only in certain cases
Let’s start with identifying two types of IP addresses that can be assigned to Amazon EC2 instances – private and public ones. Private IP addresses are responsible for the communication between internal AWS services and resources in a single VPC, whereas public ones can be additionally attached to instances to establish external connections and enable the communication with the Internet. These public IPv4 IP addresses are called Elastic IP addresses (EIP). The great advantage of using this type of an IP address lies in a simple remapping of this IP to a different machine if that’s required. From the outside point of view, there will be no difference for the end-users, they will still use the existing public IP.
To assign an EIP to an AWS instance you need to allocate it first. In general, Elastic IP addresses are free of charge, but only in case of the following rules are applied:
- EIP is assigned to an EC2 instance
- The instance is running
- The instance has only one EIP attached
- EIP remapping is limited to 100 times per month
However, if the Elastic IP doesn’t meet one of the rules mentioned above, you will be charged at the following rates:
- $0.005 per additional Elastic IP address associated with a running instance per hour on a pro rata basis
- $0.005 per Elastic IP address not associated with a running instance per hour on a pro rata basis
- $0.10 per Elastic IP address remap for additional remaps over 100 per month
Keeping an eye on all active cloud resources is not an easy task, hence, to get your resources organized and manageable, we highly recommend tagging them. Discover the rules, appropriate to your team, and tag all the resources, including EIP addresses to minimize the chance of losing them.
How to release EIPs
Before releasing an elastic IP, check that this address is not associated with any AWS resources such as an EC2 instance, NAT gateway, or Network Load Balancer, otherwise, you will not be able to release it.
From AWS console:
Go to the EC2 service and click on Elastic IPs in the left menu to observe the addresses of the specific region.
To release the IP, simply select it in the list, click on Actions → Release Elastic IP addresses
From AWS CLI:
A programmatic way to operate the resources delivers much wider capabilities – here you have a choice whether you want to release a specific IP or find all unused ones and remove them at once.
Depending on AWS EC2 platform that you use to launch the instances, select an appropriate command to find and release EIP in all regions:
EC2-Classic
aws ec2 describe-addresses --query 'Addresses[].[PublicIp,AssociationId]' --output text | \ awk '$2 == "None" { print $1 }' | \ xargs -I {} aws ec2 release-address --public-ip {}
EC2-VPC
aws ec2 describe-addresses --query 'Addresses[].[AllocationId,AssociationId]' --output text | \ awk '$2 == "None" { print $1 }' | \ xargs -I {} aws ec2 release-address --allocation-id {}
aws ec2 release-address --public-ip
command to release a specific elastic IP otherwise you must use aws ec2 release-address --allocation-id eipalloc-76f5890b
Find our recent article ‘How to tag resources in the AWS Management Console’ here → https://hystax.com/how-to-tag-resources-in-the-aws-management-console