-
Notifications
You must be signed in to change notification settings - Fork 5
Deployment via Amazon Elastic Beanstalk
Stanislav Valasek edited this page Nov 21, 2020
·
10 revisions
- Django - https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
- Migrations - https://stackoverflow.com/questions/62442212/aws-elastic-beanstalk-container-commands-failing
- DB
- SSL configuration - https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/configuring-https.html
Install AWS CLI
pip install awsebcli
ASW Deployment
mkdir .ebextensions
Create .ebextensions\django.config with content
container_commands:
01_sh_executable:
command: find .platform/hooks/ -type f -iname "*.sh" -exec chmod +x {} \;
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: ebdjango.settings
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
/static_files: static_files
aws:elasticbeanstalk:container:python:
WSGIPath: ebdjango.wsgi:application
Run the commands
eb init -p python-3.7 kicoma
eb create kicoma-env
eb status
copy CNAME value
CNAME: kicoma-env.eba-j2q4pbqw.eu-central-1.elasticbeanstalk.com
to ALLOWED_HOSTS in the settings file
Create .platform/hooks/predeploy/01_migrations.sh with a content
container_commands:
01_sh_executable:
command: find .platform/hooks/ -type f -iname "*.sh" -exec chmod +x {} \;
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: ebdjango.settings
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
/static_files: static_files
aws:elasticbeanstalk:container:python:
WSGIPath: ebdjango.wsgi:application
Update settings file
import os
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'],
}
}
Deploy
eb deploy