A NAT Server

Blog Posts

How to Make Long Running Temporary Tasks

How to make long running temporary tasks

2022-04-03
Read More

How to point a Route53 Record to a CloudFront Distribution

How to point a Route53 Record to a CloudFront Distribution in and not in the same AWS account...

2022-03-06
Read More

How To Get AWS Lambda To Run Binary Files

How to get AWS Lambda to run arbitrary binaries...

2022-03-05
Read More

A NAT Server

A NAT Server...

2022-02-06
Read More

A Serverless Relational Database

A Serverless Relational Database...

2021-12-26
Read More

Note: This was created for experimental purposes and should not be used in a production environment.

Why Build This?

AWS has NAT Gateways which are easy to set up in just a few clicks. This simplicity comes at a cost. AWS NAT Gateways have a significant cost depending on workload. At the time of writing AWS NAT Gateway cost $0.045 an hour. $0.045 * 730 hours = $32.85 a month. That is the cost of a NAT Gateway doing nothing a month. AWS also charges based on how much data goes through a NAT Gateway. According to their website there is $0.045 fee for data processed by the NAT Gateway. That includes data received by the NAT Gateway. This can result in unexpected high data transfer bills. Data transfer pricing gets very complicated. Having a NAT Gateway can result in you paying data transfer costs for data going through the NAT Gateway and then another cost for that same data to go through an Internet Gateway. Then you need to take into account the return traffic won't have a Internet Gateway cost but it will have a NAT Gateway data transfer cost. There is also almost no configurability of a NAT Gateway. This is why you may want a NAT Server. This example is a very basic example running on a very small EC2 instance.

The Solution

Design

Create a EC2 instance with the specs your use case needs and configure it with NAT. This effectively is the same thing as the NAT Gateway. The only difference is now you have more control over the settings. For example, if you wanted to configure port forwarding you can now configure that. If you do not need to send much traffic you can keep the instance type small. If you need to handle larger amounts of traffic you can increase the instance type.

Below is what you will see in the EC2 Console if you deploy the Terraform provided at the bottom of this page.
Servers

Below are the key details about the NAT Servers
NAT Server Details

Below are the key details about the Test Servers
Test Server Details

Below is a traceroute from the Test Server. You can see the traffic go to the NAT Server and then to the internet.
Test Server TraceRoute

The Terraform source code which can deploy this configuration can be found here: https://github.com/Craigspaz/AWSNATServer