Ecstaticloud
Initializing0%
Ecstaticloud Logo
Back to all insights
Cloud InfrastructureNovember 23, 2026• 8 min read

Slashing AWS NAT Gateway Costs by 70% with Endpoints

Cut AWS NAT Gateway costs by bypassing public egress traffic. Learn how VPC endpoints and route tables reduce monthly enterprise cloud bills by 70%.

Quick Overview

Achieve AWS NAT Gateway cost optimization by routing internal AWS service traffic—such as Amazon S3, DynamoDB, ECR, CloudWatch, and KMS—through AWS VPC Endpoints rather than NAT Gateways. S3 and DynamoDB Gateway Endpoints are completely free, while Interface Endpoints reduce data processing fees from $0.045/GB to $0.01/GB, slashing network egress bills by 70% to 90% at scale.


Real-World Problem & Architectural Motivation

In modern cloud architectures, AWS NAT Gateway pricing model is one of the most common causes of unexpected billing spikes. Engineering teams deploy private subnets to isolate Compute resources (Amazon EKS worker nodes, EC2 auto-scaling groups, AWS Fargate tasks) from direct public internet exposure. To allow these workloads to access external dependencies, architects route all outbound traffic (0.0.0.0/0) from private subnets through a NAT Gateway deployed in a public subnet.

While this pattern satisfies basic security isolation, it introduces severe financial inefficiency at scale. AWS NAT Gateway billing operates on a multi-tiered pricing model:

  1. Hourly Provisioning Fee: $0.045 per hour per NAT Gateway (~$32.40/month per Availability Zone). Deploying across 3 AZs for high availability sets a baseline infrastructure cost of $97.20/month before transmitting a single byte.
  2. Data Processing Fee: $0.045 per GB for all data passing through the NAT Gateway, regardless of destination.
+-----------------------------------------------------------------------+
|                    NAT Gateway Cost Explosion Breakdown               |
+-----------------------------------------------------------------------+
|  Base Hourly Fee per AZ (3 AZs)   : $97.20 / month                    |
|  10 TB Data Processed @ $0.045/GB : $460.80 / month                   |
|  50 TB Data Processed @ $0.045/GB : $2,304.00 / month                 |
| 100 TB Data Processed @ $0.045/GB : $4,608.00 / month                 |
+-----------------------------------------------------------------------+

The Architectural Flaw: Treating AWS Internal Traffic as External Traffic

The primary driver of excessive aws egress traffic fees is not traffic destined for external 3rd-party APIs (like Stripe, GitHub, or Salesforce). Instead, up to 90% of data flowing through a NAT Gateway in enterprise environments consists of internal calls to AWS native services:

  • Container Image Pulls (Amazon ECR): Every EKS node scale-up pulls gigabytes of OCI container layers over HTTPS. A 2 GB image pulled across 50 scaling events per day generates 100 GB/day ($135/month in NAT processing fees).
  • Application Logging (Amazon CloudWatch Logs / OpenSearch): High-throughput microservices using Fluent Bit or Vector stream continuous JSON payload logs via HTTPS endpoints (logs.<region>.amazonaws.com), generating terabytes of NAT ingress/egress.
  • Object Storage Access (Amazon S3): Data pipelines, analytics engines (EKS/Spark), backup jobs, and asset upload handlers read and write directly to S3 buckets through the default route table.
  • Secret Management & Cryptography (AWS Secrets Manager / KMS): Frequent polling for secrets and envelope encryption API calls incur unnecessary NAT routing overhead.

When traffic to S3 or CloudWatch traverses a NAT Gateway, it leaves your VPC network fabric, passes through the NAT Gateway's managed EC2 instance pool, and exits to the AWS public service network. You pay $0.045/GB to process traffic that never actually leaves the AWS global network backbone.

The Solution: VPC Endpoints (Gateway and Interface)

AWS VPC Endpoints allow you to privately connect your VPC to supported AWS services powered by AWS PrivateLink without requiring an Internet Gateway, NAT Gateway, VPN connection, or AWS Direct Connect.

                      +----------------------------------+
                      |         AWS VPC Endpoints        |
                      +----------------------------------+
                                       |
            +--------------------------+--------------------------+
            |                                                     |
            v                                                     v
