Reduce your AWS elastic IP costs from an AWS EC2 in stopped or terminated state

Published on August 21, 2018
Share this on

An Elastic IP (EIP) address doesn’t incur charges as long as the following conditions are true:

  • The Elastic IP address is associated with an EC2 instance.
  • The instance associated with the Elastic IP address is running.
  • The instance has only one Elastic IP address attached to it.

While stopped instances do not incur costs on EC2, the EBS volume and EIP end up accruing your cost which can be avoided by eliminating the use of EIP and bringing up your EC2 from a snapshot rather than from an EBS.

If an instance is terminated or in a stopped state it means a fee is paid for that EIP.

In order to eliminate costs for an EIP you can:

  • Remove any extra EIP that is not being used in any AWS resource or in DNS. That is done by releasing the address. Go to EC2 dashboard then select Elastic IPs and pick the desired IP then click Release address and Release;How to release Elastic IP

Many times you may have an EC2 instance that is infrequently stopped, started state from a command line script or a batch script that does an SSH to a fixed IP address, and one uses an EIP for this purpose. In such situations rather than incurring charges associated with an EIP waiting for the EC2 to start up, you can script the start-stop script to discover the current IP address assigned to your EC2 when the instance is running. Below is a way to do this:

First stop the instance for which you have the instance_id from AWS:

> aws ec2 stop-instances –instance-ids {instance_id}  && aws ec2 wait instance-stopped –instance-ids {instance_id}

Start the instance and without EIP you will most likely get a new IP address:

> aws ec2 start-instances –instance-ids {instance_id} && aws ec2 wait instance-running –instance-ids {instance_id}

Query to ensure the instance has started:

> aws ec2 describe-instances –instance-ids {instance_id}  –query “Reservations[0].Instances[0].State.Name”

If the instance is in running state query the current PublicIPAddress via command line:

> aws ec2 describe-instances –instance-ids {instance_id}  –query “Reservations[*].Instances[*].PublicIpAddress”

Then you can SSH to that new IP address assigned with your private keys:

> ‘ssh -i {your_private_key} ubuntu@{Your_new_IP}

Yet, another option is to have instances behind an ELB/ALB this way EIPs are not needed.

The use cases for requiring elastic IPs are rather limited:

  1. You have a service where customers need a fixed IP rather than a hostname.
  2. You are hosting a non-HTTP service and you are using a Network Load Balancer.
  3. You are hosting a UDP service which cannot be load-balanced using native Amazon services.
  4. You need a NAT gateway for a private subnet.

Many times you can reduce your costs from a start-stop type EC2 operation, where your EBS and EIP are billed while the EC2 is stopped by switching to a T class system or by bringing up your EC2 from a snapshot rather than from EBS.

Many times you can reduce your costs from a start-stop type EC2 operation, where your EBS and EIP are billed while the EC2 is stopped by switching to a T class system or by bringing up your EC2 from a snapshot rather than from EBS.

If you encounter issues in the process of removing an elastic IP from a stopped EC2 instance or have a question about any of our AWS Tutorials, please reach out to us with a comment and will add this to the FAQs. If you would like to partner with us and develop AWS open source scripts for these kinds of steps, reach out to us.

Download the whitepaper that explains why cloud capacity planning needs a different thought process from traditional on-premise infrastructure.

We wont spam you or sell your email address

Learn more