1

I have an EC2 instance set up through Beanstalk, but I cannot get the config to run migration

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

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. Then again, from another post, it doesn't seem like adding these ip's help since they are AWS ip's

I can't locate other error logs from cloudwatch. This seems like the only suspect

The eb-engine.log only says

Error occurred during build: Command 01_migrate failed

so I knoe the echo worked.....

JChao
  • 2,178
  • 5
  • 35
  • 65

3 Answers3

2

It turns out my migration does not run because the a data entry I put in violates the max_length of a CharField. locally I use sqlite3 so it ignores 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.

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.

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

JChao
  • 2,178
  • 5
  • 35
  • 65
0

If you are using MySQL, you have to do the below steps:

  1. Add mysqlclient to your requirements.txt.
  2. Add some packages to be installed in your EC2 instance with a config file:

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

Check my recent question and answer for more details: mysqlclient installation error in AWS Elastic Beanstalk

Yasser Mohsen
  • 1,411
  • 1
  • 12
  • 29
0

This is what it worked .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
Prajwol KC
  • 398
  • 6
  • 13