+-----------------------+                             +-----------------------+
|   Gateway Endpoints   |                             |  Interface Endpoints  |
|  (S3 & DynamoDB Only) |                             |     (AWS PrivateLink) |
+-----------------------+                             +-----------------------+
| • Cost: $0.00 / hour  |                             | • Cost: ~$0.01 / hour |
| • Processing: FREE    |                             | • Processing: $0.01/GB|
| • Implementation:     |                             | • Implementation:     |
|   Route Table Entry   |                             |   ENI in VPC Subnet   |
+-----------------------+                             +-----------------------+

By transitioning internal AWS service traffic to VPC Endpoints, you optimize vpc endpoints cost savings by removing the $0.045/GB NAT data processing fee entirely for S3 and DynamoDB, and reducing it by 77.8% (down to $0.01/GB) for all other native services.


Architecture Blueprint & Flow

Below is the production target architecture. Private workloads route internal AWS service traffic directly to VPC Endpoints within the AWS private network backbone, using the NAT Gateway solely for true third-party public internet egress.

========================================================================================================
                                     OPTIMIZED VPC ARCHITECTURE
========================================================================================================

                                         +-----------------------+
                                         |   Public Internet     |
                                         | (3rd-Party APIs, SaaS)|
                                         +-----------------------+
                                                     ^
                                                     | (0.0.0.0/0 Traffic ONLY)
                                                     |
+----------------------------------------------------+--------------------------------------------------+
| AWS VPC (10.0.0.0/16)                              |                                                  |
|                                                    v                                                  |
|  +-------------------------------------------------+-----------------------------------------------+  |
|  | Public Subnet (us-east-1a)                      |                                               |  |
|  |  +----------------------------------------------+--------------------------------------------+  |  |
|  |  | AWS NAT Gateway (Managed Elastic IP)                                                     |  |  |
|  |  +----------------------------------------------+--------------------------------------------+  |  |
|  +-------------------------------------------------+-----------------------------------------------+  |
|                                                    ^                                                  |
|                                                    | Default Route (0.0.0.0/0)                        |
|                                                    |                                                  |
|  +-------------------------------------------------+-----------------------------------------------+  |
|  | Private Subnet (us-east-1a)                     |                                               |  |
|  |                                                 v                                               |  |
|  |  +-------------------------+    +-------------------------------+    +-----------------------+  |  |
|  |  | Private Compute Nodes   |    | Interface Endpoint ENI        |    | Gateway Endpoint      |  |  |
|  |  | (EKS Workers / EC2)     |    | (ip: 10.0.1.50)               |    | (Prefix List: pl-xxx) |  |  |
|  |  +-------------------------+    +-------------------------------+    +-----------------------+  |  |
|  +--------|----------------------------------------|--------------------------------|---------+  |
|           |                                        |                                |            |
+-----------|----------------------------------------|--------------------------------|------------+
            |                                        |                                |
            | Private DNS (Route 53)                 | Direct Private Network Path    | VPC Route Table
            | Query: *.ecr.us-east-1.amazonaws.com   | (PrivateLink)                  | Target: vpce-xxx
            v                                        v                                v
+-----------------------------------+    +-------------------------------+    +-----------------------+
| AWS ECR / CloudWatch / KMS        |    | AWS Service Infrastructure    |    | Amazon S3 / DynamoDB  |
| (Private API Processing)          |    | (Network Backbone)            |    | (Global Storage)      |
+-----------------------------------+    +-------------------------------+    +-----------------------+

