Closed jwjacobson closed 5 months ago
Quick inquiry: https://chat.openai.com/share/6b769b4e-2903-43c4-9bbd-de3de3801051
I have not used aws for Django yet (I only use Aws gateway API + lambda)
Feel free to post a question post on Circle as well ...
@jwjacobson let's document all here, not on Circle.
So you fixed the wsgi import issue: Jan 25 16:23:50 ip-172-31-21-218 web[7727]: ModuleNotFoundError: No module named 'wsgi'
Should be: gunicorn project.wsgi:application
Are you working off of this? https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
Keep me posted here ...
Yes, that's the documentation I'm working from. Still on the "No module named 'application'" error
Here is current django-config:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: gunicorn project.wsgi:application
And here is relevant line in eb config:
WSGIPath: project.wisgi:application
The problem above really was the typo "wisgi" instead of wsgi. Now I'm havign issues with the DATABASE_URL variable:
DATABASES = {"default": dj_database_url.config(default=config("DATABASE_URL"))}
Jan 25 23:40:11 ip-172-31-21-218 web[30141]: ^^^^^^^^^^^^^^^^^^^^^^
Jan 25 23:40:11 ip-172-31-21-218 web[30141]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/decouple.py", line 248, in __call__
Jan 25 23:40:11 ip-172-31-21-218 web[30141]: return self.config(*args, **kwargs)
Jan 25 23:40:11 ip-172-31-21-218 web[30141]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jan 25 23:40:11 ip-172-31-21-218 web[30141]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/decouple.py", line 107, in __call__
Jan 25 23:40:11 ip-172-31-21-218 web[30141]: return self.get(*args, **kwargs)
Jan 25 23:40:11 ip-172-31-21-218 web[30141]: ^^^^^^^^^^^^^^^^^^^^^^^^^
Jan 25 23:40:11 ip-172-31-21-218 web[30141]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/decouple.py", line 92, in get
Jan 25 23:40:11 ip-172-31-21-218 web[30141]: raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))
Jan 25 23:40:11 ip-172-31-21-218 web[30141]: decouple.UndefinedValueError: DATABASE_URL not found. Declare it as envvar or define a default value.
hoping to work it out soon
No docker right? Have you checked these?
Probably best to go myself through the complete steps, unless you can give me access to this specific project somehow?
Env variable issue seemed DATABASE_URL being set twice - fixed.
Also needed to refresh app after setting new ones (this is less obvious than Heroku, also the logs were slow to regen)
New error is all about db url not being reachable = success. 🎉
So no you'll need to add a db, for which you can use this: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-rds.html
Also for docs, we had to add psycopg2 which failed, psycopg2-binary
(v2.9.5) worked, reason:
There is now a database instance running, currently working on connecting to that database. Following the documentation here https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-rds.html#python-rds-connect the relevant section of my settings.py now looks like
# DATABASES = {"default": dj_database_url.config(default=config("DATABASE_URL"))}
if 'RDS_HOSTNAME' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
with os imported up top
oops didn't see the mysql in there, replacing with postgresql
good progress, then you'll do an else to keep working with DATABASE_URL locally? aws does not use that single env variable for convenience?
going to try adding this address to allowed hosts but seems a little weird?
Jan 26 15:58:01 ip-172-31-21-218 web[67348]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/django/utils/deprecation.py", line 133, in __call__
Jan 26 15:58:01 ip-172-31-21-218 web[67348]: response = self.process_request(request)
Jan 26 15:58:01 ip-172-31-21-218 web[67348]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jan 26 15:58:01 ip-172-31-21-218 web[67348]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/django/middleware/common.py", line 48, in process_request
Jan 26 15:58:01 ip-172-31-21-218 web[67348]: host = request.get_host()
Jan 26 15:58:01 ip-172-31-21-218 web[67348]: ^^^^^^^^^^^^^^^^^^
Jan 26 15:58:01 ip-172-31-21-218 web[67348]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/django/http/request.py", line 150, in get_host
Jan 26 15:58:01 ip-172-31-21-218 web[67348]: raise DisallowedHost(msg)
Jan 26 15:58:01 ip-172-31-21-218 web[67348]: django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: '172.31.21.218'. You may need to add '172.31.21.218' to ALLOWED_HOSTS.
Jan 26 15:58:01 ip-172-31-21-218 web[67348]: Bad Request: /
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: Invalid HTTP_HOST header: '172.31.21.218'. You may need to add '172.31.21.218' to ALLOWED_HOSTS.
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: Traceback (most recent call last):
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: response = get_response(request)
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: ^^^^^^^^^^^^^^^^^^^^^
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/django/utils/deprecation.py", line 133, in __call__
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: response = self.process_request(request)
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/django/middleware/common.py", line 48, in process_request
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: host = request.get_host()
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: ^^^^^^^^^^^^^^^^^^
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/django/http/request.py", line 150, in get_host
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: raise DisallowedHost(msg)
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: '172.31.21.218'. You may need to add '172.31.21.218' to ALLOWED_HOSTS.
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: Bad Request: /
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: Invalid HTTP_HOST header: '172.31.21.218'. You may need to add '172.31.21.218' to ALLOWED_HOSTS.
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: Traceback (most recent call last):
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: response = get_response(request)
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: ^^^^^^^^^^^^^^^^^^^^^
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/django/utils/deprecation.py", line 133, in __call__
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: response = self.process_request(request)
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/django/middleware/common.py", line 48, in process_request
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: host = request.get_host()
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: ^^^^^^^^^^^^^^^^^^
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/django/http/request.py", line 150, in get_host
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: raise DisallowedHost(msg)
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: '172.31.21.218'. You may need to add '172.31.21.218' to ALLOWED_HOSTS.
Jan 26 15:58:16 ip-172-31-21-218 web[67348]: Bad Request: /
Jan 26 15:58:31 ip-172-31-21-218 web[67348]: Invalid HTTP_HOST header: '172.31.21.218'. You may need to add '172.31.21.218' to ALLOWED_HOSTS.
good progress, then you'll do an else to keep working with DATABASE_URL locally? aws does not use that single env variable for convenience?
yes that's a good idea
running into error regarding social_accounts, not sure if it's really a social account issue or just something with the database and social account is the first thing it hits
I manually specified all the database info in environment variables via the Elastic Beanstalk GUI and still get the same error, maybe this really is a social account issue? Since I'm not using social logins could I just remove those templates and all corresponding info from settings.py?
Doing this now...
Making progress! got to the signup page. not sure about that toolbar...
As per code review best to set ALLOWED_HOSTS
as env variable, can you include a subdomain range?
from decouple import config, Csv
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())
My .env
ALLOWED_HOSTS=.localhost, .herokuapp.com
``
So you fixed the DB error? I would say those could be migrations not having been applied, did you run python manage.py migrate
(btw where do you run that in eb?)
The design looking wrong could be the static files not being in place so the css styling is not being applied?
App is now running and all the user functions work for jeff and admin users, i'll be submitting some new issues
Excellent!
Was there an issue with static files in the end or is it all working now?
The tutorial for Elastic Beanstalk that comes up first on Google if you search django aws is quite old as it links to Django 2.2 docs.
Just googling around for now recommendations include Elastic Beanstalk, App Runner, or a plain EC2 instance. Investigating further...