AWS Builder Center
I Thought Cloud Cost Optimisation Meant Spending Less. Then I Built a VPC.

I Thought Cloud Cost Optimisation Meant Spending Less. Then I Built a VPC.

DevOps Journey | AWS | Cloud Cost Optimisation | VPC | Economics

Introduction

When I started learning cloud cost optimisation, I thought the idea was simple: find the expensive resources, identify the ones you don't need, remove them, and pay less.
It's not that simple. Building the networking layer for my current project taught me that the hard way, starting with something as ordinary as a NAT gateway.
In my last post,  Learning AWS Cloud Cost Auditing From Scratch , I wrote about how my economics background kept resurfacing in unexpected ways as I learned AWS.
This post is about what happened when those same ideas, such as productive efficiency, allocative efficiency, and the risk-cost trade-off, met a real architecture decision instead of a hypothetical one.
I am currently at a point in my learning where I don't just want to build infrastructure because I can, or add services simply because they are available. I want to understand the decisions I make, what problems they solve, and the cost and value behind them.
So, when I remembered a suggestion about using VPC Endpoints to reduce NAT Gateway costs, I didn't immediately change my architecture. Instead, I stopped and asked a simple question:
Would this actually make sense for my architecture?
And that question took me much deeper than I expected.

The architecture I started with

Using Terraform, I built a VPC across two availability zones: public and private subnets in each, an EKS cluster and node group in the private subnets, and a NAT Gateway per AZ for outbound connectivity.
VPC
│
┌────────────────┴────────────────┐
│ │
Availability Zone 1 Availability Zone 2
│ │
Public Subnet Public Subnet
│ │
NAT Gateway 1 NAT Gateway 2
│ │
Private Subnet Private Subnet
│ │
EKS Nodes EKS Nodes

This reasoning felt obvious at the time: two AZs, two NAT gateways, which means better availability. Then a question I wouldn't have asked myself showed up: what does this decision actually cost, and is that cost justified by the value it provides? That's when my economics brain switched on.

The comment that started it

I was reading a LinkedIn thread a few weeks back where someone had shared their AWS architecture, and one of the comments suggested using VPC Endpoints as a way to reduce networking costs.
I didn't think too much about it at the time, but while building the networking layer for my project, I remembered that comment, and I began to look at it more deeply.
Would VPC Endpoints actually be beneficial for my architecture? Or would a NAT Gateway make more sense?
That simple question is why I have this blog to share today.

First: what problem does a NAT gateway actually solve?

Before deciding whether I needed a VPC Endpoint, I had to be honest about why the NAT Gateway existed in the first place.
My EKS nodes sit in private subnets intentionally and are not exposed to inbound internet traffic. But "private" doesn't mean "never talks outward." My workloads still need to pull:
  • Pull container images.
  • Reach AWS APIs.
  • Download packages.
  • Communicate with external services.
  • Send telemetry.
Private Workload
│
▼
Private Subnet
│
▼
NAT Gateway
│
▼
Internet / AWS Services
A NAT gateway gives private workloads a general-purpose outbound path: one door that leads everywhere.
Whereas a VPC Endpoint is different: it's a private, direct line to one specific AWS service. They're not interchangeable products competing for the same job. They solve different shapes of the same problem.

Then I Thought About Docker Images

In my project, I have multiple microservices.
For example:
  • API Gateway
  • Order Worker
  • Notifier
These applications will eventually be containerized. The Docker images will be stored in Amazon Elastic Container Registry (ECR). When my workloads run on EKS, the nodes need to retrieve those images.
Initially, I looked at it like this:
EKS Worker Node ──▶ Amazon ECR ──▶ Docker Image
The process involves different interactions:
  1. The node authenticates to ECR: This is an API call to the ECR service itself ( ecr:GetAuthorizationToken  ,  ecr:BatchCheckLayerAvailability ,  ecr:GetDownloadUrlForLayer ,  ecr:BatchGetImage ), typically over a regional AWS API endpoint.
  1. It then requests the image manifest from the ECR registry API.
  1. The actual image layers aren't served from the ECR API; they're stored in and pulled from Amazon S3, since ECR uses S3 as its blob store under the hood.
The worker node needs the image; the image is in ECR, and the node pulls the image. So a single  docker pull  is really at least two different AWS services, over two different network paths:
EKS Node
│
├──────▶ ECR API (auth + manifest)
│
└──────▶ S3 (actual image layers)
This is where the conversation became more interesting. If I wanted to use private connectivity for these services, I would not simply create one magical "ECR Endpoint." I would need to consider the different services involved.
For example, private ECR image pulls can involve separate Interface Endpoints for:
  •  ecr.api 
  •  ecr.dkr 
