Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use SSH tunnel to make Django server think it's running inside AWS?

How can you make your local Django development server think it's running inside your AWS network using SSH tunneling?

My scenario, I'm running a local Django server i.e. python manage.py runserver and Redis as cache backend (Elasticache). When my app runs in the AWS environment it has access to Elasticache, but, Locally it won't (and that's a good thing). If for some reason I want to test my local environment with Elasticache I need to somehow use SSH tunneling to make AWS think it's running inside the VPC network.

I've tried to get this working by using below. I've confirmed I can connect locally using SSH tunneling with Redis Desktop Manager so 100% I know AWS supports this, my problem is now doing the same thing with Django.

This is what I've tried:

> python manage.py runserver 8000
> ssh -i mykey.pem [email protected] -L 6379:localhost:6379

I get the message "Error 60 connecting to" message when I visit http://127.0.0.1:8000/.

What I'm I doing wrong here?

Notes:

  • [email protected] is not the Redis server, just another EC2 instance on AWS that has access Elasticache that I want to use as a tunnel.
  • The mykey.pem has access and the correct permission.
  • The ec2 instance has all the correct permissions and ports for access.
  • Tested SSH tunneling with Redis Desktop Manager and this works for that software.
  • Elasticache and the EC2 instances are all in the same region and can connect to each other.
like image 364
Prometheus Avatar asked Oct 19 '22 13:10

Prometheus


1 Answers

ssh -i mykey.pem [email protected] -L 6379:localhost:6379

This will forward requests from your local machine (on :6379) to localhost:6379 on the EC2 instance. This is not what you want (unless you have redis running locally on the EC2 instance)

You should use the Elasticache IP instead

ssh -i mykey.pem [email protected] -L 6379:<elasticache-ip>:6379
like image 164
Kedar Avatar answered Oct 28 '22 16:10

Kedar