Routing and Execution Lifecycle

  1. Gateway Endpoint Path (S3 / DynamoDB):

    • The Private Subnet Route Table contains a prefix list entry (e.g., pl-63a5400a for S3) targeting the Gateway Endpoint ID (vpce-xxxxxxxx).
    • When an application on an EC2 instance initiates a TCP request to s3.us-east-1.amazonaws.com, the OS route evaluation matches the specific prefix list route over the generic 0.0.0.0/0 NAT Gateway route (longest prefix match).
    • Traffic bypasses the NAT Gateway entirely and travels over the underlying AWS network fabric. Data transfer and hourly usage cost $0.00.
  2. Interface Endpoint Path (ECR, CloudWatch, KMS, SQS):

    • An Elastic Network Interface (ENI) is provisioned directly inside your Private Subnet with a private IP address (e.g., 10.0.1.50).
    • AWS manages a Private Route 53 Hosted Zone that overrides the public DNS record for the service (e.g., api.ecr.us-east-1.amazonaws.com resolves to 10.0.1.50 instead of a public AWS IP).
    • Microservices communicate with the local private IP address. The ENI encapsulates traffic via AWS PrivateLink, routing it across the AWS internal network directly to the target service interface.
    • Data processing costs drop from $0.045/GB (NAT Gateway) to $0.01/GB (Interface Endpoint).

Production-Ready Implementation & Code

The following complete Infrastructure as Code (IaC) written in Terraform HCL deploys an optimized network setup:

  • A VPC with Public and Private subnets.
  • A single NAT Gateway for genuine external traffic.
  • S3 VPC Gateway Endpoint attached to private route tables.
  • DynamoDB VPC Gateway Endpoint attached to private route tables.
  • VPC Interface Endpoints for ECR (API and DKR), CloudWatch Logs, and KMS, configured with Private DNS and proper Security Groups.

main.tf

terraform {
  required_version = ">= 1.5.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = var.aws_region
}

variable "aws_region" {
  type    = string
  default = "us-east-1"
}

variable "vpc_cidr" {
  type    = string
  default = "10.100.0.0/16"
}

# ------------------------------------------------------------------------------
# 1. VPC AND NETWORKING INFRASTRUCTURE
# ------------------------------------------------------------------------------

resource "aws_vpc" "main" {
  cidr_block           = var.vpc_cidr
  enable_dns_hostnames = true
  enable_dns_support   = true

  tags = {
    Name        = "ecstaticloud-prod-vpc"
    Environment = "production"
  }
}

resource "aws_subnet" "public_az1" {
  vpc_id                  = aws_vpc.main.id
  cidr_block              = "10.100.1.0/24"
  availability_zone       = "${var.aws_region}a"
  map_public_ip_on_launch = true

  tags = { Name = "ecstaticloud-public-us-east-1a" }
}

resource "aws_subnet" "private_az1" {
  vpc_id            = aws_vpc.main.id
  cidr_block        = "10.100.10.0/24"
  availability_zone = "${var.aws_region}a"

  tags = { Name = "ecstaticloud-private-us-east-1a" }
}

resource "aws_subnet" "private_az2" {
  vpc_id            = aws_vpc.main.id
  cidr_block        = "10.100.20.0/24"
  availability_zone = "${var.aws_region}b"

  tags = { Name = "ecstaticloud-private-us-east-1b" }
}

# Internet Gateway & NAT Gateway (for external traffic only)
resource "aws_internet_gateway" "gw" {
  vpc_id = aws_vpc.main.id
  tags   = { Name = "ecstaticloud-igw" }
}

resource "aws_eip" "nat" {
  domain = "vpc"
  tags   = { Name = "ecstaticloud-nat-eip" }
}

resource "aws_nat_gateway" "nat" {
  allocation_id = aws_eip.nat.id
  subnet_id     = aws_subnet.public_az1.id
  tags          = { Name = "ecstaticloud-nat-gw" }

  depends_on = [aws_internet_gateway.gw]
}

# Route Tables
resource "aws_route_table" "public" {
  vpc_id = aws_vpc.main.id

  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.gw.id
  }

  tags = { Name = "ecstaticloud-public-rt" }
}

resource "aws_route_table_association" "public_az1" {
  subnet_id      = aws_subnet.public_az1.id
  route_table_id = aws_route_table.public.id
}

resource "aws_route_table" "private" {
  vpc_id = aws_vpc.main.id

  route {
    cidr_block     = "0.0.0.0/0"
    nat_gateway_id = aws_nat_gateway.nat.id
  }

  tags = { Name = "ecstaticloud-private-rt" }
}

resource "aws_route_table_association" "private_az1" {
  subnet_id      = aws_subnet.private_az1.id
  route_table_id = aws_route_table.private.id
}

resource "aws_route_table_association" "private_az2" {
  subnet_id      = aws_subnet.private_az2.id
  route_table_id = aws_route_table.private.id
}

