본문 바로가기

Develop

Django 배포시 항상 겪는 현상

 

WSGIPath

.ebextensions/10-django-wsgi.config

option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: main.settings
  aws:elasticbeanstalk:environment:proxy:
    ProxyServer: apache
  aws:elasticbeanstalk:environment:proxy:staticfiles:
    /html: statichtml
    /images: staticimages
  aws:elasticbeanstalk:container:python:
    WSGIPath: main.wsgi:application
    NumProcesses: 3
    NumThreads: 20

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-container.html

User Permissions

https://aws.amazon.com/ko/premiumsupport/knowledge-center/elastic-beanstalk-iam-permissions/

 

Migrate

.ebextensions/05-migrate.config 

container_commands:
  01_migrate:
    command: "source /var/app/venv/*/bin/activate && python3 manage.py migrate"
    leader_only: true
option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: main.settings

 

패키지 명시

동일한 패키지, 버전을 찾아 requirements.txt 파일에 추가

pip freeze

 

Key Pair

CLI 를 이용해 배포하려면, aws console 에서 생성된 key pair 를 등록한다.

 

Create EB environment with CLI

eb create staging-mysite -i t2.small -c staging-mysite \
--envvars DB_PW="HJGnZHlYVYyV",DB_USER="onns",DB_NAME="mysite_db",DB_HOST="db-mysite-staging.ce6uph5ztrl3.ap-northeast-2.rds.amazonaws.com"
--vpc.id vpc-042054ff559c077e9 \
--vpc.publicip \
--elb-type application \
--vpc.elbpublic \
--vpc.elbsubnets subnet-02985fea2c1a6bcdb,subnet-0abd784b2e7b13ac7,subnet-0b729945228dbf4fa \
--vpc.ec2subnets subnet-0b729945228dbf4fa

 

Log 확인

sudo tail -F /var/log/web.stdout.log

 

Run Django command

# activate
source /var/app/venv/*/bin/activate

# run django command
cd /var/app/current/
python manage.py
반응형