SSL connection error when connecting to MySQL RDS from Django

I am trying to deploy a Django application on Heroku with an RDS instance as the database. Everything works until I try to encrypt the connection, then I get this error:

OperationalError at /path/ (2026, 'SSL connection error') 

Here's the setting:

  • Django Standard Application
  • A MySQL RDS instance with a security group that allows connections from all IP addresses.
  • MySQL user configured to allow connections from any host
  • Amazon pem is loaded and specified in Django settings.

On Heroku:

 DATABASE_URL: mysql2://username: password@instance.us-east-1.rds.amazonaws.com :3306/name_staging?sslca=path/to/mysql-ssl-ca-cert.pem 

In Django settings:

 DATABASES = { 'default': dj_database_url.config() } DATABASES['default']['OPTIONS'] = {'ssl': {'ca': 'mysql-ssl-ca-cert.pem'}}` 

I tried searching and read a lot about setting up this type of environment in Rails, but the documentation about it with Django is easy for nonexistent.

Has anyone out there successfully deployed a similar setup, or does anyone have thoughts on how to resolve this error?

Update:

The connection through cli works, and also connects directly using MySQLdb in the python interpreter.

+6
source share
1 answer

It is decided:

The path to the pem file must be absolute, and you cannot use python to try to build an absolute path.

 DATABASES = { 'default': dj_database_url.config() } DATABASES['default']['OPTIONS'] = { 'ssl': {'ca': '/app/project_name/rds/mysql-ssl-ca-cert.pem'} } 

Again, defining a path like this does not work, the path must be hard-coded:

 DATABASES['default']['OPTIONS'] = { 'ssl': {'ca': os.path.join(os.path.dirname(__file__), 'rds', 'mysql-ssl-ca-cert.pem')} } 
+6
source

All Articles