【问题标题】:AWS Elastic Beanstalk Django MigrationAWS Elastic Beanstalk Django 迁移
【发布时间】:2020-09-21 16:19:39
【问题描述】:

我通过 Beanstalk 设置了一个 EC2 实例,但我无法让配置运行迁移

我的.ebextension/django.config

option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: my_app.settings
  aws:elasticbeanstalk:container:python:
    WSGIPath: my_app.wsgi:application
    NumProcesses: 3
    NumThreads: 20
container_commands:
  00_test_output:
    command: "echo 'testing.....'"
  01_migrate:
    command: "python manage.py migrate"
    leader_only: true

检查日志后,它说

Invalid HTTP_HOST header: '52.37.179.147'. You may need to add '52.37.179.147' to ALLOWED_HOSTS.
Invalid HTTP_HOST header: '172.31.0.249'. You may need to add '172.31.0.249' to ALLOWED_HOSTS.

现在,即使我将这些 ip 添加到我的 settings.py 中的 ALLOWED_HOSTS,问题仍然存在。我在这里搜索并没有找到这个特定问题的答案

没有迁移命令,我的服务器构建成功并且正在运行。

有人知道为什么吗?

编辑:

添加更多信息:

当我在提交到我的 github 后运行 eb deploy 时,出现以下错误

2020-06-03 03:45:10    ERROR   [Instance: i-05f872f7e96ccd26d] Command failed on instance. An unexpected error has occurred [ErrorCode: 0000000001].
2020-06-03 03:45:11    INFO    Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
2020-06-03 03:45:11    ERROR   Unsuccessful command execution on instance id(s) 'i-05f872f7e96ccd26d'. Aborting the operation.
2020-06-03 03:45:11    ERROR   Failed to deploy application.

然后我进入web.stdout.log 查找那些 allowed_host 错误。再说一次,从另一篇文章来看,似乎没有添加这些 ip 的帮助,因为它们是 AWS ip 的

我无法从 cloudwatch 中找到其他错误日志。这似乎是唯一的嫌疑人

eb-engine.log 只说

Error occurred during build: Command 01_migrate failed

所以我知道echo 工作了.....

【问题讨论】:

  • 您使用什么数据库引擎?是mysql5.7吗?
  • Postgres。我在requirement.txt中安装了psycopg2

标签: django amazon-web-services amazon-elastic-beanstalk


【解决方案1】:

结果我的迁移没有运行,因为我输入的数据条目违反了 CharField 的 max_length。在本地我使用 sqlite3 所以它忽略了 max_length......

我一开始没有找到错误,因为 eb 日志告诉我检查 cfn-init.log,而实际上错误日志在 cfn-init-cmd.log 中,默认情况下不会在 cloudwatch 中注册的东西并且 eb 没有显示任何指示来检查该登录文档或终端消息。

最后,我的配置文件看起来像

option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: my_app.settings
  aws:elasticbeanstalk:container:python:
    WSGIPath: my_app.wsgi:application
    NumProcesses: 3
    NumThreads: 20
container_commands:
  00_test_output:
    command: "echo 'testing.....'"
  01_migrate:
    command: "source /var/app/venv/staging-LQM1lest/bin/activate && python3 manage.py migrate --noinput"
    leader_only: true

在 ssh-ing 到我的 ec2 实例时找到了 venv 源路径。

对于那些在 eb logs 中找不到有用信息的人,请通过 ssh 进入您的 EC2 实例(如果您正在使用它)并检查 /var/log/*.log

【讨论】:

    【解决方案2】:

    如果您使用的是 MySQL,则必须执行以下步骤:

    1. mysqlclient 添加到您的requirements.txt
    2. 使用配置文件添加一些要安装在您的 EC2 实例中的软件包:

      packages:
        yum:
          python3-devel: []
          mariadb-devel: []
      

    查看我最近的问题和答案以获取更多详细信息: mysqlclient installation error in AWS Elastic Beanstalk

    【讨论】:

      【解决方案3】:

      这就是它的工作原理 .ebextensions/django.config

          option_settings:
            aws:elasticbeanstalk:application:environment:
              DJANGO_SETTINGS_MODULE: my_app.settings
            aws:elasticbeanstalk:container:python:
              WSGIPath: travel.wsgi:application
              NumProcesses: 3
              NumThreads: 20
          container_commands:
            01_collectstatic:
              command: "source /var/app/venv/staging-LQM1lest/bin/activate && python manage.py collectstatic --noinput"
            02_migrate:
              command: "source /var/app/venv/staging-LQM1lest/bin/activate && python manage.py migrate --noinput"
              leader_only: true
      

      【讨论】:

        猜你喜欢
        • 2021-02-03
        • 2015-06-14
        • 2014-03-10
        • 2015-11-05
        • 1970-01-01
        • 2021-05-21
        • 2020-10-08
        • 2021-06-08
        • 2015-09-06
        相关资源
        最近更新 更多