And because the image layers are retrieved through S3, I would also need to consider an S3 Gateway Endpoint.
That distinction matters because these endpoints do not all work or cost the same way. The ECR endpoints are Interface Endpoints, while S3 can use a Gateway Endpoint.
An S3 Gateway Endpoint does not have the hourly charges associated with Interface Endpoints.
Suddenly, replacing "the NAT Gateway" with "VPC Endpoints" was no longer one simple decision. It was becoming a per-service networking decision.

My Light Bulb Moment

This is where it became clearer:
Cloud cost optimization is not simply about choosing the cheapest architecture.
Because sometimes you are paying for:
  • Availability
  • Reliability
  • Security
  • Simplicity
  • Scalability
Initially, I was looking at the NAT Gateway and VPC Endpoint conversation mainly from one perspective: Which one costs less?
But architecture decisions are rarely that simple. A solution that appears cheaper on paper may introduce additional complexity or operational overhead. Another solution may cost more but provide better availability, reliability, or simplicity.
So the real question isn't always:
"Which option is cheaper?"
Sometimes, the better question is:
"What am I paying for, and is the value I'm getting worth the cost?"
I think this is where the economics concepts I wrote about in my previous blog started to become practical for me. The goal isn't simply to spend the least amount of money possible. It is to understand what the money is buying and whether that value justifies the cost.

So, What About My Two NAT Gateways?

At this point, I had to turn the question back to my own architecture.
I had created two NAT gateways, one in each availability zone.
Was that necessary? The honest answer is: it depends on what I am building for.
My original reasoning was straightforward. I was deploying my infrastructure across two Availability Zones, so having a NAT Gateway in each Availability Zone gave my workloads independent outbound connectivity.
Availability Zone 1 Availability Zone 2

Private Subnet Private Subnet
│ │
▼ ▼
NAT Gateway 1 NAT Gateway 2
│ │
▼ ▼
Internet / AWS Services Internet / AWS Services
If one Availability Zone has a problem, workloads in the other Availability Zone don't have to depend on a NAT Gateway located in the affected zone.
But there is, of course, a cost to that decision. Two NAT gateways cost more than one, and this is where I had to pause because
the fact that something costs more does not automatically make it a bad architecture decision.
I could reduce the cost by using a single NAT gateway, but then I would be making a different trade-off.
Availability Zone 1 Availability Zone 2

Private Subnet Private Subnet
│ │
└──────────────┐ │
│ │
▼ │
NAT Gateway │
│ │
▼ │
Internet / AWS Services
This approach reduces infrastructure costs, but it also means workloads across both Availability Zones depend on a single NAT Gateway for outbound connectivity.
There is also another networking consideration: workloads in one availability zone may need to send traffic across one availability zone to reach a NAT Gateway located in another AZ, which can introduce cross-AZ data transfer costs.
So the comparison isn't simply
One NAT Gateway = cheap Two NAT Gateways = expensive
The architecture with one NAT gateway may reduce one type of cost while introducing other trade-offs involving resilience and cross-AZ traffic. This was where the risk-cost trade-off became real to me. The second NAT Gateway costs more, but that additional cost is paying for something specific:
Higher availability and reduced dependency on a single Availability Zone for outbound connectivity.
So the question isn't simply:
"Why am I paying for two NAT Gateways?"
The better question is:
"What am I getting in return for paying for two NAT Gateways?"
And that brought me back to something I am beginning to understand more deeply about cloud architecture:
Every architecture decision has a cost. But every cost should also have a reason.

So, where does that leave VPC endpoints?

At this point, I understood something I hadn't considered when I first saw that LinkedIn comment.
Using a VPC Endpoint isn't as simple as replacing a NAT Gateway and suddenly paying less.
Let's go back to my Docker image example. My EKS nodes need to pull images from ECR. But when I looked more closely at what actually happens during that process, I realised that the traffic doesn't only involve ECR.
The node communicates with ECR for authentication and image information, while the actual image layers are retrieved from S3. That means if I wanted to reduce NAT Gateway traffic for image pulls using VPC Endpoints, I would need to consider the different services involved.
For example:
EKS Node
│
├──────▶ ecr.api
│
├──────▶ ecr.dkr
│
└──────▶ Amazon S3
And those services do not necessarily use the same type of VPC Endpoint or have the same pricing model.
The architecture was becoming more specific.
Instead of asking:
"Should I use a NAT Gateway or VPC Endpoints?"
I was beginning to ask:
"Where is my traffic actually going?"
Because that question changes everything.
If a significant amount of my private subnet traffic is going to AWS services such as ECR or S3, then it makes sense to investigate whether VPC Endpoints could reduce the amount of traffic going through the NAT Gateway.
But if my workloads need general access to the internet or services outside AWS such as:
  • Package repositories
  • Third-party APIs
  • External services
