[英]AWS Elastic Beanstalk Django Migration
我有一個通過 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.
然后我將 go 放入web.stdout.log
以查找那些 allowed_host 錯誤。 再說一次,從另一篇文章來看,似乎沒有添加這些 ip 的幫助,因為它們是 AWS ip
我無法從 cloudwatch 中找到其他錯誤日志。 這似乎是唯一的嫌疑人
eb-engine.log
只說
Error occurred during build: Command 01_migrate failed
所以我知道echo
有效.....
事實證明我的遷移沒有運行,因為我輸入的數據條目違反了 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 進入我的 ec2 實例時,找到了 venv 源路徑。
對於那些在eb logs
中找不到有用信息的人,將 ssh 放入您的 EC2 實例(如果您正在使用它)並檢查/var/log/*.log
如果您使用的是 MySQL,則必須執行以下步驟:
mysqlclient
添加到您的requirements.txt
。使用配置文件添加一些要安裝在您的 EC2 實例中的軟件包:
packages: yum: python3-devel: [] mariadb-devel: []
查看我最近的問題和答案以獲取更多詳細信息: AWS Elastic Beanstalk 中的 mysqlclient 安裝錯誤
這就是它的工作原理。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.