7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Elastic Beanstalk + Python 3.6 + Django 2.0.5

Last updated at Posted at 2018-05-03

Elastic Beanstalk への Django アプリケーションのデプロイ

  • Python 2.7
  • Django 1.11.3

この構成は少し古いので、最新の構成で構築する。

  • Python 3.6
  • Django 2.0.5

Elastic Beanstalk(以降、EB)は、下記の構成になっている

  • EB
  • アプリケーション
  • 環境(ステージング|運用)

Macにawsebcliをインストール

$ pip install awsebcli --upgrade --user
$ export PATH=~/Library/Python/3.6/bin:$PATH
$ source ~/.bash_profile
$ eb --version
EB CLI 3.12.4 (Python 3.6.5)

Djangoのチュートリアル

$ sudo easy_install virtualenv

DjangoでPython仮想環境を設定する

$ virtualenv ~/eb-virt -p python3
$ source ~/eb-virt/bin/activate

(eb-virt)$ pip install django
(eb-virt)$ pip freeze
Django==2.0.5
pytz==2018.4

Djangoプロジェクト(アプリケーション)を作成する

(eb-virt)$ django-admin startproject {アプリケーション名}

ローカルで実行

(eb-virt)$ cd {アプリケーション名}
(eb-virt)$ python manage.py runserver

Elastic Beanstalk用にDjangoをアプリケーションを設定する

(eb-virt)$ pip freeze > requirements.txt
(eb-virt)$ mkdir .ebextensions
(eb-virt)$ vi .ebextensions/django.config
.ebextensions/django.config

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: {アプリケーション名}/wsgi.py
(eb-virt)$ deactivate

EB CLIでサイトをデプロイする

アプリケーションの作成

$ eb init -p python-3.6 {アプリケーション名}
Select a default region
1) us-east-1 : US East (N. Virginia)
2) us-west-1 : US West (N. California)
3) us-west-2 : US West (Oregon)
4) eu-west-1 : EU (Ireland)
5) eu-central-1 : EU (Frankfurt)
6) ap-south-1 : Asia Pacific (Mumbai)
7) ap-southeast-1 : Asia Pacific (Singapore)
8) ap-southeast-2 : Asia Pacific (Sydney)
9) ap-northeast-1 : Asia Pacific (Tokyo)
10) ap-northeast-2 : Asia Pacific (Seoul)
11) sa-east-1 : South America (Sao Paulo)
12) cn-north-1 : China (Beijing)
13) cn-northwest-1 : China (Ningxia)
14) us-east-2 : US East (Ohio)
15) ca-central-1 : Canada (Central)
16) eu-west-2 : EU (London)
17) eu-west-3 : EU (Paris)
(default is 3): 

アプリケーションの初期化

$ eb init
Cannot setup CodeCommit because there is no Source Control setup, continuing with initialization
Do you want to set up SSH for your instances?
(Y/n): 

環境の作成

EC2インスタンスの立ち上げや、ロードバランサーの設定を行うため3分ほど時間がかかる

$ eb create {アプリケーション名}-{環境名}

以降のデプロイ

$ eb deploy
7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?