Subscribe
AWS

Deleting a non-production NAT gateway, and when to put one back

We deleted a two-AZ regional NAT gateway in non-production to save money, then added one zonal NAT back three weeks later. The costs on both sides, what one AZ gives up, and a Terraform nat_mode switch for none, zonal or regional.

Deleting a non-production NAT gateway, and when to put one back

On 28 October we deleted the NAT gateway in our non-production VPC. On 18 November we added one back. That sounds like a wasted three weeks, but the one we added is not the one we deleted, and the bill is lower than before either way: $42.53 a month, as part of the 31% bill cut.

In this blog we will look at both changes, the costs on each side, and the small Terraform switch that lets one network module do all three shapes. Prices are Mumbai (ap-south-1), from the AWS price list on 30 November 2026, before GST.

What the NAT was costing

The non-production VPC (stage and SIT, seven small Fargate services) had a regional NAT gateway. A regional NAT is the newer kind: one gateway for the whole VPC, and AWS adds addresses in the AZs where you have workloads. Billing is per AZ it is active in. Ours was active in two.

In Mumbai a NAT gateway hour is $0.056, regional or zonal, and so is each GB it processes. Two AZs is $0.112 an hour, about $82 a month before a single byte goes through it. With data and its two addresses, the review put it at about $97 a month. For seven services whose CPU averaged close to 0%, that was quite a lot.

And all seven tasks already had public IPs. They paid for an address and for the NAT, and only used the NAT.

Deleting it

The plan was simple: move the seven services to the VPC's public subnets, keep their public IPs, let them go out through the internet gateway, then delete the NAT. Security groups still blocked inbound traffic, so having a public IP did not open anything.

We moved the services first and checked they were running and passing health checks. Then the NAT went. The private route tables were left with no default route at all, which is fine as long as nothing runs in those subnets.

In Terraform that became a new option on the network module: nat_mode = "none". The module already handled a zonal NAT for production and a regional one for non-production; "none" just means no gateway and no default route for the private subnets.

The saving was real, but smaller than NAT's price. Seven tasks with public IPs at $0.005 an hour each is $25.55 a month, and that stayed.

Putting one back

On 18 November, three weeks after the delete, we put a NAT back. Not the same kind, though.

Why would you want a NAT in non-production at all, once it's working without one? There are a few reasons you might, and they're worth weighing before you delete yours.

If production runs in private subnets behind a NAT (ours does), a non-production setup without one stops being a good test of production networking. Something that works on a public task in SIT proves quite little about the private one in production. A wrong security group rule on a public task is also a bigger mistake than the same rule on a private one.

Then there's the egress IP. With public IPs on tasks, every new task gets a new outbound address. Third parties that allowlist your calls can't work with that. A NAT gateway gives you one Elastic IP that stays the same.

And the public IPs aren't free. In our case seven of them were $25.55 a month, which ate into what the delete saved.

What we added was a single zonal NAT gateway in one AZ (ap-south-1a), pointed both private route tables at it, and moved all seven services back to private subnets with assignPublicIp=DISABLED. That's $0.056 an hour, about $40.88 a month, plus $3.65 for its Elastic IP and $0.056 for each GB. Half the regional NAT's hourly cost, since it lives in one AZ only.

What one AZ gives up

A zonal NAT lives in one AZ. If ap-south-1a has a bad day, tasks in ap-south-1b lose outbound internet too, even though their own AZ is fine. For production I would not do this. For stage and SIT? It's acceptable. Nobody's paying customers sit on SIT.

