Reputation: 1427
I need help deploying a django web app to AWS EB. My local development env is mac os maverick. I'm using django 1.6 and virtualenv 1.11.4. If you were able to deploy using the AWS instructions, I really hope you can share your experience and what you've done differently to overcome the obstacles.
[django aws] (http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html)
I am stuck at Step 6: Update Application.
I've tried several config file and none of these worked:
dgeneric.config:
container_commands:
01_syncdb:
command: "django-admin.py syncdb --noinput"
leader_only: true
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: django_generic/wsgi.py
- option_name: DJANGO_SETTINGS_MODULE
value: django_generic.settings
- option_name: AWS_SECRET_KEY
value: SAMPLESECRETxMkk7DTME37PgiEnzA8toans
- option_name: AWS_ACCESS_KEY_ID
value: SAMPLEACCESSDAHRD7A
dgeneric.config version2:
container_commands:
collectstatic:
command: "django-admin.py collectstatic --noinput"
01syncdb:
command: "django-admin.py syncdb --noinput"
leader_only: true
02migrate:
command: "django-admin.py migrate"
leader_only: true
99customize:
command: "scripts/customize.sh"
You can specify any key-value pairs in the aws:elasticbeanstalk:application:environment namespace and it will be
passed in as environment variables on your EC2 instances
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "django_generic.settings"
"application_stage": "staging"
"aws:elasticbeanstalk:container:python":
WSGIPath: django_generic/wsgi.py
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"
dgeneric.config version3:
container_commands:
00_make_executable:
command: "chmod +x scripts/createadmin.py"
leader_only: true
01_syncdb:
command: "django-admin.py syncdb --noinput"
leader_only: true
02_createadmin:
command: "scripts/createadmin.py"
leader_only: true
03_collectstatic:
command: "django-admin.py collectstatic --noinput"
option_settings:
"aws:elasticbeanstalk:container:python:environment":
DJANGO_SETTINGS_MODULE: "django_generic.settings"
"aws:elasticbeanstalk:container:python":
WSGIPath: "django_generic/wsgi.py"
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"
The errors I've received are:
2014-03-19 16:30:09 UTC-0400 INFO Environment update completed successfully.
2014-03-19 16:30:09 UTC-0400 INFO New application version was deployed to running EC2 instances.
2014-03-19 16:30:08 UTC-0400 INFO Command execution completed. Summary: [Successful: 0, Failed: 1].
2014-03-19 16:30:08 UTC-0400 ERROR [Instance: i-3311f412 Module: AWSEBAutoScalingGroup ConfigSet: null] Command failed on instance. Return code: 1 Output: Error occurred during build: Command 02_createadmin failed .
2014-03-19 16:28:59 UTC-0400 INFO Deploying new version to instance(s).
And here is another snippet of errors from a different attempt with only minor changes to the config file:
2014-03-19 16:02:57 UTC-0400 INFO Environment update completed successfully.
2014-03-19 16:02:57 UTC-0400 INFO New application version was deployed to running EC2 instances.
2014-03-19 16:02:56 UTC-0400 INFO Command execution completed. Summary: [Successful: 0, Failed: 1].
2014-03-19 16:02:56 UTC-0400 ERROR [Instance: i-3311f412 Module: AWSEBAutoScalingGroup ConfigSet: null] Command failed on instance. Return code: 1 Output: Error occurred during build: Command 01_syncdb failed .
2014-03-19 16:02:49 UTC-0400 INFO Deploying new version to instance(s).
2014-03-19 16:01:52 UTC-0400 INFO Environment update is starting.
Essentially, these errors are coming from the config file being configured wrongly. Could you share your success story or how you got pass this step in your deployment? As I see it, following amazon docs does not work. BTW, I've also tried the following examples and it did not seem to work for me either. http://grigory.ca/2012/09/getting-started-with-django-on-aws-elastic-beanstalk/
I really appreciate your help.
Upvotes: 1
Views: 6902
Reputation: 19618
Instead of using django-admin.py
I use manage.py
since, as reported in the django doc:
In addition, manage.py is automatically created in each Django project. manage.py is a thin wrapper around django-admin.py that takes care of two things for you before delegating to django-admin.py:
It puts your project’s package on sys.path. It sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project’s settings.py file. It calls django.setup() to initialize various internals of Django.
So my working config is:
container_commands:
01_syncdb:
command: "python manage.py syncdb --noinput"
leader_only: true
...
ps: don't pass your aws credential in the config file! Use instead environment variables ;)
Upvotes: 2
Reputation: 1265
This also happen when you deploy a new app and forget to create a RDS instance.
Upvotes: 0
Reputation: 567
If you can not solve 01_syncdb failed problem by checking the config file (exactly the same with the tutorial), you should check other files that may cause this error.
For example, in my case, the application was build successfully for the first time, then it failed with "01_sycndb". After I double check the log file, I found this error was introduced by a typo in settings.py.
Check the log and you may find some candies.
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.loggingS3.title.html
Upvotes: 1
Reputation: 1377
I feel your pain.
I found that using eb logs
from the deployment command line gave me back the necessary stack traces to resolve this issue every time. Search the logs that come back for 01_syncdb
and you will find the necessary bits to find a resolution. For me it has happened many times and once the cause was letting my local_settings.py
into the git repo. Then I found in eb logs
that my application was trying to connect to the database at 127.0.0.1. I removed that file from git and redeployed and BLAMMO! the application was fixed.
You could do this to capture the logs locally: eb logs > eb_logs.txt
.
Unfortunately, the response from the eb status
command is very brief. Reading the full logs is the only way to really know what happened in there. The BRIGHT SIDE™ is that with eb logs
you don't need to connect to the instance.
Upvotes: 2
Reputation: 4021
I had problems with setting environment variables through the .config file. So what I did is to use only a minimal option_settings:
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: django_generic/wsgi.py
And then having the following line in the wsgi.py
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_generic.settings")
And setting all the Environment variables (such as the AWS access keys) in the settings of the EB Environment (Configuration --> Software Configuration --> Environment Properties). That's also where you can set the ALLOWED_HOSTS
setting and your DB_NAME
etc.
Sometimes the problem can also be related to using django-admin.py vs manage.py, see this question: Django on AWS Elastic Beanstalk: Unexpected syncdb error on deploy
Upvotes: 1