Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django + MySQL on Elastic Beanstalk - Error When Querying MySQL

I'm getting an error when I query MySQL on my Django app hosted on elastic beanstalk. The error says:

OperationalError at /admin/login (1045, "Access denied for user 'adminDB'@'172.30.23.5' (using password: YES)")

Here is my .config file:

container_commands:
  01_migrate:
    command: "source /opt/python/run/venv/bin/activate && python manage.py migrate --noinput"
    leader_only: true

option_settings:
  "aws:elasticbeanstalk:application:environment":
    DJANGO_SETTINGS_MODULE: "mysite.settings"
    "PYTHONPATH": "/opt/python/current/app/mysite:$PYTHONPATH"
    "ALLOWED_HOSTS": ".elasticbeanstalk.com"
  "aws:elasticbeanstalk:container:python":
    WSGIPath: mysite/wsgi.py
    NumProcesses: 3
    NumThreads: 20
  "aws:elasticbeanstalk:container:python:staticfiles":
    "/static/": "www/static/"

Here is my the databases section on settings.py:

DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            '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'],
        }
    }

I created the eb environment through the eb create command and then proceeded to create an RDS database on the eb console on their website. Is there anything else I need to do to connect Django to MySQL? Something to do with security groups or something?

Thanks!

like image 552
Arnold Lam Avatar asked Jul 13 '15 03:07

Arnold Lam


1 Answers

Thanks for your response @DrewPierce, but the problem was a simple one, and it's also extremely silly. Turns out the dollar sign in my RDS password was causing a problem. Changed it to a simpler password and I successfully logged in.

Hope this helps anyone else with a similar issue!

like image 74
Arnold Lam Avatar answered Oct 14 '22 00:10

Arnold Lam