[AWSマイスターシリーズ] AWS Elastic Beanstalk -Python編- | PDFMore Related Content
PDF
20190521 AWS Black Belt Online Seminar Amazon Simple Email Service (Amazon SES) PDF
PDF
AWS X-Rayによるアプリケーションの分析とデバッグ PDF
AWS Black Belt Techシリーズ AWS Direct Connect PDF
20191029 AWS Black Belt Online Seminar Elastic Load Balancing (ELB) PDF
20191002 AWS Black Belt Online Seminar Amazon EC2 Auto Scaling and AWS Auto S... PDF
20190730 AWS Black Belt Online Seminar Amazon CloudFrontの概要 PDF
What's hot
PDF
20210119 AWS Black Belt Online Seminar AWS CloudTrail PDF
20210309 AWS Black Belt Online Seminar AWS Audit Manager PDF
20180704(20190520 Renewed) AWS Black Belt Online Seminar Amazon Elastic File ... PDF
20200526 AWS Black Belt Online Seminar AWS X-Ray PDF
20190326 AWS Black Belt Online Seminar Amazon CloudWatch PDF
20190130 AWS Black Belt Online Seminar AWS Identity and Access Management (AW... PDF
AWS Black Belt Online Seminar 2017 AWSにおけるアプリ認証パターンのご紹介 PDF
AWS Black Belt Online Seminar 2017 Amazon ElastiCache PDF
20190731 Black Belt Online Seminar Amazon ECS Deep Dive PDF
20200818 AWS Black Belt Online Seminar AWS Shield Advanced PDF
AWSとオンプレミスを繋ぐときに知っておきたいルーティングの基礎知識(CCSI監修!) PDF
AWS Black Belt Online Seminar 2017 EC2 Windows PDF
AWS Black Belt Online Seminar 2018 AWS Certificate Manager PDF
20200722 AWS Black Belt Online Seminar AWSアカウント シングルサインオンの設計と運用 PDF
20180704 AWS Black Belt Online Seminar Amazon Elastic File System (Amazon EFS... PDF
AWS Black Belt Online Seminar AWS Key Management Service (KMS) PDF
AWS Black Belt Online Seminar 2017 AWS WAF PDF
20190619 AWS Black Belt Online Seminar Dive Deep into AWS Chalice PDF
20191105 AWS Black Belt Online Seminar Amazon Route 53 Hosted Zone PDF
20190320 AWS Black Belt Online Seminar Amazon EBS Similar to [AWSマイスターシリーズ] AWS Elastic Beanstalk -Python編-
PDF
PDF
華麗なるElastic Beanstalkでの環境構築 PPTX
AWSマイスターシリーズ(Elastic Beanstalk) PDF
20120416 aws meister-reloaded-aws-elasticbeanstalk-public PDF
AWSマイスターシリーズReloaded(AWS Beanstalk) PDF
AWS Elastic Beanstalk 詳細 -ほぼ週刊AWSマイスターシリーズ第9回- PPTX
PDF
Aws elastic beanstalk-handson-summit2012 PDF
PDF
[AWSマイスターシリーズ] Amazon Elastic Compute Cloud (EC2) PDF
Awsではじめるgluster fs 20120726-public PDF
[AWSマイスターシリーズ] Amazon VPC PDF
PDF
AWSマイスターシリーズReloaded -AWS SDK for .NET- PDF
[AWSマイスターシリーズ] AWS Elastic Beanstalk PDF
AWS Black Belt Online Seminar 2017 AWS Elastic Beanstalk PDF
これでAWSマスター!? 初心者向けAWS簡単講座 PDF
クラウド/Amazon EC2の特徴とメリット・デメリット PDF
【セミナー講演資料】オープンクラウドソリューションのご紹介 PDF
More from Amazon Web Services Japan
PDF
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM) PDF
202205 AWS Black Belt Online Seminar Amazon FSx for OpenZFS PDF
202204 AWS Black Belt Online Seminar AWS IoT Device Defender PDF
Infrastructure as Code (IaC) 談義 2022 PDF
202204 AWS Black Belt Online Seminar Amazon Connect を活用したオンコール対応の実現 PDF
202204 AWS Black Belt Online Seminar Amazon Connect Salesforce連携(第1回 CTI Adap... PDF
Amazon Game Tech Night #25 ゲーム業界向け機械学習最新状況アップデート PPTX
20220409 AWS BLEA 開発にあたって検討したこと PDF
202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用 PDF
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf PDF
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介 PDF
Amazon QuickSight の組み込み方法をちょっぴりDD PDF
マルチテナント化で知っておきたいデータベースのこと PDF
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ PDF
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介 PDF
202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles PDF
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するために PDF
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨ PPTX
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介 PDF
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介 Recently uploaded
PPTX
FOSS4G Japan 2025 - QGISでスムーズに地図を比較 - QMapCompareプラグインの紹介 PDF
「似ているようで微妙に違う言葉」2025/10/17の勉強会で発表されたものです。 PDF
FOSS4G Hokkaido - QFieldをランナーのために活用した - QField for runners PDF
DX人材育成 サービスデザインで実現する「巻き込み力」の育て方 by Graat PDF
技育祭2025秋 サボろうとする生成AIの傾向と対策 登壇資料(フューチャー渋川) PDF
FOSS4G Japan 2024 ハザードマップゲームの作り方 Hazard Map Game QGIS Plugin PPTX
How to buy a used computer and use it with Windows 11 PPTX
「Drupal SDCについて紹介」2025/10/17の勉強会で発表されたものです。 [AWSマイスターシリーズ] AWS Elastic Beanstalk -Python編-
- 1.
AWSマイスターシリーズ
Reloaded
AWS Elastic Beanstalk Python編
アマゾンデータサービスジャパン株式会社
2012.12.17
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 2.
Agenda
Elastic Beanstalkとは?
• Elastic Beanstalkの概要
• 最近のアップデート、追加された機能をご紹介
仕組み
• 技術的な仕組みを解説
Python環境について
• Python利用に特化した環境関連など
開発ワークフロー
• 具体的な開発からデプロイ、環境アップデートなどのワークフ
ロー
2
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 3.
Agenda
Elastic Beanstalkとは?
• Elastic Beanstalkの概要
• 最近のアップデート、追加された機能をご紹介
仕組み
• 技術的な仕組みを解説
Python環境について
• Python利用に特化した環境関連など
開発ワークフロー
• 具体的な開発からデプロイ、環境アップデートなどのワークフ
ロー
3
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 4.
Elastic Beanstalkをひとことで言うと
開発したコードをデプロイするだけでWEBアプリケー
ション環境を構築できるサービス
• ELBやRDSもまとめて構築
• 簡単にオートスケーリングが利用可能
• 監視やイベント通知も含む
Instance
Elastic Load Amazon RDS
Balancer (オプション)
WAR deploy!
Instance
Auto scaling Group
CloudWatch
4
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 5.
AWS Elastic Beanstalkとは
Beanstalk = 豆の木
• 「アプリケーションが実る幹」のイメージ
Webアプリケーションの実行環境を構築・管理するサー
ビス
以前にもマイスターで取り上げています。
• http://www.slideshare.net/AmazonWebServicesJapan/201
20416-aws-meisterreloadedawselasticbeanstalkpublic-
12662630
5
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 6.
AWS Elastic Beanstalkとは
使用可能な言語/環境
言語 コンテナ
Java Apache +Tomcat6,
Apache+ Tomcat7
.NET IIS7.5, IIS8
PHP Apache + mod_php
Python Apache + mod_wsgi
Ruby Nginx + Passenger
6
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 7.
AWS Elastic Beanstalkとは
実行環境の設定
• サーバスペック、VM設定など40項目以上の設定が可
能
ロードバランサー・オートスケーリング
• ロードバランサーとオートスケーリングが標準装備
• 詳細な条件設定が可能
7
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 8.
AWS Elastic Beanstalkとは
Webアプリケーションのバージョン管理
• WARやZIPの世代管理が可能
• アプリのロールバック・ロールフォワードが容易
複数環境の構築が可能
• 本番・テストなど目的別に構築可能
開発・管理ツールを提供
• AWS Management Console
• コマンドラインツール
• Eclipseプラグイン
8
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 9.
開発・管理ツール
AWS Management
Console
AWS Toolkit for
Eclipse
9
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 10.
CloudWatchによるリソース監視
各種リソースをCloudWatchの機能を使って監視できま
す。
10
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 11.
Eventログの閲覧と通知
環境の構築やオートスケーリングなどのイベントの監視
が可能です。
各イベントはSNS経由でメール通知可能です。
11
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 12.
料金
Elastic Beanstalk自体は料金は発生しません。
立ち上げたEC2やELB、RDSなどの、通常の
AWS利用料金の分だけかかります。
12
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 13.
Agenda
Elastic Beanstalkとは?
• Elastic Beanstalkの概要
• 最近のアップデート、追加された機能をご紹介
仕組み
• 技術的な仕組みを解説
Python環境について
• Python利用に特化した環境関連など
開発ワークフロー
• 具体的な開発からデプロイ、環境アップデートなどのワークフ
ロー
13
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 14.
用語とアーキテクチャ
14
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 15.
アプリケーション管理の論理構成
Application
Environment Version
URL Environment Configuration WAR/ZIP
WAR/ZIP
Environment
URL Environment Configuration WAR/ZIP
WAR/ZIP
Environment
WAR/ZIP
URL Environment Configuration
Configuration Template
15
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 16.
用語説明
Application
• トップレベルの論理単位
• Applicationの中に、EnvironmentやVersionが入る
• デプロイするアプリケーション(WAR/ZIPファイル)と混同し
やすいので注意
Environment
• アプリをデプロイする環境
• 環境毎にURLが付与される
• URLは、XXX.elasticbeanstalk.com
• 各環境毎にEC2、ELBなどが立ち上がる
• ログも環境毎に取得できる(1時間おきにS3へ送信可能)
16
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 17.
用語説明
Version
• Webアプリケーションのバージョン管理
• アプリケーションファイルの履歴管理が可能
• S3上でファイルを保持
• Versionで管理したWAR/ZIPファイルを、各Environmentと紐
付け
17
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 18.
テクニカルアーキテクチャ
この環境が
自動で構成される
Application
Instance Amazon RDS
(オプション)
Elastic Load
Balancer
ログ集約
(オプション)
Instance Amazon S3
Auto scaling Group
Email Amazon
Notification CloudWatch
18
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 19.
Elastic Beanstalkの機能紹介
-環境(environment)の設定-
19
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 20.
設定項目
Server
• 起動するアプリケーションサーバのインスタンス関連の設定
LoadBalancer
• ELB関連の設定
Auto Scaling
• オートスケーリングに関する設定
Database
• RDSに関する設定(Java, Python, Ruby環境のみ)
Notifications
• 各種アラートの通知先設定
Container
• コンテナ設定
20
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 21.
設定項目
Serverで設定可能な項目
• インスタンスタイプ
• セキュリティグループ
• キーペア
• 監視インターバル(1min or 5min)
• AMI
Load Balancerで設定可能な項目
• 待受ポート番号(http, https)
• SSL証明書
• ヘルスチェック関連
• セッションスティックネス
21
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 22.
設定項目
Auto Scalingで設定可能な項目
• 最大/最小台数
• AZ(任意のAZ、もしくは任意のAZ数を指定可能)
• クールダウンタイム
• スケーリングトリガー
Databaseで設定可能な項目
• RDSインスタンスタイプ
• (必要に応じて)復元元スナップショット
• DBエンジン
• ストレージ容量
• 削除ポリシー(environment削除時にRDSを削除するかどうか)
• DBユーザー名
• Multi-AZ設定
22
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 23.
設定項目
Notificationsで設定可能な項目
• 通知先メールアドレス
• 環境構築完了時やオートスケーリング動作時などに通知が飛びます。
Containerで設定可能な項目
• S3へのログ集約のオン/オフ
• 環境変数
• AWSアクセスキー
• AWSシークレットキー
• その他言語環境に応じた変数
• 自由定義可能な変数
23
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 24.
Elastic Beanstalkの機能紹介
-eb-
24
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 25.
ebとは
2012/6リリース
eb
ElasticBeanstalkアプリのライフサイクル管理CLI
Python based
サブコマンドを受け取る短い単一コマンド
• E.g. “eb init”
eb is NOT
個々のAPIコールを行うCLI
• elastic-beanstalk-describe-applications
• elastic-beanstalk-*
Ruby based
25
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 26.
eb コマンド一覧
eb init
アプリケーションの初期設定
eb start
アプリケーション環境の開始
eb status
ステータスの確認
eb update
アプリケーション環境の設定更新
eb stop
アプリケーション環境の停止
eb delete
アプリケーションの削除
26
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 27.
Elastic Beanstalkの機能紹介
-RDS-
27
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 28.
Elastic Beanstalk環境へのRDS統合
2012/8リリース
環境構築時にRDSも一緒に構築できるようになりました。
現状(2012/12)、.NETではご利用いただけません。
スナップショットからの起動や、環境削除時にRDSを削
除するかどうかなど、細かい設定が可能です。
構築したRDSの各種設定値(エンドポイントなど)は環境
変数としてコンテナに渡されます。
28
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 29.
Elastic Beanstalk環境へのRDS統合
設定項目
29
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 30.
Elastic Beanstalkの機能紹介
-コンフィグによるコンテナカスタマイズ-
30
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 31.
コンフィグファイル
2012/10リリース
EC2内の環境(コンテナ)をカスタマイズするための機能
2012/12現在、.NETではご利用頂けません。
アプリケーションリポジトリ内にyamlにて定義
• /.ebextensions/*.config
• ファイルは複数配置可能。ファイルは名前の順に処理される
• リポジトリ内に配置するのでgit等での管理も容易
packages:
yum:
postfixをインストールして postfix: '2.6.6'
特定のシェルスクリプトを実行する例
commands:
01prepare:
command: “scripts/prepare.sh”
31
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 32.
コンフィグファイルで実行可能な操作
Packages
• yumやrpmを利用したパッケージのインストール
Sources
• 外部からのアーカイブ(tarなど)をダウンロードして指定した場所に展開する
Files
• 任意の場所にファイルを生成して配置する
• ファイルの内容は外部からダウンロードする
Users
• 任意のユーザーを作成する
Groups
• 任意のグループを作成する
より詳細な情報は下記から参照してください。
http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/customize-containers.html
32
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 33.
コンフィグファイルで実行可能な操作
Commands
• 任意のコマンド・プログラムを起動する
Container commands
• リポジトリ内の任意のコマンド・プラグラムを起動する
Services
• serviceを起動したり、起動設定を変更したりする
Options settings
• 環境変数の設定を実施する
• 特定のnamespaceを設定するとコンテナ側の設定を修正することができる。
• namespaceについての参考
http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/comma
nd-options.html
33
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 34.
Elastic Beanstalkの機能紹介
-VPC-
34
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 35.
VPC内へのデプロイ
Elastic Beanstalkアプリケーションは既存のVPCへデプ
ロイすることも可能です。
2012/12現在、.NETでは
ご利用頂けません。
ELBとEC2が別々の
subnetにデプロイされます。
35
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 36.
環境ごとElastic Beanstalk機能比較表
Java、Python、Rubyは新機能に対応済み
言語 コンテナ eb RDS コンフィグ VPC
Java Tomcat6, ○ ○ ○ ○
Tomcat7
.NET IIS7.5, IIS8 ○
PHP Apache + ○ ○ ○ ○
mod_php
Python Apache + ○ ○ ○ ○
mod_wsgi
Ruby Nginx + ○ ○ ○ ○
Passenger
36
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 37.
Agenda
Elastic Beanstalkとは?
• Elastic Beanstalkの概要
• 最近のアップデート、追加された機能をご紹介
仕組み
• 技術的な仕組みを解説
Python環境について
• Python利用に特化した環境関連など
開発ワークフロー
• 具体的な開発からデプロイ、環境アップデートなどのワークフ
ロー
37
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 38.
PythonでElastic Beanstalk
以下のような環境が立ち上がります。
Application
Instance Amazon RDS
(オプション)
Elastic Load
Balancer
ログ集約
(オプション)
Instance Amazon S3
Auto scaling Group
Email Amazon
Notification CloudWatch
Apache+mod_wsgi
supervisord
38
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 39.
アプリケーションサーバの構成
supervisord
• apacheはsupervisordから起動され、プロセス監視されていま
す。
• 設定ファイルのパスは下記のとおりです。
• /opt/python/etc /supervisord.conf
apache
• /etc/httpd/conf/httpd.confで動いています。
• mod_wsgi経由で/opt/python/current/app/application.pyを
起動しています。(パスはデフォルト)
• アプリケーションのパスは、コンフィグファイルで指定できま
す。(httpd.confの内容が書き換わります)
39
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 40.
WEBアプリケーションフレームワークの利用
現在、下記の2つのWAFがテスト済みです。
• Django
• http://docs.amazonwebservices.com/elasticbeanstalk/latest/
dg/create_deploy_Python_django.html
• Flask
• http://docs.amazonwebservices.com/elasticbeanstalk/latest/
dg/create_deploy_Python_flask.html
もちろん、PyramidなどのWAFも動きます。
40
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 41.
pipによる依存モジュールのインストール
アプリケーションが依存するモジュールをインストール
• コード内で利用しているpythonの各種モジュールをリポジトリ
のトップレベルにrequirements.txtというファイル名で記述し
ておくことにより、それらのモジュールをデプロイ時にインス
トールしてくれます。
Django==1.4.1
pip freezeを使うと簡単に作成可能です。
$ pip install Django
$ pip install xxx
$ pip freeze > requirements.txt
41
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 42.
コンフィグファイルとpipの棲み分け
pipはpythonのモジュールインストール。コンフィグ
ファイルはそれ以外。
スコープ:コンテナ(サーバー)グローバル
→ コンフィグファイル
スコープ:python環境
→ pip
42
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 43.
RDSの利用方法
RDSの各種情報・設定値
• 環境内に構築されたRDSの各種情報には、環境変数からアクセ
スできます。
• http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/create_
deploy_Python.rds.html#create_deploy_Python.rds.newDB
43
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 44.
Agenda
Elastic Beanstalkとは?
• Elastic Beanstalkの概要
• 最近のアップデート、追加された機能をご紹介
仕組み
• 技術的な仕組みを解説
Python環境について
• Python利用に特化した環境関連など
開発ワークフロー
• 具体的な開発からデプロイ、環境アップデートなどのワークフ
ロー
44
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 45.
Djangoアプリケーションをデプロイしてみる
Djangoを使ったウェブアプリケーションをElastic
Beanstalk上にデプロイしてみます
• 下記の手順をベースにしています。
http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/create_
deploy_Python_django.html
• 今回つかったコードは下記にアップロードしました。
https://github.com/imaifactory/elasticbeanstalk-python-django
45
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 46.
Djangoアプリケーションをデプロイしてみる
1. djangoアプリケーションを作成する
django_testという名前でプロジェクトを作成します。
$django-admin.py startproject django_site
2. gitのリポジトリ初期化
$cd django_site
$git init
46
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 47.
Djangoアプリケーションをデプロイしてみる
3. ebにてElastic Beanstalkアプリとして初期化
$eb init
eb initコマンドを発行すると、対話形式で以下の項目が聞かれます。
1. AWSアクセスキー
2. AWSシークレットキー
3. 利用リージョン
4. コンテナ環境
5. RDS設定(コンテナにJava, Python, Rubyを選択した場合)
47
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 48.
Djangoアプリケーションをデプロイしてみる
3. ebにてElastic Beanstalkアプリとして初期化
eb initコマンドが完了すると以下のようなファイルが出来上がって
きます。
$vi .elasticbeanstalk/config
1 AwsCredentialFile=/home/ec2-user/.elasticbeanstalk/aws_credential_file
2 ApplicationName=django_site
3 EnvironmentName=djangosite-env
4 Region=ap-northeast-1
5 ServiceEndpoint=https://elasticbeanstalk.ap-northeast-1.amazonaws.com
6 RdsEndpoint=https://rds.ap-northeast-1.amazonaws.com
7 SolutionStack=64bit Amazon Linux running Python
8 RdsEnabled=Yes
9 RdsSourceSnapshotName=
10 RdsDeletionPolicy=Snapshot
48
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 49.
Djangoアプリケーションをデプロイしてみる
4. ebでアプリケーション環境を立ち上げる
$eb start
数分~10分ほど時間がかかります。eb statusというコマンドか、マネー
ジメントコンソールで状況が確認できます。完了すると、以下のような
WEB画面を表示するアプリケーションが動くようになっています。
現状、サンプルアプリケー
ションが動いている状態な
ので、これからdjangoアプ
リをデプロイしていきます。
49
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 50.
Djangoアプリケーションをデプロイしてみる
5. 環境変数を設定するコンフィグファイルを作成
.ebextensionsというディレクトリを作ってその中に
django_sample.configというファイルを作ります。
$mkdir .ebextensions
$vi .ebextensions/django_sample.config
1 option_settings:
2 - namespace: aws:elasticbeanstalk:container:python
3 option_name: WSGIPath
4 value: django_site/wsgi.py
5 - option_name: DJANGO_SETTINGS_MODULE
6 value: django_site.settings
• ファイル名は拡張子が.configであればなんでも構いません。アルファ
ベット順にすべてのファイルが処理されます。
• WSGIPathという環境変数に、
aws:elasticbeanstalk:container:pythonというnamespaceを付けて
設定することにより、apacheのアプリのパスがここに設定されます。
50
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 51.
Djangoアプリケーションをデプロイしてみる
6. requirements.txtを作成
$pip freeze > requirements.txt
ここで作成したrequirements.txtに記載されているものがElastic
Beanstalkの環境でも自動的にインストールされます。
7. アプリケーションをコミットしてpush
$git add ./*
$git commit -a -m ‘first commit’
$git aws.push
51
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 52.
Djangoアプリケーションをデプロイしてみる
8. こんな画面が表示されたらOK!
URLはマネージメントコンソールもしくは
eb statusで確認可能です。
52
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 53.
TIPS
53
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 54.
TIPS
SSHでのログイン
• SSHでEC2にログインするにはマネジメントコンソールなどで
keypairの設定をしてあげて下さい。
AMIのカスタマイズ
• コンフィグファイルやpip以外の環境カスタマイズの方法として、
AMIを自分でカスタマイズすることも可能です。
• 環境カスタマイズについては、コンフィグ, pip, AMIなどいろい
ろな方法で実現可能ですが、どれが良い、どれがベストプラク
ティスというのはありませんので、それぞれご自分の環境で使
いやすい方法をとってください。
54
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 55.
TIPS
継続的なコードデプロイ
• 今回ご紹介した一連のデプロイの流れはアプリケーションの初
期化から始まっていますが、一旦環境を作ったあとは、コード
を修正してgit aws.pushすれば新しいコードがデプロイされて
いきます。
55
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 56.
TIPS
VPC内へのデプロイ
• Elastic BeanstalkはVPC内へのデプロイも可能です。
• 手順的には、以下のものを事前に作った上でそれをコンフィグ
ファイルに設定してデプロイします。
• VPC
• ELB用subnet
• EC2用subnet
• NATインスタンス
• RDS用subnet(option)
• 参考:
http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/AWSHowTo-vpc-
basic.html
56
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 57.
まとめ
57
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
- 58.
まとめ
Beanstalkを使うとWEBアプリケーションの開発/デプ
ロイが容易。
RDSやVPCなどの他のAWSのサービスとの連携も容易。
注意点としては、言語ごとに利用できる機能に差異があ
ること。
簡単に使うことも可能ですが、非常に柔軟な環境カスタ
マイズも可能!
58
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.