Django-Cms 2.4 South Migration on AWS Beanstalk - amazon-web-services

I have a Django app (still in development) built with Django-Cms 2.4 and its other dependencies, the problem i'm having is that during deployment to AWS Beanstalk Environment, the 01_syncdb command below fails whenever i add a new app to INSTALLED_APPS in settings.py.
In the .config file
I have the in the container commands:
01_syncdb:
command: "django-admin.py syncdb --noinput"
leader_only = True
02_migrate:
command: "django-admin.py migrate --noinput"
leader_only = True
log
2013-08-20 10:21:46,812 [DEBUG] (19029 MainThread) [commandWrapper.py-60] [root commandWrapper main] Command result: {'status': 'FAILURE', 'results': [{'status': 'FAILURE', 'config_set': u'Infra-EmbeddedPostBuild', 'returncode': 1, 'events': [], 'msg': 'Error occurred during build: Command 01_syncdb failed\n'}], 'api_version': '1.0'}
What could be wrong? Thanks

To others that encounter this problem, you might want to check if you have mysql-python (or whatever database driver compatible with the database your project is using) included in your requirements.txt so that the system will know that you need this installed in your environment. Django won't be able to communicate with the database without this package.
I also predict that your second command (02_migrate) will fail since the migrate command will not be recognized by django-admin.py. Use the following instead
02_migrate:
command: "python manage.py migrate --noinput"

Related

How to run the collectstatic script after deployment to amazon elastic beanstalk?

I have a django app that is deployed on aws elastic beanstalk when I want to deploy I need to run the migrate, and the collectstatic script.
I have created 01_build.config in .ebextensions directory and this is its content
commands:
migrate:
command: "python manage.py migrate"
ignoreErrors: true
collectstatic:
command: "python manage.py collectstatic --no-input"
ignoreErrors: true
but still, it is not running these scripts.
Sounds like you want to run these scripts after the app has been set up, in which case you need to use the key container_commands rather than commands. From the docs:
The commands run before the application and web server are set up and the application version file is extracted.
and
Container commands run after the application and web server have been set up and the application version archive has been extracted, but before the application version is deployed. Non-container commands and other customization operations are performed prior to the application source code being extracted.

Beanstalk not running makemigrations

I am trying to deploy my Django server to Amazon through Beanstalk, and so far it's been ok except I've made a few changes to my models and when I deployed the instance on Aws is not updating accordingly.
I have followed the guide from amazon and created a file named db-migrate.config with the content
container_commands:
01_migrate:
command: "django-admin.py migrate"
leader_only: true
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: myAppName.settings
but obviously it doesn't seem to be working. I tried to access my django instance on Aws with
eb ssh myAppEnv
but when I enter I saw nothing and I couldn't find the code for my django server anywhere, thus i am unable to debug and manually run makemigrations also.
Anyone can help me with this?
Only way i was able to fix this was by specifying the exact applications i wanted to makemigrate and migrate.
02_migrateapps:
command: "source /opt/python/run/venv/bin/activate && python3 manage.py makemigrations organisations shows media exhibitors && python3 manage.py migrate --noinput"
leader_only: true
It's a real pain but each time i make a new app i'll need to add it to the list of makemigrations.
Hope this helps.

Elastic Beanstalk Django migrate issue

I'm deploying Django app to the AWS EB using CLI and noticed that EB doesn't see new migrations files for the first time. So, when I have new migrations I need to deploy twice. I looked at logs and indeed migrations were not found for the first time and found for the second time.
Here is my code for migrations:
container_commands:
01_migrate:
command: "django-admin.py migrate"
leader_only: true
02_collectstatic:
command: "python ras-server/manage.py collectstatic --noinput"
Am I need to change commands order? Also, I think that issue could be with Jenkins as I deploy from Jenkins. Any suggestions?
The issue was with Jenkins: for some reason when I deployed using execute shell migrations where not found for the first time.
The solution is to use Elastic Beanstalk Deployment plugin. Also, it takes less time to deploy with the plugin.
Same Error for me. In my case. I forgot to include App name in the migration. Try including App name exams
01_migrate:
command: "python manage.py makemigrations exams --noinput"
command: "python manage.py migrate exams --noinput"
leader_only: true

