简体   繁体   English

AWS Elastic Beanstalk Django 迁移

[英]AWS Elastic Beanstalk Django Migration

I have an EC2 instance set up through Beanstalk, but I cannot get the config to run migration我有一个通过 Beanstalk 设置的 EC2 实例,但我无法让配置运行迁移

my .ebextension/django.config我的.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

After checking the logs, it says检查日志后,它说

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.

Now even if I add these ip's to ALLOWED_HOSTS in my settings.py, the problem remains.现在,即使我将这些 ip 添加到我的 settings.py 中的 ALLOWED_HOSTS,问题仍然存在。 I searched around here and found no answer to this specific issue我在这里搜索并没有找到这个特定问题的答案

Without the migration commands, my server is built successfully and is running.如果没有迁移命令,我的服务器将成功构建并正在运行。

Anyone know why?有谁知道为什么?

EDIT:编辑:

to add more info:添加更多信息:

When I run eb deploy after committing to my github, i got error as following当我在提交到我的 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.

Then I go into web.stdout.log to find those allowed_host errors.然后我将 go 放入web.stdout.log以查找那些 allowed_host 错误。 Then again, from another post, it doesn't seem like adding these ip's help since they are AWS ip's再说一次,从另一篇文章来看,似乎没有添加这些 ip 的帮助,因为它们是 AWS ip

I can't locate other error logs from cloudwatch.我无法从 cloudwatch 中找到其他错误日志。 This seems like the only suspect这似乎是唯一的嫌疑人

The eb-engine.log only says eb-engine.log只说

Error occurred during build: Command 01_migrate failed

so I knoe the echo worked.....所以我知道echo有效.....

It turns out my migration does not run because the a data entry I put in violates the max_length of a CharField.事实证明我的迁移没有运行,因为我输入的数据条目违反了 CharField 的max_length locally I use sqlite3 so it ignores max_length......在本地我使用 sqlite3 所以它忽略了 max_length ......

I did not locate the error at first because eb log tells me to check cfn-init.log when in fact the error logs are in cfn-init-cmd.log, something that doesn't get registered in cloudwatch by default and eb doesn't show any indication to check for that log in doc OR terminal msg.我一开始没有找到错误,因为 eb 日志告诉我检查 cfn-init.log,而实际上错误日志在 cfn-init-cmd.log 中,默认情况下不会在 cloudwatch 中注册而 eb 没有'不显示任何指示来检查该登录文档或终端消息。

At the end, my config file looks like最后,我的配置文件看起来像

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

the venv sourcing path is found when ssh-ing into my ec2 instance. ssh 进入我的 ec2 实例时,找到了 venv 源路径。

For those of you who do not find useful info in eb logs , ssh into your EC2 instance (if you're using it) and check /var/log/*.log对于那些在eb logs中找不到有用信息的人,将 ssh 放入您的 EC2 实例(如果您正在使用它)并检查/var/log/*.log

If you are using MySQL, you have to do the below steps:如果您使用的是 MySQL,则必须执行以下步骤:

  1. Add mysqlclient to your requirements.txt .mysqlclient添加到您的requirements.txt
  2. Add some packages to be installed in your EC2 instance with a config file:使用配置文件添加一些要安装在您的 EC2 实例中的软件包:

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

Check my recent question and answer for more details: mysqlclient installation error in AWS Elastic Beanstalk查看我最近的问题和答案以获取更多详细信息: AWS Elastic Beanstalk 中的 mysqlclient 安装错误

This is what it worked.ebextensions/django.config这就是它的工作原理。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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM