AWS Builder Center
Connecting Serverless to Private Networks: My Hands-On Experience with API Gateway & VPC Lattice

Connecting Serverless to Private Networks: My Hands-On Experience with API Gateway & VPC Lattice

A deep dive into how I combined Amazon API Gateway, AWS Lambda, and VPC Lattice to route traffic from the public internet to a private EC2 backend securely.

Aspiring AWS Cloud Engineer | AWS Core & Networking | Automation | Terraform (IaC) | Docker | CI/CD
n the world of AWS, we often build serverless applications (API Gateway + Lambda) and private backends (EC2 in a VPC). But how do you connect the two securely without exposing your backend to the public internet?
Recently, I spent time exploring Amazon API Gateway and AWS VPC Lattice to understand how these services work together for end-to-end request routing. Here is a breakdown of my hands-on journey.

The Building Blocks

Before jumping into the integration, I completed individual labs to understand the core concepts:
  • Amazon API Gateway: I built a Serverless API using API Gateway and Lambda. I also did a troubleshooting lab that taught me how Lambda Proxy Integration works and how critical Lambda invocation permissions (IAM) are.
  • AWS VPC Lattice: I built a VPC Lattice Service Network, configured listeners, target groups, and connected them to backend services. VPC Lattice acts as a private application networking layer, making it easy to connect services across VPCs.

The Real Challenge: End-to-End Integration

Reading theory is one thing, but connecting the dots is where the real learning happens. I decided to build an architecture where a public client could reach a private EC2 instance securely.
Here is the flow I built:  Client → API Gateway → Lambda → VPC Lattice → Target Group → EC2 Backend 

How I Solved the Connectivity Issues

This architecture sounds simple on paper, but it involved a few tricky networking challenges:
  1. Lambda VPC Connectivity: By default, Lambda functions run in an AWS-managed VPC and cannot access private resources. I had to configure the Lambda function to attach to my VPC's private subnets. This required creating the necessary IAM role permissions and network interfaces (ENIs).
  1. HTTPS via VPC Lattice: I wrote a simple script in Lambda to make an HTTPS request to the VPC Lattice service endpoint. This meant my EC2 backend needed Apache running with SSL/TLS enabled.
  1. Routing & Target Groups: I configured the VPC Lattice listener to route traffic to a Target Group, which then forwarded the request to the EC2 instance over HTTPS.

The Final Test:  curl  is Your Best Friend

After setting up the entire flow, I tested the API Gateway endpoint using  curl . Seeing a successful HTTP 200 response from the private EC2 backend after the request traveled through API Gateway, Lambda, and VPC Lattice was an amazing feeling.

Key Takeaways

  • Security by Design: This architecture allows you to expose a public API without making your backend EC2 instances public. They remain safely isolated in private subnets.
  • Cross-Layer Troubleshooting: When things don't work, you have to check Layer 7 (API Gateway mappings), Lambda VPC configs, Security Groups, and VPC Lattice routing rules.
  • Service Connectivity: VPC Lattice is a game-changer for application networking. It abstracts away the complexity of VPC Peering and complex routing tables.
If you are studying for your AWS Solutions Architect or just love building complex architectures, I highly recommend trying this setup. It bridges the gap between serverless computing and traditional networking!
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