Reducing Our AWS Public IP Usage

Reducing Our AWS Public IP Usage
Photo by Towfiqu barbhuiya / Unsplash

So like a lot of other small businesses we got our AWS bill at the end of March and were surprised by the cost of our Public IP usage. We knew we needed to do some cleanup of our usage but no one had done an actual count of the number of public IP’s that we have in use and forecast how much our bill would increase.

Needless to say this cost is now front of mind as we are working in our accounts and today I as was working on a few EC2 instances that are sitting behind an ALB and I noticed that they all had public ip addresses. These are some of our legacy servers, lift and shift from the data center so we don’t touch them very often. And since these instances were originally launched with public ip’s enabled we are kind of stuck as AWS does not allow you to just remove those public ip’s and rebuilding these EC2 instances is not a great option.

So after a bit of searching I found a solution, no to be honest it’s a little bit of a hack but it does work and it’s simple: Just add a 2nd NIC to the instance and this will disable the public ip.

Warning: This works for me because we have a VPN connection into AWS so I can SSH to instances via their private IP addresses. Make sure you’ve got a VPN, bastion host, session manager or some other way to connect to your servers prior to trying this.

Here’s my steps:

  1. Create a new NIC, I named it something descriptive so that future me doesn’t delete it. I added this new NIC to the same security groups as the existing NIC.
  2. Add the NIC to the EC2 instance.
  3. Stop the instance, this will release the Public IP.
  4. Start the instance and enjoy the cost savings.

It does appear that if you remove the 2nd NIC that the public IP will reattach. I’ve gone ahead and just left the NIC attached as it does not appear to be causing any issues and going to call it a day.