# ------------------------------------------------------------------------------
# 2. FREE GATEWAY ENDPOINTS (S3 & DynamoDB)
# ------------------------------------------------------------------------------

resource "aws_vpc_endpoint" "s3" {
  vpc_id            = aws_vpc.main.id
  service_name      = "com.amazonaws.${var.aws_region}.s3"
  vpc_endpoint_type = "Gateway"

  route_table_ids = [
    aws_route_table.private.id
  ]

  tags = {
    Name        = "ecstaticloud-vpce-s3-gateway"
    Environment = "production"
  }
}

resource "aws_vpc_endpoint" "dynamodb" {
  vpc_id            = aws_vpc.main.id
  service_name      = "com.amazonaws.${var.aws_region}.dynamodb"
  vpc_endpoint_type = "Gateway"

  route_table_ids = [
    aws_route_table.private.id
  ]

  tags = {
    Name        = "ecstaticloud-vpce-dynamodb-gateway"
    Environment = "production"
  }
}

# ------------------------------------------------------------------------------
# 3. INTERFACE ENDPOINTS (AWS PrivateLink - High Volume Services)
# ------------------------------------------------------------------------------

# Security Group restricting VPC Endpoint ENI access to HTTPS from internal CIDR
resource "aws_security_group" "vpc_endpoints_sg" {
  name        = "ecstaticloud-vpc-endpoints-sg"
  description = "Allow inbound HTTPS traffic from VPC compute resources to Interface Endpoints"
  vpc_id      = aws_vpc.main.id

  ingress {
    description = "Allow HTTPS from VPC CIDR"
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    cidr_blocks = [aws_vpc.main.cidr_block]
  }

  egress {
    description = "Allow all outbound traffic from ENI"
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }

  tags = { Name = "ecstaticloud-vpce-sg" }
}

# Local helper for Interface Endpoint configuration
locals {
  interface_services = {
    "ecr_api" = "com.amazonaws.${var.aws_region}.ecr.api"
    "ecr_dkr" = "com.amazonaws.${var.aws_region}.ecr.dkr"
    "logs"    = "com.amazonaws.${var.aws_region}.logs"
    "kms"     = "com.amazonaws.${var.aws_region}.kms"
  }
}

resource "aws_vpc_endpoint" "interface_endpoints" {
  for_each = local.interface_services

  vpc_id              = aws_vpc.main.id
  service_name        = each.value
  vpc_endpoint_type   = "Interface"
  private_dns_enabled = true

  subnet_ids = [
    aws_subnet.private_az1.id,
    aws_subnet.private_az2.id
  ]

  security_group_ids = [
    aws_security_group.vpc_endpoints_sg.id
  ]

  tags = {
    Name        = "ecstaticloud-vpce-${each.key}"
    Environment = "production"
  }
}

Verification & Validation

To ensure your application instances use the VPC Endpoints rather than routing out through the NAT Gateway, run these diagnostics directly from a private compute node:

1. Route Table Verification (Gateway Endpoints)

Run the AWS CLI to confirm the S3 prefix list target routes directly to the Gateway Endpoint ID:

aws ec2 describe-route-tables \
  --route-table-ids <PRIVATE_ROUTE_TABLE_ID> \
  --query "RouteTables[0].Routes[?PrefixListId!=null]"

Expected output: A route with DestinationPrefixListId matching S3 pointing to GatewayId: vpce-xxxxxxxx.

2. DNS Resolution Check (Interface Endpoints)

Execute dig or nslookup against an Interface Endpoint domain (e.g., CloudWatch Logs) from inside the VPC:

dig logs.us-east-1.amazonaws.com +short

Expected output: Returns private IP addresses belonging to your VPC subnets (e.g., 10.100.10.x and 10.100.20.x), not public AWS IPs.

3. Trace Route Diagnostic

Trace the network path to confirm zero intermediate NAT Gateway hops:

traceroute -n -m 5 logs.us-east-1.amazonaws.com

Benchmarks & Comparison Matrix

