Need help setting up architecture to reach a developer's machine from an EC2 instance, via a peering connection and VPN Client

, , ,

Claude just sent me down a 2-hour rabbit hole of nonsense, hoping a kind human here can help me out.

I have the following network setup:

  • VPC A contains an EC2 instance.

  • VPC B contains an AWS Client VPN endpoint.

  • VPC A and VPC B are peered. I have set up routing and security rules such that a VPN user can reach instances in VPC A from the client endpoint in VPC B.

I’d like to be able to set up the reverse of above. In other words, I want an instance in VPC A to be able to send requests to a developer’s machine that is connected via the AWS VPN client. Is this possible to do?


Related discussions:

RSD/PostgreSQL migration without downtime
VPCs and IAM
Some Elastic Load Balancing Questions
Easy question for you all on this lovely Friday! ACL/Security Groups/VPC related.
Microsoft Failover clustering in AWS?
Lambda Functions in VPC: Cold Boot Times of 10+ Seconds Every Other Invocation
Can an on premise server talk to an S3 endpoint in a VPC? VPN / Direct Connect? Is an AWS proxy required?
What does 0.0.0.0/0 means?
AWS VPN continuously going down
Dynamic routing between VPC?
VPC Dropping isakmp packets?
Virtual Private Gateway route selection w/ multiple VPNs
I would like to run an instance without a public IP
Can Amazon Systems Manager (SSM) agent be forced to communicate only through VPN or Direct Connect ?
Migration of office LAN services to AWS
what repo/source does EMR ami use to install apps?
Active Directory service without VPN or DX
Fault-tolerant OpenVPN in AWS
iBGP Inter-AZ Full Mesh
Is there a feed for AWS feature releases more granular than the announcement or blog pages?
Any using Transit Gateway or planning to very soon?
Palo Alto static route tunnel to vpc
Stoked about the new AWS Quick Start for Jira
Build a cheaper, more flexible VPN solution on AWS with our open-source OpenVPN Certificate Authority
AWS VPN Internet Access
Can someone please explain how subnetting works in AWS
Best "under the hood" re:Invent sessions?
Why would I want my Amazon RDS instance to be publicly accessible?
How can I access a private API gateway locally?
Security Group, VPC Security Group and network ACLs
Separate VPC's can do More Harm Than Good
VPC Traffic Mirroring – Capture & Inspect Network Traffic
How to identify all external entry points on AWS account for penn testing?
AWS VPN with MFA (OTP)
Is there a standard way to design VPC architecture diagrams?
Workspaces vs EC2 for Dental Software
One large VPC with lots of smaller subnets VS lots of smaller VPC
Amazon FSx file share - multi-region
ECS task cannot resolve hostnames
Resources inside and outside of VPC
AWS Route Selection
AWS Site-to-Site VPN now supports Internet Key Exchange (IKE) initiation (It's about freaking time!)
Transit Gateway with SSM?
How private is the traffic within for example VPC or within a single subnet?
Multi-account with AWS Organization + VPN server access to multiple VPC/regions: best practices?
Getting Started with Terraform in Business
Cheaper Lambda w/ EIP Option Than NatGateway
VPC Subnet routing not making sense
Just can't decide on best multi account structure. Help
Alternatives to AWS VPN?
Allow only a certain Azure tenant access to S3 blob
unable to pull ECR image
How do I enable internet access to an EC2 instance in public subnet without public IP address?
Does VPC peering compromise security?
What Exactly are VPC Endpoints and Why They Need Real Inter-Region Support (2022-03-01)
AWS VPN Client - any way around the horrible autofocus-on-connect?
Networking - Is it ok to use a network range for my VPC that does not fall into the reserved private ranges?
Cannot resolve RDS Instance Endpoint name with AWS-Client-VPN - Only IP addresses
Amazon VPC Lattice now GA!
How to scale RDS beyond one writer/reader instance?
Using CDK and integrating with existing non CDK infrastructure?
Working implementation of AWS EKS + Cilium vxlan (no more pod limits, no more stuck pods/IP issues)
Multi-VPC ENI Attachments
Ipam in a multi account landing zone environment
Why is Amazon Route 53 Profiles so expensive?
Idea for Flux inference using AWS
is it ok if i delete the default vpc (and subnets, IG, etc)?
Best way to manage ec2 ssh access for teams
Centralised egress VPC with Palo Alto firewall
AWS site to site VPN using BGP without advertising RFC 1918 private IP addresses of my vpc subnet.
How can I workaround VPC that are using valid public addresses for the private addressing
Enhancing VPC Security with Amazon VPC Block Public Access
Advice on Infrastructure as Code
Transit VPC
Requesting to associate an IP with a VPC server, within that server
VPC and security groups: why go with private subnets?
AWS Architecture question from a noob...
AWS default VPC setup question

ummmm… ever hear of `ngrok` ?

  1. Set routing tables in VPC B for:
    destination VPC A, target VPC peering
  2. Set routing tables in VPC A to forward traffic to the VPN’s Client CIDR block

What do you have there already?
can you reach something in VPC B?

Thanks for the polite and productive comment

Just to lay things out here is your layout:

Developer Laptop ↔ Client VPN ↔ Client VPN Endpoint ↔ VPC B ↔ Peering ↔ VPC A ↔ EC2

You have correctly configured communication so that the developer laptop can reach the EC2. But you want the EC2 to be able to reach the Developer laptop.

Your issue is that the Client VPN uses Static NAT / PAT on the Endpoint which means that client traffic is mapped to the IP address of it’s interface. There is no where to point traffic because there is no consistent mapping for traffic. It works from the laptop because NAT rewrites the proper ports creating mappings, but you have no way to create those mappings with traffic from the EC2.

Outside client VPN it might be possible to use NAT traversal to discover and use those mappings but the timeouts in AWS Client VPN are very tight and tied to state so it’s not possible to do this.

Is this possible to do?

No. You’ll need to ensure any solution you design has the developer laptop performing the establishment of the session. You can not establish the connection from the EC2.

It’s not possible with Client VPN, but if OP wants AWS-native tools they could install the SSM Agent on the developer machine. That will keep a connection with AWS open, and they could then configure IAM policies allowing the EC2 instances to send commands to the developer machine or open port forwardings to it.

Given OPs request, I’m assuming public routing is disabled entirely or otherwise restricted

Try Tailscale

Reverse connectivity from EC2 to a VPN-connected client is possible but requires the client to advertise its route back through the endpoint. The peering alone doesn’t handle that direction without additional routing config on the client side.

The Client VPN does SNAT, that make it works with VPC peering. because VPC peering is non transitive. The developer machine IP is not visible from the EC2 instance, so the EC2 instance can not initiate communication to the developer machine.

One way to avoid SNAT is by attaching the Client VPN to Transit Gateway instead, but it requires change to your architecture.

You might honestly get a better solution if you describe the problem you’re trying to solve more holistically. This solution smells like an anti pattern and you can probably get solid advice for how to implement a solution but you end up with a less brittle or convoluted system if you describe your problem and not the solution that you see to your problem.

Eg it might be 100 times easier to have the other computer publish to sns and you subscribe to it. It might also be way easier and more pragmatic to move the workload off the developers machine and into ec2 if you’re gonna use that anyway but no one here can answer that for you because you’ve omitted all the relevant information

Sure! This is just a POC so brittleness is not a major concern, at least no now.

One of our developers has a machine in her house where she has exposed a REST API. Let’s just say that keeping this API on her machine is a hard constraint, as I don’t want to give away too much business info. We want to send requests to this API from our EC2 instances.

The network architecture has been mapped out accurately by /u/mrbiggbrain

Interesting, can you please expand on this? Or shoot over some documentation?

This would be my suggestion as well.

Makes sense if it’s a hard constraint but if it was my team I’d probably still push for deploying to lambda to make sure the app wasn’t jacked up because the developer was mid feature implantation or their computer was sleeping or all the other issues that come with that setup but to each their own

Here is the announcement artcile for SSM Port Forwarding:

https://aws.amazon.com/blogs/aws/new-port-forwarding-using-aws-system-manager-sessions-manager/

Use NGrok on the developer machine.

https://ngrok.com

Usually AWS Client VPN isn’t designed for inbound connections from VPC resources to client devices, which is why it feels like a dead end. Instead of fighting routing rules, you can just expose your local service securely using a tunnel like Pinggy or cf tunnel. It flips the flow so your EC2 can reach your machine without complex network gymnastics.

Ended up doing this. So easy! This is blowing my mind! Thank you!

Yes, it’s possible, but the important detail is that AWS Client VPN is primarily designed for client-to-VPC access, not VPC-to-client initiated connectivity. The return path and routing are what usually trip people up.

The cleanest approach is:

  • Ensure the developer laptop gets an IP from the Client VPN CIDR
  • In VPC A, add a route for the Client VPN CIDR pointing through the peering connection to VPC B
  • In VPC B, the route table associated with the Client VPN subnet must route the client CIDR correctly
  • The developer machine’s local firewall must allow inbound traffic from VPC A

The big gotcha is that many laptops will drop inbound connections even if routing is correct. Windows Defender Firewall, macOS PF, corporate endpoint agents, etc. are often the actual blocker.

Also note AWS Client VPN does not support true transitive routing. Peering works here because traffic is still between VPC A and the VPN endpoint VPC, but you need explicit routes on both sides.

I’d test incrementally:

  1. EC2 in VPC B → developer machine
  2. Then EC2 in VPC A → developer machine across peering

If step 1 fails, it’s usually client firewall or missing Client VPN route authorization.