All posts

Development Teams: VPC Private Subnet Proxy Deployment

Virtual Private Cloud (VPC) configurations are pivotal for securely managing your cloud architecture. A common challenge for development teams is securely enabling resources in private subnets to access the internet—whether for software updates, API calls, or communicating with external services. Enter the concept of deploying a proxy within a private subnet, a solution that ensures connectivity without compromising security. In this blog post, we’ll walk through the why and how of deploying a

Free White Paper

Database Proxy (ProxySQL, PgBouncer) + GCP VPC Service Controls: The Complete Guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free. No spam. Unsubscribe anytime.

Virtual Private Cloud (VPC) configurations are pivotal for securely managing your cloud architecture. A common challenge for development teams is securely enabling resources in private subnets to access the internet—whether for software updates, API calls, or communicating with external services. Enter the concept of deploying a proxy within a private subnet, a solution that ensures connectivity without compromising security.

In this blog post, we’ll walk through the why and how of deploying a proxy in a VPC private subnet. By the end, you’ll have a clear understanding and actionable steps to implement this setup. Let’s solve the connectivity and security challenges of private subnets effectively.


Why Deploy a Proxy in a Private Subnet?

When resources are confined to a private subnet, they have no direct internet access. While this prevents unauthorized incoming connections, it also blocks outbound traffic. For example, an application hosted in your private subnet won’t be able to fetch updates or communicate with external APIs.

A proxy acts as an intermediary—handling outgoing traffic by routing it through a managed service or NAT gateway while keeping the resources within the private subnet hidden from the public internet. This setup brings multiple advantages:

  1. Security: Sensitive resources remain inaccessible from the open internet.
  2. Logging and Monitoring: Proxies can log requests, enabling better observability and tracking.
  3. Centralized Control: Rules for outgoing traffic can be enforced from a single point rather than across individual resources.
  4. Cost Optimization: In specific setups, using a proxy for handling requests can reduce data transfer costs compared to NAT gateways alone.

Components of a VPC Private Subnet Proxy Deployment

To deploy a proxy in your private subnet, you will need a clear understanding of the architecture and dependencies involved. The setup typically includes:

  • VPC with Private Subnets: A private subnet ensures resources are isolated and have no public IPs.
  • Proxy Server: Acts as the intermediary for requests. This could be a lightweight forward proxy (e.g., Squid, Envoy) or a managed service.
  • NAT Gateway or Transit Gateway: Ensures the proxy can forward traffic to the internet.
  • IAM Roles and Policies: Manage permissions for accessing AWS resources securely.
  • Route Tables: Direct traffic between the private subnet and the proxy/NAT gateway.

Each of these components plays a critical role in ensuring visibility, security, and compliance when connecting private resources to the outside world.


Step-by-Step: Deploying a Proxy in a Private Subnet

1. Create a VPC with Private Subnets

Begin by creating a VPC with at least one private subnet. Ensure the private subnet lacks an internet gateway attachment, keeping the resources inaccessible from the public internet.

Continue reading? Get the full guide.

Database Proxy (ProxySQL, PgBouncer) + GCP VPC Service Controls: Architecture Patterns & Best Practices

Free. No spam. Unsubscribe anytime.
aws ec2 create-vpc --cidr-block 10.0.0.0/16
aws ec2 create-subnet --vpc-id <VPC_ID> --cidr-block 10.0.1.0/24 # Private Subnet

2. Set Up a Proxy Instance

Deploy an instance within your private subnet to act as the proxy. Install and configure proxy software of your choice. For example, using Squid:

sudo apt update
sudo apt install -y squid
sudo vi /etc/squid/squid.conf

Customize the configuration file to allow your specified outbound requests and networks.

3. Attach a NAT Gateway

Deploy a NAT gateway with its respective Elastic IP address to handle outgoing traffic. Associate the NAT gateway with the route table attached to your private subnet.

aws ec2 create-nat-gateway --subnet-id <SUBNET_ID> --allocation-id <EIP_ID>

Update the route table to route all non-local traffic to the NAT gateway:

aws ec2 create-route --route-table-id <ROUTE_TABLE_ID> --destination-cidr-block 0.0.0.0/0 --gateway-id <NAT_GATEWAY_ID>

4. Configure Route Table for Proxy

Ensure the route table associated with the private subnet points traffic to the proxy for specified ports and services.

5. Test the Setup

SSH into a resource inside the private subnet and test the outgoing connection through the proxy:

curl -x http://<PROXY_IP>:3128 http://example.com

Logs on the proxy server should confirm successful forwarding.


Tips for Managing and Scaling Your Proxy

Once deployed, management and scaling are critical for sustaining performance and reliability. Consider these points:

  • Scaling: Use Auto Scaling Groups if traffic volume grows. Place the proxy behind a load balancer for redundancy.
  • Monitoring: Use AWS CloudWatch to monitor performance and set up alerts for unusual patterns.
  • Security: Limit access using AWS VPC Security Groups and implement role-based access for administrators and developers.
  • Automated Updates: Ensure the proxy software remains updated to close vulnerabilities.

Conclusion

Deploying a proxy server within a VPC private subnet offers a robust solution for managing secure outbound internet access. It bridges the gap between maintaining strict resource isolation and enabling external communication. Whether you're working with third-party APIs, fetching updates, or connecting with remote services, this setup balances security, control, and flexibility.

Want to implement this in minutes instead of hours? See how Hoop.dev simplifies your private subnet proxy deployment today. Skip the manual headaches and get started now!

Get started

See hoop.dev in action

One gateway for every database, container, and AI agent. Deploy in minutes.

Get a demoMore posts