VPC Endpoints cannot replace the NAT Gateway. So, for me, this wasn't really an either/or decision. A NAT gateway gives my workloads a general route for outbound traffic. VPC Endpoints can provide private routes to specific AWS services. Depending on the workload, both can exist in the same architecture.
And honestly, I think that was the biggest misconception I had when I started looking into this.
I initially saw the conversation as
VPC Endpoint
OR
NAT Gateway
But it is more like
Private Workload
│
┌────────────┴────────────┐
│ │
▼ ▼
VPC Endpoint NAT Gateway
│ │
▼ ▼
Specific AWS Services Internet / Other Services
The question, therefore, is not necessarily which one should win.
The question is whether my workload has enough traffic going to specific AWS services to justify adding private endpoints alongside the NAT Gateway.
The answer may be different for different services. An S3 Gateway Endpoint, for example, has different cost characteristics from paid Interface Endpoints.
So even the question:
"Should I use VPC Endpoints?"
is probably too broad.
A better question is:
"Which services does my workload communicate with, and which of those services would benefit from private connectivity?"

Where I stopped myself

This was the point where I stopped. Not because VPC Endpoints were a bad idea, and not because I suddenly decided that NAT Gateways were cheaper.
I stopped because I began to understand the complexity behind the decision.
When I first saw that LinkedIn comment suggesting VPC Endpoints as a way to reduce NAT Gateway costs, the idea sounded straightforward:
identify the AWS services my workloads communicate with, add the appropriate endpoints, and reduce the amount of traffic going through the NAT Gateway.
But when I began tracing something as simple as pulling a Docker image, I realised that the decision wasn't that simple. The workload wasn't communicating with just one service. ECR image pulls involved different interactions, including ECR and S3, with different types of VPC Endpoints and different pricing models.
And then I had to ask myself another question:
Do I actually have enough evidence yet to justify adding this additional complexity to my architecture?
The honest answer is no. I haven't finished deploying the platform yet. I haven't observed real traffic patterns. I don't know how much traffic will actually pass through my NAT Gateways, and I don't yet know which destinations will account for most of that traffic.
So adding VPC Endpoints now simply because they might reduce costs would mean making another architecture decision based on assumptions, and that is where I stopped myself.
Because complexity has a cost too.
Not necessarily as a line item on an AWS bill, but in
  • engineering time,
  • configuration,
  • maintenance,
  • troubleshooting,
  • and operational overhead.
A more complex architecture can absolutely be worth it. But from a business perspective, I think the additional complexity should provide enough value to justify it. Right now, I don't have enough information to know whether it would.

What I will measure next

Once the platform is deployed, I plan to observe the traffic and costs generated by the environment during deployments, testing, and normal project activity. I also recognise that this is a personal project and that the traffic I generate will not represent a production workload with real users.
The data I collect will help me understand how this architecture behaves under controlled conditions, but it will not automatically justify a production recommendation.
The goal isn't to pretend that a personal project has production-scale traffic. It's to understand the relationship between architecture decisions, workload behaviour, and cost well enough to ask better questions.
I plan to look at:
  • How much traffic is passing through my NAT Gateways
  • The costs associated with that traffic
  • Which destinations account for a significant portion of the outbound traffic
  • How much of that traffic is going to AWS services that support VPC Endpoints
  • Whether the potential savings would justify the additional infrastructure and operational complexity
I can use tools such as:
  • Amazon CloudWatch for NAT Gateway metrics
  • AWS Cost Explorer to understand the costs associated with my infrastructure
  • VPC Flow Logs to investigate traffic patterns
I don't expect one metric to answer every question. The goal is to gradually build enough information to understand what is actually happening inside the architecture. Then I can make a more informed decision.

Where I am now

So, for now, my two NAT Gateways stay. This is not because I have concluded that they are the cheapest option or because I have concluded that VPC Endpoints aren't useful, but because I don't yet have the data required to justify changing the architecture.
Once the platform is deployed and carrying meaningful traffic, I can look at the actual usage and costs and then ask a more informed question:
Is the traffic passing through my NAT Gateways significant enough that introducing VPC Endpoints would provide more value than the additional complexity they introduce?
And I think that might be the most important lesson I have taken from this exercise.
Cloud cost optimisation is not about finding the cheapest architecture. It is about understanding what you are paying for, why you are paying for it, and whether the value you are getting justifies the cost.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article