Im in a similar boat to the user on this question; Connecting the elastic beanstalk environment with existing RDS instance
I have a Codestar project (Django via Beanstalk) and i cannot get the application to access any rds instances. When attempting to deploy during the testing step (python manage.py test
) the following error message is thrown;
django.db.utils.OperationalError: could not connect to server: Connection timed out
Is the server running on host "172.31.44.126" and accepting
TCP/IP connections on port 5432?
Things ive already tried
- Running locally
works fine via django and psql
- using ipaddress and public hostname (name.key.eu-west-2.rds.amazonaws.com)
both work fine locally and provide the same error message when deploying
- Connecting to rds via the EC2 instance
This works fine connecting via local ip and name. Queries such as \d and \l return fine indincating the instance can see the database.
- Changing vpc / subnets
Both EC2 and rds instances are in the same vpc (only have one) and subnet (eu-west, availability group 2a)
- Spinning up an attached beanstalk rds instance
I have tried dedicated rds instances and a connected instance using the EBS tool and the application has been unable to connect to either.
Settings.py
if 'RDS_DB_NAME' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
else:
DATABASES = {
'default':
{
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'db_user',
'PASSWORD': 'db_pwd',
'HOST': 'db_host',
'PORT': '5432',
}
}