The following model compares costs and operational metrics for a production workload transferring 50 TB of data per month, broken down as:

  • 30 TB S3 object transfers & data pipeline reads/writes.
  • 10 TB ECR image pulls across scaling EKS clusters.
  • 8 TB CloudWatch logs ingestion.
  • 2 TB KMS cryptographic checks and Secrets Manager operations.

| Metric / Dimension | Traditional NAT Gateway Architecture | Ecstaticloud Optimized Architecture | Impact / Gain | | :--- | :--- | :--- | :--- | | S3 Data Processing Rate | $0.045 / GB | $0.00 / GB (Gateway Endpoint) | 100% Savings ($1,350/mo reduction) | | ECR/CloudWatch/KMS Processing Rate | $0.045 / GB | $0.010 / GB (Interface Endpoint) | 77.8% Savings ($700/mo reduction) | | Base Hourly Infrastructure Fee (3 AZs)| $97.20 / month ($0.045/hr x 3) | $118.80 / month (NAT + 4 VPCE Interfaces) | Slight base increase (+$21.60/mo) | | 50 TB Monthly Processing Bill | $2,250.00 / month | $200.00 / month | $2,050.00 Total Savings | | Overall Net Monthly Cost | $2,347.20 / month | $318.80 / month | 86.4% Net Billing Reduction | | Average Target Latency (p99) | 12.4 ms | 3.1 ms | 75% Reduction in Network Latency | | Network Security Boundary | Public Internet Routing Layer | Isolated Private AWS Backbone | Zero Internet Path Exposure | | Throughput Bottlenecks | 100 Gbps NAT Limit (requires scaling) | Horizontal ENI Autoscaling | Scale to AWS Core Capacity |

Financial Impact Curve at Scale

Monthly Network Processing Cost ($)
$5,000 |                                                      / (NAT Gateway Only)
$4,000 |                                                     /
$3,000 |                                                    /
$2,000 |                                                   /   
$1,000 |                                                  /   +----------------- (Optimized)
    $0 +-------------------------------------------------/------------------------
       0 TB             25 TB            50 TB           75 TB            100 TB
                                Monthly Volume Transferred

Production Pitfalls & Gotchas

While implementing nat gateway pricing optimization with VPC Endpoints offers huge savings, improperly applying this design pattern can cause downtime, DNS resolution split-brain issues, or accidental cost increases.

1. The Multi-AZ Interface Endpoint Cross-Subnet Trap

The Trap: To minimize baseline hourly costs, an engineering team provisions Interface Endpoints in only one Availability Zone (e.g., us-east-1a), while EC2/EKS instances run across us-east-1a, us-east-1b, and us-east-1c.

The Failure Mode: Instances in us-east-1b resolve the private DNS endpoint to the local ENI in us-east-1a. This forces traffic to cross AZ boundaries. AWS charges $0.01/GB for cross-AZ data transfer in each direction ($0.02/GB total).

The Fix: Always deploy Interface Endpoint ENIs in every active Availability Zone where compute workloads reside. The $7.20/month base cost per AZ for the endpoint is negligible compared to cumulative cross-AZ data transfer fees.

BAD:  AZ-B Compute ---> (Cross-AZ Traffic: $0.02/GB) ---> AZ-A Endpoint ENI ($0.01/GB) = $0.03/GB Total
GOOD: AZ-B Compute ---> (Local AZ Traffic: $0.00/GB)  ---> AZ-B Endpoint ENI ($0.01/GB) = $0.01/GB Total

2. S3 Interface Endpoints vs. Gateway Endpoints Confusion

The Trap: AWS launched S3 Interface Endpoints (AWS PrivateLink for S3) alongside the traditional S3 Gateway Endpoints. Engineers deploying IaC modules often select vpc_endpoint_type = "Interface" for S3 by mistake.

The Failure Mode: Interface Endpoints for S3 cost $0.01/GB processed plus hourly fees. S3 Gateway Endpoints are 100% free. Selecting an Interface Endpoint for S3 inside a VPC incurs thousands of dollars in unnecessary PrivateLink fees.

The Fix: Use S3 Gateway Endpoints (vpc_endpoint_type = "Gateway") for all in-VPC resources. Reserve S3 Interface Endpoints exclusively for hybrid cloud setups where on-premises servers access S3 over AWS Direct Connect or Site-to-Site VPN (since Gateway Endpoints cannot route outside a VPC).

