I created a new EC2 Instance with Postgres on RDS. I confirmed that I can connect from the EC2 instance to the database using psql without any issue which means my security settings are fine.
However, when I try to run manage.py runserver
or manage.py dbshell
(from the virtualenv) Django hangs then eventually gives a timeout error:
psql: could not connect to server: Connection timed out Is the server running on host "whatever.rds.amazonaws.com" (172.xxx.xxx.xxx) and accepting TCP/IP connections on port 5342?
Traceback (most recent call last): File "manage.py", line 22, in execute_from_command_line(sys.argv) File "/home/ubuntu/Env/xxxx/lib/python3.5/site-packages/django/core/management/init.py", line 363, in execute_from_command_line utility.execute()
File "/home/ubuntu/Env/ss2017/lib/python3.5/site-packages/django/core/management/init.py", line 355, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ubuntu/Env/ss2017/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv self.execute(*args, **cmd_options)
File "/home/ubuntu/Env/ss2017/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute output = self.handle(*args, **options)
File "/home/ubuntu/Env/ss2017/lib/python3.5/site-packages/django/core/management/commands/dbshell.py", line 22, in handle connection.client.runshell()
File "/home/ubuntu/Env/ss2017/lib/python3.5/site-packages/django/db/backends/postgresql/client.py", line 66, in runshell DatabaseClient.runshell_db(self.connection.get_connection_params())
File "/home/ubuntu/Env/ss2017/lib/python3.5/site-packages/django/db/backends/postgresql/client.py", line 58, in runshell_db subprocess.check_call(args)
File "/usr/lib/python3.5/subprocess.py", line 581, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['psql', '-U', 'db_name', '-h', 'whatever.rds.amazonaws.com', '-p', '5342', 'user_name']' returned non-zero exit status 2
I tried creating a new copy of the Django app to see if there were perhaps corrupt files involved, and I played with some changes to my settings.py
file, but no luck.
Any ideas?
Edit:
Settings.py (the important bits)
DEBUG = False
ALLOWED_HOSTS = ['localhost', '0.0.0.0', '127.0.0.1', 'compute.amazonaws.com']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database_name',
'USER': 'xxxxxxxx',
'PASSWORD': 'xxxxxxxx',
'HOST': 'whatever.us-west-2.rds.amazonaws.com',
'PORT': '5342',
}
}
psql -U db_name -h something.rds.amazonaws.com -p 5432 user name
from the EC2 CLI connects with no issues? - gold_cyos.environ.setdefault("DJANGO_SETTINGS", "settings")
in yourmanage.py
file? also have you tried changing the host tolocalhost
- gold_cy