J.Necker
J.Necker

Reputation: 75

Django on AWS Elasticbeanstalk: Command 02_createadmin failed

I'm trying to deploy my first django application, and chose AWS with elastic beanstalk because it seemed like the most straightforward way to do so. I have been haltingly working through the (outdated) official docs, but am completely stuck trying to configure the admin site (step 7). I've also been using this blog post and the accompanying broilerplate code. I'm using Python 2.7, Django 1.6.1, (locally) Windows 8 with Powershell.

When I try to deploy my application, I get the error:

[Instance: i-03f98f2d Module: AWSEBAutoScalingGroup ConfigSet: null] Command failed on instance. Return code: 1 Output: Error occurred during build: Command 02_createadmin failed.

Here's what (I think) the relevant part of the logs looks like, I'd be happy to update with more if this isn't enough:

2014-02-10 19:07:17,373 [INFO] (25971 MainThread) [command.py-130] [root command execute] Command returned: (code: 1, stdout: Error occurred during build: Command 02_createadmin failed
, stderr: None)
2014-02-10 19:07:17,375 [DEBUG] (25971 MainThread) [commandWrapper.py-60] [root commandWrapper main] Command result: {'status': 'FAILURE', 'results': [{'status': 'FAILURE', 'config_sets': ['Infra-WriteRuntimeConfig', 'Infra-WriteApplication1', 'Infra-WriteApplication2', 'Infra-EmbeddedPreBuild', 'Hook-PreAppDeploy', 'Infra-EmbeddedPostBuild', 'Hook-EnactAppDeploy', 'Hook-PostAppDeploy'], 'returncode': 1, 'events': [], 'msg': 'Error occurred during build: Command 02_createadmin failed\n'}], 'api_version': '1.0'}

...

2014-02-10 19:07:17,234 [DEBUG] Running command 02_createadmin
2014-02-10 19:07:17,235 [DEBUG] Generating defaults for command 02_createadmin
<<<

2014-02-10 19:07:17,319 [DEBUG] Running test for command 02_createadmin
2014-02-10 19:07:17,330 [DEBUG] Test command output: 
2014-02-10 19:07:17,331 [DEBUG] Test for command 02_createadmin passed
2014-02-10 19:07:17,340 [ERROR] Command 02_createadmin (scripts/createadmin.py) failed
2014-02-10 19:07:17,341 [DEBUG] Command 02_createadmin output: /bin/sh: scripts/createadmin.py: Permission denied

2014-02-10 19:07:17,341 [ERROR] Error encountered during build of postbuild_0_legi_track_prod: Command 02_createadmin failed
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 511, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 247, in build
    changes['commands'] = CommandTool().apply(self._config.commands)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/command_tool.py", line 113, in apply
    raise ToolError(u"Command %s failed" % name)
ToolError: Command 02_createadmin failed
2014-02-10 19:07:17,342 [ERROR] Unhandled exception during build: Command 02_createadmin failed
Traceback (most recent call last):
  File "/opt/aws/bin/cfn-init", line 122, in <module>
    worklog.build(detail.metadata, configSets)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 117, in build
    Contractor(metadata).build(configSets, self)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 502, in build
    self.run_config(config, worklog)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 511, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/construction.py", line 247, in build
    changes['commands'] = CommandTool().apply(self._config.commands)
  File "/usr/lib/python2.6/site-packages/cfnbootstrap/command_tool.py", line 113, in apply
    raise ToolError(u"Command %s failed" % name)
ToolError: Command 02_createadmin failed

My files:

legi_track_prod.config:

container_commands:
  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:
  - namespace: aws:elasticbeanstalk:container:python
    option_name: WSGIPath
    value: legi_track_prod/wsgi.py
  - namespace: aws:elasticbeanstalk:container:python:staticfiles
    option_name: /static/
    value: static/
  - option_name: DJANGO_SETTINGS_MODULE
    value: legi_track_prod.settings
  - option_name: AWS_SECRET_KEY
    value: key
  - option_name: AWS_ACCESS_KEY_ID
    value: key

/scripts/createadmin.py (I've tried several versions of this, none of them seem to work):

#!/usr/bin/env python

from django.contrib.auth.models import User
if User.objects.count() == 0:
    admin = User.objects.create_superuser('admin', '[email protected]', 'passwd')
    admin.save()

Also tried:

#!/usr/bin/env python

from django.contrib.auth.models import User
if User.objects.count() == 0:
    admin = User.objects.create(username='admin')
    admin.set_password('admin')
    admin.is_superuser = True
    admin.is_staff = True
    admin.save()

File-structure:

+---.ebextensions
+---.elasticbeanstalk
+---legi_track_prod
+---scripts
\---tracker
    +---api
    +---static
    |   \---tracker
    \---templates
        \---admin

What I've Tried:

I would just skip this step if I could, but I can't figure out any other way to get access to the app's database. I have been banging my head against this particular wall for about two days now, and would really appreciate any help. I can't be the only one to have had this problem, but all the internet reveals to me is problems/solutions for commands 01_syncdb and 03_collectstatics. Any advice on how to get this setup to work, or (alternatively) get by without scripting the creation of the admin?

Update

I'm running it exactly, and not getting any error. The filepath for the command looks like its coming from git, so I'm not sure if it's doing the same thing as the bash chmod. Googling "powershell chmod" turns up a fairly complicated workaround, so I'll try that. But when I use the GUI to look at the file's permissions, SYSTEM, admin, and regular user (locally) all have all permissions for createadmin.py, so I'm not the permissions haven't been set correctly, at least locally. I'll try the powershell version of chmod, and then I guess ssh into the aws server (which I really don't know how to do at the moment) and update with the results.

Upvotes: 6

Views: 2505

Answers (1)

kukido
kukido

Reputation: 10601

container_commands:
    00_make_executable:
        command: "chmod +x scripts/createadmin.py"
    01_...

Upvotes: 4

Related Questions