Django app deployed on elastic beanstalk with MySQL RDS - tables never get created

I have followed every guide, and tutorial, on setting up RDS MySQL for my Django app. Everything works fine locally. When I deploy, I get no errors. My website runs. But when I try to access the restful framework I have setup, or I try to log into the admin page, I get a ProgrammingError that the table doesn't exist (none of the tables exist).
Access to the database doesn't seem to be the problem, all of my RDS environment variables are set up, the security group is set up, etc. I can even access the database from my local mysql client and I can see that the database has no tables in it.
I have commands set up in my config file to run 'django-admin.py makemigrations' and 'django-admin.py migrate', I even tried changing this to 'python manage.py ...' etc., it seems like the commands never work.
When I ssh into my elastic beanstalk environment, I can get into the mysql using 'mysql -u my_username'. However, if I navigate to the folder where my app is, and try to run 'python manage.py makemigrations' manually, I get this: django.db.utils.OperationalError: (1045, "Access denied for user 'my_username'#'localhost' (using password: YES)")
Here is my config...
requirements.txt
virtualenv==15.0.1
Django==1.9.5
django-compressor==2.0
django-model-utils==2.4
djangorestframework==3.3.2
dj-database-url==0.4.0
gunicorn==19.4.5
MySQL-python==1.2.5
jsonfield==1.0.3
.ebextentions/01_packages.config
packages:
yum:
git: []
gcc: []
mysql: []
mysql-devel: []
python-devel: []
.ebextentions/project.config
container_commands:
01_makemigrations:
command: "source /opt/python/run/venv/bin/activate && python manage.py makemigrations --noinput"
leader_only: true
02_migrate:
command: "source /opt/python/run/venv/bin/activate && python manage.py migrate --noinput"
leader_only: true
03_createsu:
command: "source /opt/python/run/venv/bin/activate && python manage.py createsu"
leader_only: true
04_collectstatic:
command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"
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'],
}
}
Please help. Thank you!
See if the RDS security group is configured in EC2 security groups for your elastic beanstalk. It should look like this:
EC2 security groups: your-rds-security-group-name, your-Elastic-Beanstalk-Security-Group
Make sure that the same settings are used when migrating and running!
I had a similar problem but I figured out that I used local settings (from manage.py) when migrating. But for running i used production settings (defined in wsgi.py). That meant that a local database was migrated but a production one was used but was never migrated, thus tables were never created even if migration command returning a success. I had to change my django.config:
container_commands:
01_makemigrations:
command: "source /opt/python/run/venv/bin/activate && python manage.py makemigrations"
leader_only: true
02_migrate:
command: "source /opt/python/run/venv/bin/activate && python manage.py migrate"
leader_only: true
to:
container_commands:
01_migrate:
command: "django-admin migrate"
leader_only: true
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: fund.productionSettings
as recommended here.

Django with AWS - Correct way to syncdb and run scheema migrations using South

In development when I was running django on a local server, I first added South in my installed apps and then did
python manage.py syncdb
After that, whenever I made a change to the database, I'd do
python manage.py scheemamigration
python manage.py migrate appName
I now am using AWS elastic beanstalk and do
git add .
git commit "change made"
git aws.push
to update the aws server. However, I cannot run
python manage.py syncdb
because it says
Unknown command 'syncdb'
so I cannot syncdb and do scheemamigrations. What is the best way for me syncdb and do scheema migrations using South now that I am using AWS servers.
You need to make a container command, heres a snippet from the aws docs...
On your local computer, update your configuration file (e.g., myapp.config) in the > .ebextensions directory.
container_commands:
01_syncdb:
command: "django-admin.py syncdb --migrate --noinput"
leader_only: true
See http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html (Step 6, point number 2) Sorry no anchors in aws docs..
EDIT: Added in migrate flag to syncdb, and changed aws doc reference to a more pertinent one