EC2 Network Tunnel

0

How can I tunnel the requests from my EC2 to another machine (my local machine to develop or the Kubernetes cluster where the controller of the service running on EC2 will be executed)?

On the EC2 machine is running a slave that performs some actions that cause a network request to a server. The objective is to catch the response that carries some information that cannot be obtained in any other way than by intercepting the response

On the master program hosted on Kubernetes or a local instance for developing purposes there's a mitmproxy (https://mitmproxy.org/) that listens to localhost:<proxy-port>, where the traffic of the EC2 instance should be intercepted

1 Answer
1

For local development, you could use something as simple as an SSH tunnel to proxy requests to your local machine for development purposes. OpenSSH has this feature built in and there's some useful documentation at https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Tunnels that explains how it works. If you don't want to expose SSH on your EC2 instance to the outside world, you could also use SSH with Session Manager to connect to your instance (see https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started-enable-ssh-connections.html for more information), or even the new EC2 Instance Connect endpoint feature (https://aws.amazon.com/blogs/compute/secure-connectivity-from-public-to-private-introducing-ec2-instance-connect-endpoint-june-13-2023/).

For a more permanent set up, you'll need to enable some kind of long-lived connectivity between your EC2 instance and then thing you want to proxy connections to. If it's an K8s/EKS instance running inside the same VPC, then it should be possible to create an Ingress in Kubernetes and then make requests to it. If it's not in the same VPC then you need to consider how you might build that connectivity. It could be public internet, it could be via a VPN/Direct Connect.

profile pictureAWS
AndrewB
answered 10 months ago
profile picture
EXPERT
reviewed 10 months ago
profile pictureAWS
EXPERT
kentrad
reviewed 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions