代码之家  ›  专栏  ›  技术社区  ›  vt2424253

AWS Elastic Beanstalk,生成过程中发生错误:命令01_syncdb

  •  1
  • vt2424253  · 技术社区  · 11 年前

    我需要帮助将django web应用程序部署到AWS EB。我的本地开发环境是mac os特立独行。我使用的是django 1.6和virtualenv 1.11.4。如果您能够使用AWS说明进行部署,我真的希望您能够分享您的经验以及您在克服障碍方面所做的不同。

    [django aws]( http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html )

    我陷入了第6步:更新应用程序。

    我尝试了几个配置文件,但都没有成功:

    数据库配置:

    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版本2:

    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版本3:

    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/"
    

    我收到的错误是:

    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).
    

    下面是另一段来自不同尝试的错误,只对配置文件进行了少量更改:

    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.
    

    本质上,这些错误来自错误配置的配置文件。你能分享你的成功故事吗?或者你是如何通过这一步骤的?在我看来,遵循亚马逊文档是行不通的。顺便说一下,我也尝试了以下示例,但它似乎也不适合我。 http://grigory.ca/2012/09/getting-started-with-django-on-aws-elastic-beanstalk/

    我真的很感谢你的帮助。

    5 回复  |  直到 11 年前
        1
  •  2
  •   amirouche    4 年前

    而不是使用 django-admin.py 我使用 manage.py 自,如 django doc :

    此外,在每个Django中都会自动创建manage.py 项目manage.py是django-admin.py的一个薄薄的包装 在授权给django-admin.py之前,请注意两件事:

    它将项目包放在sys.path上 DJANGO_SETTINGS_MODULE环境变量,使其指向 项目设置.py文件。它调用django.setup()来初始化 Django的各种内部。

    所以我的工作配置是:

    container_commands:
      01_syncdb:
        command: "python manage.py syncdb --noinput"
        leader_only: true
    ...
    

    ps:不要在配置文件中传递aws凭据!改用环境变量;)

        2
  •  2
  •   e.thompsy    11 年前

    我感觉到你的痛苦。

    我发现使用 eb logs 从deployment命令行返回每次解决此问题所需的堆栈跟踪。搜索返回的日志 01_syncdb 你会找到找到分辨率所需的比特。对我来说,这已经发生过很多次了,而且有一次 local_settings.py 进入git回购。然后我发现 eb日志 我的应用程序试图连接到127.0.0.1的数据库。我从git中删除了该文件,并重新部署了BLAMMO!应用程序已修复。

    您可以这样做以在本地捕获日志: eb logs > eb_logs.txt .

    不幸的是 eb status 命令非常简短。阅读完整的日志是真正了解那里发生了什么的唯一方法。这个 明亮的一面 那是用的吗 eb日志 您不需要连接到实例。

        3
  •  1
  •   Community CDub    8 年前

    我在通过.config文件设置环境变量时遇到了问题。因此,我所做的是仅使用最小的option_settings:

    option_settings:
      - namespace: aws:elasticbeanstalk:container:python
        option_name: WSGIPath
        value: django_generic/wsgi.py
    

    然后在wsgi.py中有以下行

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_generic.settings")
    

    并在EB环境的设置中设置所有环境变量(如AWS访问键)(配置——>软件配置——>环境财产)。这也是您可以设置 ALLOWED_HOSTS 设置和您的 DB_NAME

    有时,问题也可能与使用django-admin.py vs manage.py有关,请参阅以下问题: Django on AWS Elastic Beanstalk: Unexpected syncdb error on deploy

        4
  •  1
  •   user1552891    10 年前

    如果你不能解决 01_syncdb失败 通过检查配置文件(与教程完全相同),您应该检查可能导致此错误的其他文件。

    例如,在我的案例中,第一次成功构建了应用程序,然后它以“01_sycndb”失败。在我再次检查 日志文件 ,我发现这个错误是由settings.py中的错别字引起的。

    检查一下日志,你可能会发现一些糖果。

    http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.loggingS3.title.html

        5
  •  0
  •   jamesthakid    10 年前

    当你部署了一个新的应用程序而忘记创建RDS实例时,也会发生这种情况。