Optimizing AWS Costs: Uncovering Unused Elastic IPs with a Simple Bash Script

Chetan Bothra
3 min readSep 7, 2024

AI Generated Image

Introduction

As a DevOps engineer, one of our key responsibilities is to manage infrastructure efficiently while keeping an eye on costs. AWS provides a powerful and flexible cloud environment, but with that power comes the potential for unexpected expenses if resources are not managed carefully. One such often-overlooked resource is the Elastic IP (EIP).

Elastic IPs are static, public IP addresses that you can allocate to your AWS account, and they remain associated with your account until you explicitly release them. However, when an EIP is allocated but not in use, AWS charges for it — an unnecessary cost that can add up over time, especially in large, multi-region environments.

The Hidden Cost of Unused Elastic IPs

In our day-to-day operations, we often focus on optimizing resources like EC2 instances, storage, and network traffic. But it’s easy to forget about the smaller details — like unused Elastic IPs — that can quietly contribute to your AWS bill. Since AWS charges for every unused EIP, identifying and releasing them is a simple yet effective way to cut costs.

But how do you ensure that no unused EIP is overlooked, especially when managing multiple regions? This is where a well-crafted script can make all the difference.

Introducing the Elastic IP Management Script

To help streamline the process of identifying unused Elastic IPs across all AWS regions, I’ve developed a simple yet powerful bash script. This script not only counts the total number of EIPs in each region but also identifies which of them are currently unused. With this script, you can quickly pinpoint potential cost savings and take action before those charges add up.

The Script: A DevOps Engineer’s Ally

Here’s a breakdown of how the script works:

  1. Setting Up the Environment: The script starts by setting up your AWS CLI profile and specifying a default region. This ensures that the script can run smoothly even if no default region is set on your machine.
  2. Fetching All Regions: It then retrieves a list of all available AWS regions, ensuring that no region is missed.
  3. Evaluating Elastic IPs: For each region, the script fetches the list of Elastic IPs and evaluates whether each IP is associated with an EC2 instance or a network interface. If an EIP is found to be unassociated (unused), it’s flagged for potential removal.
  4. Summarizing the Findings: Finally, the script provides a summary of all the Elastic IPs found across your AWS account, along with a specific count of those that are unused.

Here’s the script in its entirety:

Conclusion: A Small Step for Cost Efficiency

By identifying and releasing unused Elastic IPs, you can take a small but meaningful step toward optimizing your AWS costs. As DevOps engineers, our role is not just to keep the systems running but also to ensure that they run efficiently — both technically and financially. This script is a simple yet effective tool to help you do just that.

Remember, in cloud environments, every dollar counts. So, let’s keep an eye on those hidden costs and ensure that our resources are being used wisely. Happy optimizing!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Chetan Bothra
Chetan Bothra

Written by Chetan Bothra

AWS Certified | GCP | DevOps | SRE | Docker | DevSecOps | Kubernetes | Automation | Terraform | Serverless | Blockchain

No responses yet

Write a response