cost: eliminate NAT gateways by running Fargate tasks in public subnets#28
Open
jesserockz wants to merge 1 commit into
Open
cost: eliminate NAT gateways by running Fargate tasks in public subnets#28jesserockz wants to merge 1 commit into
jesserockz wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NAT gateways account for ~$74/month (~63% of our total AWS bill) despite serving a single low-traffic Fargate task. This PR eliminates them by moving Fargate tasks to public subnets with a public IP, while keeping the ALB as the sole ingress point.
Changes
New
public_taskvariable on thewebservicemodulefalseby default — existing behaviour is fully preserved for any service that needs to stay in a private subnettrue: task is placed in public subnets withassign_public_ip = true, and the container security group is tightened to accept inbound traffic from the ALB security group only (replacing the previous0.0.0.0/0rule)New
enable_nat_gatewayvariable on theinfrastructure/regionmoduletrueby default — NAT gateways, EIPs, and private route table routes are still created unless explicitly disabledfalsefor this deployment sinceservice-hub-botsis the only service and is switching topublic_task = trueservice_hub_botspublic_task = trueCost impact
Security considerations
The Fargate task will have a public IP assigned by AWS. It is not directly reachable from the internet in practice — the container security group only permits inbound traffic on port 5000 from the ALB security group. All external traffic continues to enter through the ALB on port 443.
Alternatives considered
fck-nat): ~$3/month, but adds EC2 operational overheadRollback
Set
enable_nat_gateway = trueandpublic_task = falsein the relevant workspaces and re-apply. No data is at risk — subnets and route tables are recreated cleanly by Terraform.