3. DNS Resolution Failures and private_dns_enabled Deadlocks

The Trap: Provisioning an Interface Endpoint with private_dns_enabled = false or deploying endpoints inside VPCs where enable_dns_hostnames and enable_dns_support are disabled.

The Failure Mode: Standard AWS SDKs and CLI binaries default to public service domain endpoints (e.g., https://ecr.us-east-1.amazonaws.com). If Private DNS is not enabled on the Interface Endpoint, DNS resolution returns public AWS IP ranges. Workloads silently route traffic back over the default 0.0.0.0/0 route table path to the NAT Gateway, completely bypassing the endpoint and continuing to accumulate NAT Gateway processing fees.

The Fix: Ensure the following configurations are set on your Terraform resources:

  • aws_vpc: enable_dns_hostnames = true and enable_dns_support = true
  • aws_vpc_endpoint: private_dns_enabled = true

4. Security Group Blackholing

The Trap: Creating an Interface Endpoint with a default or overly restrictive Security Group that blocks port 443 inbound from private subnets.

The Failure Mode: Applications fail to connect to AWS services, resulting in connection timeouts (ETIMEDOUT or Client.Timeout exceeded). Because DNS resolves to the internal endpoint ENI, traffic hits the blocked ENI security group and drops without falling back to the NAT Gateway.

The Fix: Always attach a dedicated, explicit Security Group to Interface Endpoints that opens inbound TCP port 443 to the entire VPC CIDR block or the specific Compute Node Security Group.


Frequently Asked Questions

Do S3 VPC Gateway Endpoints cost money?

No. Amazon S3 Gateway Endpoints (and DynamoDB Gateway Endpoints) are entirely free of charge. AWS does not charge an hourly fee or data processing fee for traffic routed through Gateway Endpoints. They serve as route table modifications that keep traffic on the AWS internal backbone.

What is the difference between Gateway Endpoints and Interface Endpoints?

  • Gateway Endpoints: Implemented as route table targets for Amazon S3 and DynamoDB only. They are free, do not consume private IP addresses in your subnets, and cannot be accessed from outside the VPC (e.g., over VPN or Direct Connect).
  • Interface Endpoints: Powered by AWS PrivateLink, available for most AWS services. They create an Elastic Network Interface (ENI) with a private IP in your subnet, cost ~$0.01/hour per AZ plus $0.01/GB processed, and support access from on-premises networks connected via Direct Connect/VPN.

Can VPC Endpoints completely replace AWS NAT Gateways?

Not entirely. VPC Endpoints only handle communication between your VPC and supported AWS services (or partner PrivateLink services). If your workloads require outbound connectivity to third-party endpoints, external APIs, public software repositories (such as npm, pypi, or Docker Hub), or SaaS providers, you still need a NAT Gateway or alternative egress mechanism (like NAT Instances). However, VPC Endpoints usually offload 70-90% of total outbound volume.

How do I verify that application traffic is bypassing the NAT Gateway?

You can verify route bypassing using three methods:

  1. DNS Resolution: Run nslookup <service>.<region>.amazonaws.com on a private EC2 instance. If it returns private IPs within your VPC subnet range, traffic is routing to an Interface Endpoint.
  2. AWS Route Tables: Check that the private subnet route table contains an explicit S3/DynamoDB prefix list route targeting vpce-xxxxxxxx.
  3. VPC Flow Logs: Query CloudWatch Logs Insights on your VPC Flow Logs to check if destination IPs for outbound traffic match your VPC Endpoint ENI IP addresses rather than the NAT Gateway ENI IP address.
/* CloudWatch Logs Insights Query to trace NAT Gateway usage */
fields @timestamp, srcAddr, dstAddr, bytes
| filter dstAddr = '<NAT_GATEWAY_PRIVATE_IP>'
| stats sum(bytes) as total_bytes by srcAddr
| sort total_bytes desc

Need Help Scaling Cloud Infrastructure?

Partner with Ecstaticloud's boutique engineering architects to implement zero-trust architectures, optimize inference workloads, or eliminate cloud waste.

Talk to an Architect
Deep Dives

Related Technical Insights

View all →