There's also a small charge you may not notice: traffic from tasks in the other AZ crosses an AZ boundary to reach the NAT, and cross-AZ traffic is billed per GB. For our volume it's noise. If your non-production pulls big images or datasets often, put an S3 gateway endpoint on the private route tables (it's free) so ECR's image layers don't go through the NAT at all. Our module already has one.

Here is how I'd decide, roughly:

Setup Monthly fixed cost (Mumbai) Per GB out Egress IP
No NAT, public IPs on 7 tasks $25.55 none (internet gateway) changes with every task
Zonal NAT, one AZ $40.88 + $3.65 $0.056 one, fixed
Regional NAT, two AZs $81.76 + addresses $0.056 per AZ, managed by AWS

If nothing outside allowlists you and the services are few, the first row is cheapest. That's actually where we were for three weeks. Once a fixed egress IP matters, the zonal row wins for non-production.

The Terraform switch

This is a trimmed version of the module, enough to show the switch. It takes existing subnets and route tables as inputs so you can drop it next to whatever builds your VPC:

variable "nat_mode" {
  description = "\"none\", \"zonal\" (one NAT gateway in the first AZ) or \"regional\"."
  type        = string
  default     = "zonal"

  validation {
    condition     = contains(["none", "zonal", "regional"], var.nat_mode)
    error_message = "nat_mode must be \"none\", \"zonal\" or \"regional\"."
  }
}
locals {
  first_az = sort(keys(var.public_subnet_ids))[0]
}

# Zonal: one classic NAT gateway with its own Elastic IP, in the first AZ.
resource "aws_eip" "nat" {
  count  = var.nat_mode == "zonal" ? 1 : 0
  domain = "vpc"
  tags   = { Name = "${var.name}-nat-${local.first_az}" }
}

resource "aws_nat_gateway" "zonal" {
  count         = var.nat_mode == "zonal" ? 1 : 0
  allocation_id = aws_eip.nat[0].id
  subnet_id     = var.public_subnet_ids[local.first_az]
  tags          = { Name = "${var.name}-nat-${local.first_az}" }
}

# Regional: one gateway for the whole VPC, billed per AZ it is active in.
resource "aws_nat_gateway" "regional" {
  count             = var.nat_mode == "regional" ? 1 : 0
  availability_mode = "regional"
  connectivity_type = "public"
  vpc_id            = var.vpc_id
  tags              = { Name = "${var.name}-regional-nat" }
}

locals {
  nat_gateway_id = {
    none     = null
    zonal    = one(aws_nat_gateway.zonal[*].id)
    regional = one(aws_nat_gateway.regional[*].id)
  }[var.nat_mode]
}

# Every private route table gets the same default route, or none at all.
resource "aws_route" "private_default" {
  for_each = var.nat_mode == "none" ? {} : var.private_route_table_ids

  route_table_id         = each.value
  destination_cidr_block = "0.0.0.0/0"
  nat_gateway_id         = local.nat_gateway_id
}

The map lookup with one() keeps the rest of the module from caring which shape is in use. The routes use for_each over a map keyed by AZ, so switching from "none" to "zonal" just adds two routes and doesn't touch anything else.

Calling it for non-production:

module "network" {
  source = "../network"

  name   = "sit"
  vpc_id = "vpc-0123456789abcdef0"
  public_subnet_ids = {
    "ap-south-1a" = "subnet-0aaa1111aaaa1111a"
    "ap-south-1b" = "subnet-0bbb2222bbbb2222b"
  }
  private_route_table_ids = {
    "ap-south-1a" = "rtb-0aaa1111aaaa1111a"
    "ap-south-1b" = "rtb-0bbb2222bbbb2222b"
  }
  nat_mode = "zonal"
}

I checked this with terraform validate on Terraform 1.17.1 and AWS provider 6.74.0, and checked that nat_mode = "bogus" fails on the validation rule. A word on the regional block: in our real module, on provider 6.56, a few regional NAT arguments (like which route table hosts it) were read-only. Importing the existing gateway worked fine, but creating a fresh one would not fully converge without a CLI step. Check your provider's changelog before relying on the regional path for a new VPC.

The order on the day was the same both times: change live AWS first, one service at a time, then sync Terraform until the plan shows nothing. If you go the other way and apply first, the services get moved in one shot, and with a NAT being deleted in the same apply, the tasks can lose their route before they lose their private subnet. I'd rather do that slowly, one service at a time itself.

If NAT gateways and route tables are new to you, Building a VPC by hand goes through them step by step. And the public IPv4 post has the checks to run before moving a service into a private subnet, including the third-party allowlists.