2

I'm hoping someone could help me out with some questions regarding VPC. I'm pretty new to AWS and I'm just trying to build a sample web app to get my feet wet with everything. I've been roughly following this guide to try and setup a basic project using Zappa + Django. I've gotten to the state where I'm configuring a VPC and trying to add a Postgres instance that Django/zappa can talk to. Per that article, I've setup up my network like this:

  • Internet Gateway attached to VPC
  • 4 Public subnets
  • 4 Private subnets
  • Lambda function in 2 of the private subnets
  • RDS with subnet group in other 2 private subnets
  • EC2 box in 1 public subnet that allows SSH from my local IP to forward port 5432 to RDS instance

My issue comes when I try and run migrations on my local machine using "python manage.py makemigrations". I keep getting an error that says "Is the server running on host "zappadbinstance.xxxxx.rds.amazonaws.com" (192.168.x.xxx) and accepting TCP/IP connections on port 5432?".

I'm not sure what step I'm missing. I followed this guide and this post to setup the bastion host, and I know it is working because I am able to (1) ssh from my terminal and (2) establish a database connection using PSequel on my local machine.

I feel like I'm really close but I must be missing something. Any help or pointers would be greatly appreciated.

cle_joe
  • 101
  • 1
  • 10
  • 1
    Can you post your Django and Zappa database settings? FWIW, I've never tried this method but have successfully run migrations from Zappa itself (e.g. `zappa manage dev migrate`), as well as from an EC2 instance inside the VPC. – Kevin Christopher Henry Aug 19 '18 at 03:26
  • 1
    I tried zappa manage dev migrate as well and got the same error. In my settings.py file I have the following configured under databases: 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'zappadb', 'USER': 'zappauser', 'PASSWORD': 'xxxxx', 'HOST': 'xxxxx.us-east-2.rds.amazonaws.com', 'PORT': '5432' In my zappa settings.json file I have the following for my vpc: "vpc_config" : { "SubnetIds": [ "subnet-07ddc89a2c33a1d65","subnet-0c038ee74b4456b75" ], "SecurityGroupIds": [ "sg-0dbe5b442c882c461" ] – cle_joe Aug 19 '18 at 04:32

1 Answers1

2

First, nice job on getting this set up - it's quite a challenge. I agree with you that you're almost there. Since you can connect with PSequel from your local system, that validates that your machine is accurately connected to the VPC RDS from a network perspective.

Next area to look at is the Django setup. If the local machine Django settings are incorrect, this would cause the error. So your database section in your settings file should be different on the local machine. As you describe in one of your comments above, I believe you have 'HOST': 'xxxxx.us-east-2.rds.amazonaws.com' When you run python manage.py makemigrations, django attempts to use that host name and connect to it. Unfortunately, this bypasses your carefully constructed ssh tunnel.

To fix this, you can either:

  1. Edit your local settings.py to have 'HOST':'127.0.0.1'
  2. Edit your /etc/hosts file to point to the FQDN above (but I wouldn't recommend this since often I forget to remove the edits)

Should be easy enough to try #1 above and see if that works.

Edgar
  • 1,174
  • 8
  • 9
  • WOW!!! Edgar I can't thank you enough. "django attempts to use that host name and connect to it" --- I'm not sure how I overlooked this but I think I was so busy focusing on the VPC setup that it just never occurred to me. Thank you so much for taking the time to read this and figure it out! – cle_joe Aug 21 '18 at 04:29