Location via proxy:
[ UP ]
[Report a bug]
[Manage cookies]
No cookies
No scripts
No ads
No referrer
Show this form
Submit Search
Submit Search
Upload
[AWSマイスターシリーズ] AWS Elastic Beanstalk
•
27 likes
•
15,727 views
Amazon Web Services Japan
Follow
Report
Share
Report
Share
1 of 65
Download now
Download to read offline
More Related Content
[AWSマイスターシリーズ] AWS Elastic Beanstalk
1.
re:G ene AWS マイスターシリーズ rate AWS
ElasticBeanstalk アマゾン データサービス ジャパン株式会社 ソリューションアーキテクト 安川 健太 © 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 ! AWS
Elastic Beanstalkとは? • Elastic Beanstalkの概要と⽤用語説明 ! 開発ワークフローに沿った各種機能紹介 • デプロイ • ログの確認や監視、Auto Scalingの設定 • 環境の追加とスワッピング ! Advanced Tips • VPCへのデプロイ • 設定ファイルによるコンテナカスタマイズ • 他サービスとの連携 ! まとめ 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.
AWS ElasticBeanstalk: 構築・デプロイの⾃自動化サービス Instance WAR deploy! Instance CloudWatch Java Python Amazon
RDS Elastic Load Balancer PHP .NET Auto scaling Group Ruby nodeJS 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.
AWSの構築・デプロイ⾃自動化サービスの 中での位置づけ 導入の容易さ Elastic Beanstalk OpsWorks CloudFormation フレキシビリティ 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.
ElasticBeanstalkの論論理理構成 Application Environment URL Environment Configuration Environment URL Environment Configuration Version Respository WAR/ZIP WAR/ZIP WAR/ZIP Environment URL Environment
Configuration WAR/ZIP Configuration Template 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.
各環境の中には ! ⾃自動で構築された⾼高可⽤用構成 !
カスタマイズも容易易 • SSHでログイン, パッケージ追加 • AMIも差替え可 Application Environment URL Environment Configuration AMI Admin AWS Management Console Instance Users Elastic Load Balancer Amazon RDS SSH Instance CloudWatch Auto Scaling Group Developer WAR 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.
Single Instance 環境もサポート Environment URL Management Console SNS HM EC2 eclipse CloudWatch S3 AutoScaling ELBを使わないので省コスト •
開発環境・ElasticBeanstalk自体の動作の確認などに • 小規模なAPIサーバなどにも 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.
⽤用語説明 ! Application •
トップレベルの論論理理単位 • Applicationの中に、EnvironmentやVersionが⼊入る • デプロイするアプリケーション(WAR/ZIPファイル)と混同し やすいので注意 ! Environment • アプリをデプロイする環境 • 環境毎にURLが付与される • URLは、XXX.elasticbeanstalk.com • 各環境毎にEC2、ELBなどが⽴立立ち上がる • ログも環境毎に取得できる(1時間おきにS3へ送信可能) 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.
⽤用語説明 ! Version • • • • Webアプリケーションのバージョン管理理 アプリケーションファイルの履履歴管理理が可能 S3上でファイルを保持 Versionで管理理したWAR/ZIPファイルを、各Environmentと紐紐 付け 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.
サポートするアプリケーションコンテナ ! 使⽤用可能な⾔言語/環境 Java Python PHP .NET Ruby 言語 コンテナ Java Apache
+Tomcat6, Apache+ Tomcat7 .NET IIS7.5, IIS8 PHP Apache + mod_php Python Apache + mod_wsgi Ruby Nginx + Passenger Node.js nodeJS Nginx / Apache + node.js 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.
環境の作成や操作の⽅方法 ! マネージメントコンソール !
各種IDE マネージメントコンソール • Eclipse à Javaアプリのデプロイに対応 • VisualStudio à .Netアプリのデプロイに対応 ! AWS SDK Eclipse • Java, PHP, Ruby, Python, .Net … ! AWS CLI $ aws elasticbeanstalk … ! コマンドラインツール eb 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.
eb: CLIでElasticBeanstalk環境を操作 !
eb init § アプリケーションの初期設定 ! eb start § アプリケーション環境の開始 ! eb status § ステータスの確認 ! eb update § アプリケーション環境の設定更更新 ! eb stop § アプリケーション環境の停⽌止 ! eb delete § アプリケーションの削除 © 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.
ebによるライフサイクル管理理 ローカルに設定 ファイルを⽣生成 eb init アプリケーションの作成 環境の起動 • インスタンス起動 •
ELB設置 • Autoscaling設定 eb update eb start Configuration Created Launching eb delete Ready eb stop eb delete Updating eb start Terminating アプリケーションの 削除 各種構成変更更, e.g.: • インスタンスタイプ変更更 • Autoscaling設定変更更 Not Running 環境の停⽌止 • インスタンスの破棄 • ELBの破棄 (アプリケーションは残る) © 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.
Agenda ! Elastic
Beanstalkとは? • Elastic Beanstalkの概要と⽤用語説明 ! 開発ワークフローに沿った各種機能紹介 • デプロイ • ログの確認や監視、Auto Scalingの設定 • 環境の追加とスワッピング ! Advanced Tips • VPCへのデプロイ • 設定ファイルによるコンテナカスタマイズ • 他サービスとの連携 ! まとめ 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.
開発フローに沿った各種機能紹介 ! ! ! ! ! ! ! アプリケーションの作成 コードのデプロイ 環境変数の設定 ログの確認 負荷のモニタリング Auto Scalingの設定 環境の追加とスワッピング 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.
アプリケーションと環境の作成 開発プラットフォームを選択 16 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.
アプリケーションと環境の作成 環境の構成が終わるのを待つ 経過表示 17 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.
アプリケーションと環境の作成 ! 初期バージョンにアクセス Click 18 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.
アプリケーションと環境の作成 ! デプロイされたサンプルアプリケーションを確認 19 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.
コードのデプロイ ! ⼤大きく分けて2種類 •
WARやZIPなどのアーカイブをアップロード • GitでPush ! いずれにせよS3にアーカイブが作られ、各インスタンスはそれをダ ウンロードしてデプロイ作業を⾏行行う コード WAR/ZIP Developer デプロイ 指示 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.
ZIPやWARをアップロード ! マネージメントコンソールから 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.
ZIPやWARをアップロード ! 各種IDEから VisualStudio Eclipse 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.
Gitでコードをデプロイ 〜~準備編〜~ ! ElasticBeanstalkのCLIツールをダウンロード • 下記URLから最新版のURLを取得 •
http://aws.amazon.com/code/6752709412171743 • ダウンロードと解凍(下記例例ではVersion 2.5.1) $ wget https://s3.amazonaws.com/elasticbeanstalk/cli/AWS-ElasticBeanstalkCLI-2.5.1.zip $ unzip AWS-ElasticBeanstalk-CLI-2.5.1.zip 23 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.
Gitでコードをデプロイ 〜~プロジェクトセットアップ編〜~ ! プロジェクトを作成して初期化 $
mkdir ebapp # rails なら rails new ebapp $ cd ebapp $ git init ! AWS Dev Toolを使ってデプロイに関するコンフィグ • スクリプトを⾛走らせてgit の拡張コマンドをインストール $ ~/AWS-ElasticBeanstalk-CLI-2.5.1/AWSDevTools/Linux/AWSDevTools-RepositorySetup.sh • aws.configコマンドでデプロイに関するコンフィグを設定 24 $ git aws.config AWS Access Key: AKIXXXXXXXXXXXXXXXX AWS Secret Key: zGt9B9XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX AWS Region [default to us-east-1]: ap-northeast-1 AWS Elastic Beanstalk Application: My First Elastic Beanstalk Application AWS Elastic Beanstalk Environment: Default-Environment 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.
Security Credentialsの取得 !
作成したIAMユーザの権限を設定 25 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.
Security Credentialsの取得 26 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.
Gitでコードをデプロイ 〜~実施編〜~ ! Git でローカルレポジトリに変更更をコミット $
git add . $ git commit -m "initial commit" ! Beanstalkの環境にコードをデプロイ $ git aws.push Counting objects: 3, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 306 bytes, done. Total 3 (delta 0), reused 0 (delta 0) remote: To https://AKIA.... * [new branch] HEAD -> master 27 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.
更更新されたコードのデプロイを確認 更新が完了するとステータスが 再びグリーンに 28 Running Versionも更新される © 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
29.
バージョンレポジトリの確認 1. Running Version下のUpload
and Deployをクリック バージョンタブを選択 2. All Versionsをクリック 29 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.
バージョンレポジトリの確認 アップロードした全バー ジョンのアーカイブが保存 されている 任意のバージョンを選 択して任意の環境にデ プロイ可能 30 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.
ここまでに出来上がった構成 Application Default Environment URL Environment Configuration サンプルアプリケーション Version WAR/ZIP … WAR/ZIP http://Default-EnvironmentXXXXXX.elasticbeanstalk.com 最後にデプロイした バージョン 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.
RDSインスタンスの追加と参照 ! RDSインスタンスを環境に紐紐づ けて作成可能 !
RDSインスタンスへの接続情報 は環境変数に⾃自動で設定される production: adapter: mysql2 encoding: utf8 database: <%= ENV['RDS_DB_NAME'] %> username: <%= ENV['RDS_USERNAME'] %> password: <%= ENV['RDS_PASSWORD'] %> host: <%= ENV['RDS_HOSTNAME'] %> port: <%= ENV['RDS_PORT'] %> Instance Amazon RDS Elastic Load Balancer Instance CloudWatch Auto scaling Group 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.
環境設定:S3へのログローテーション ! S3へのログのローテーションを設定 •
S3へのアクセスに⽤用いるIAM Roleを設定 • ログのローテーションを有効化 ログ 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.
環境設定:環境変数の設定 ! 任意の環境変数を設定可能 •
設定した値は環境変数としてアプリケーションから参照可 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.
負荷のモニタリング メトリクス のサマリ 項目追加 も可能 各グラフは クリックで 詳細表示に 35 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.
CPU負荷の詳細表⽰示例例 Auto Scalingの閾値 インスタンスの追加 36 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.
Auto Scalingの設定 !
Scalingに関する設定画⾯面を開く 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.
Auto Scalingの設定投⼊入 !
CPU負荷でスケールアウト・インする設定の例例 画面下までスクロール 変更 à CPUUtilization 変更 à Percent 変更 à 70 変更 à 30 38 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.
イベントログの確認 39 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.
環境の追加 Create New Environmentをクリック ウィザードに従うことで新しい環境を作成 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.
環境のスワッピング ステージング環境を本番環境に移行する場合など DNSの切り替えにより実施される 41 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.
環境のスワッピング 入れ替え元 入れ替え先 42 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.
環境スワップが実⾏行行されたことを確認 今までStaging環境についていたURLが Default-Environmentに 今までDefault-Environmentについていた URLがStaging-Environmentに 43 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.
Route53を使えば柔軟な移⾏行行や併⽤用も可 ! DNSの切切り替えでリクエストを新環境へ移⾏行行 !
その際、Weighted Round Robinを使えば任意の⽐比率率率で徐々に移 ⾏行行可 Weighted Transitionパターン Route 53 Old Environment 44 Auto scaling Group New Environment Auto scaling Group © 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.
ここまでに出来上がった構成 Application Default Environment URL Environment Configuration サンプルアプリケーション Version WAR/ZIP … http://Default-EnvironmentXXXXXX.elasticbeanstalk.com Staging
Environment URL WAR/ZIP 新たにデプロイしたバー ジョン Environment Configuration 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.
eb + gitでコマンドラインのみで開発 ! ElasticBeanstalk⽤用CLIであるebとGitを⽤用いるとコマンドライ ンのみで開発からデプロイまで実⾏行行可 §
プロジェクトディレクトリの作成と初期化 $ $ $ $ mkdir project cd project git init eb init # AWSのCredential、リージョン、コンテナ等を設定 § アプリケーションの開始 $ eb start # 設定内容に従ってアプリケーション環境が起動 § アプリケーション環境の状態確認 $ eb staus # StatusがReadyになれば起動完了了 § コードをデプロイ $ git aws.push # コンテナのカスタマイズ、コードのデプロイが実⾏行行される © 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.
eb + gitでコマンドラインのみで開発 !
eb branchコマンドでgitブランチごとにデプロイ先環境 を設定する事も § 新しいgitブランチを作成 $ git checkout –b new_branch Switched to a new branch 'new_branch' § new_̲branch⽤用の環境を作成(環境設定を引き継ぎ) $ eb branch The current branch is "new_branch". Enter an AWS Elastic Beanstalk environment name (auto-generated value is “sample-newbranch-env"): Do you want to copy the settings from environment "nodesample-env" for the new branch? [y/n]: y § new_̲branch⽤用の新環境をスタート $ eb start Starting application "sample". Waiting for environment "sample-newbranch-env" to launch. 2013-10-08 08:12:59 INFO createEnvironment is starting. … © 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.
Agenda ! Elastic
Beanstalkとは? • Elastic Beanstalkの概要と⽤用語説明 ! 開発ワークフローに沿った各種機能紹介 • デプロイ • ログの確認や監視、Auto Scalingの設定 • 環境の追加とスワッピング ! Advanced Tips • VPCへのデプロイ • 設定ファイルによるコンテナカスタマイズ • 他サービスとの連携 ! まとめ 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.
Advanced Tips -‐‑‒VPCへのデプロイ-‐‑‒ 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.
VPC内へのデプロイ ! Elastic
BeanstalkアプリケーションはVPCへデプロイ可(*) • VPCは要別途作成 ! ELBとEC2が別々の subnetにデプロイされる • VPCの参考例例 http://docs.aws.amazon.com/ elasticbeanstalk/latest/dg/ AWSHowTo-vpc-basic.html (*) 2013年4月に.NETコンテナもVPC対応。 Legacyコンテナを除く 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.
マネージメントコンソールで デプロイ先サブネットを選択 ! 設定時の注意 •
ELB, EC2は各AZに1つ サブネットが必要 • ELBとEC2は異異なる サブネットが必要 • RDSは最低2つの サブネットが必要 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.
Advanced Tips -‐‑‒コンフィグファイルによる環境カスタマイズ-‐‑‒ 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.
コンフィグファイル ! アプリケーションコンテナをカスタマイズ •
独⾃自AMIを⽤用いなくても必要なコンポーネントの追加が可能に ! アプリケーションリポジトリ内に下記の形式で配置 • /.ebextensions/*.config • ファイルは複数配置可能。ファイルは名前の順に処理理される • リポジトリ内に配置するのでgit等での管理理も容易易 yumでgitをインストールしつつ、 特定のシェルスクリプトを実行する例 packages: yum: git: [] commands: 01prepare: command: “scripts/prepare.sh” 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.
コンフィグファイルで実⾏行行可能な操作 ! packages •
yumやrpmを利利⽤用したパッケージのインストール ! sources • 外部からのアーカイブ(tarなど)をダウンロードして指定した場所に展開 ! files • 指定した場所にファイルを作成 • 外部からのダウンロードしたファイルの配置も可 ! services • serviceを起動したり、起動設定を変更更したりする ! users/groups • 任意のユーザー/グループを作成 詳細情報: http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/customize-‐‑‒containers.html 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.
コンフィグファイルで実⾏行行可能な操作 ! commands •
デプロイ処理理前に実⾏行行すべきコマンドやスクリプトを指定 • 例例:OSやミドルウェアの設定変更更 ! container_̲commands • 新バージョンの展開後に実⾏行行すべきコマンドやスクリプトを指定 • 例例:アプリ内のリソースや設定の環境に応じた変更更など ! option_̲settings • 環境変数の設定 ! Resources • 追加のリソースを定義 • 例例: SQSのキュー、DynamoDBのテーブル、CloudWatchのアラーム 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.
コンフィグ例例ファイル例例 1 !
例例:サーバ監視のためにNew Relicエージェントを インストール .ebextensions/01newrelic.config packages: yum: newrelic-sysmond: [] rpm: newrelic: http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelicrepo-5-3.noarch.rpm commands: configure_new_relic: command: nrsysmond-config --set license_key=XXXXX 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.
コマンド実⾏行行の設定に関する詳細 ! CommandsとContainer
Commandsの違い Commands Container Commands 実行タイミング デプロイ直後、バージョン 更新前 更新バージョンのセット アップ後、切り替え直前 コンテナ環境変数の 自動読み込み 無し 有り leader_onlyフラグの 無し サポート 有り container_commands: leader_only_command: command: <command to run> leader_only: true every_node_command: command: <command to run> Leader 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.
デプロイ時のコマンド実⾏行行順序 ! コンフィグファイルで指定したコマンドと デプロイフックが下記の順序で実⾏行行される 1. コンフィグファイルの”commands” 2. /opt/elasticbeanstalk/hooks/appdeploy/pre/* à新バージョン有効化に先⽴立立って⾏行行う処理理 (アセットのコンパイルやDBのマイグレーションなど) 3. コンフィグファイルの”container_̲commands” 4. /opt/elasticbeanstalk/hooks/appdeploy/enact/* à新バージョン有効化時に⾏行行うべき処理理 (バージョンの差し替えとアプリケーションサーバの再起動など) 5. /opt/elasticbeanstalk/hooks/appdeploy/post/* àデプロイ後に⾏行行うべき処理理 (バックグラウンドワーカーの起動など) 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.
59.
コンフィグ例例ファイル例例 2 !
例例:コンパイル済みアセットをダウンロードしてデプロ イ時間を短縮 files: "/opt/elasticbeanstalk/hooks/appdeploy/pre/01a_bootstraup.sh": mode: "000755" owner: root group: root content: | #!/usr/bin/env bash cd /var/app/ondeck/public s3cmd get s3://mybucket/assets.tgz tar xvzf assets.tgz 59 © 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.
60.
コンフィグ例例ファイル例例 3 !
例例:デプロイ後に実⾏行行されるフックを利利⽤用してバックグ ラウンドワーカーを動かす files: "/opt/elasticbeanstalk/hooks/appdeploy/post/99_start_resque_worker.sh": mode: "000755" owner: root group: root content: | #!/usr/bin/env bash . /opt/elasticbeanstalk/support/envvars cd $EB_CONFIG_APP_CURRENT if [ -e /var/run/resque.pid ]; then kill `cat /var/run/resque.pid` fi chown $EB_CONFIG_APP_USER /var/run/resque.pid su -c "PIDFILE=/var/run/resque.pid BACKGROUND=yes RAILS_ENV=production QUEUE=default bundle exec rake environment resque:work" $EB_CONFIG_APP_USER 60 © 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.
61.
Advanced Tips -‐‑‒他サービスのリソースを環境ごとに作成-‐‑‒ 61 © 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.
62.
他サービスのリソースを定義する例例 ! コンフィグファイルのResourcesセクションに定義 Resources:
<name of resource>: Type: <resource type identifier> Properties: <property name>: <value> ! サポートするサービス • • • • • DynamoDB ElastiCache SQS SNS CloudWatch 注:デプロイするユーザに各サービスを 操作する権限が必要 62 © 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.
63.
例例:DynamoDBのテーブルの作成と参照 .ebextensions/sessiontable.config Resources: SessionTable:
Type: AWS::DynamoDB::Table Properties: KeySchema: HashKeyElement: AttributeName: "username" AttributeType: "S" ProvisionedThroughput: ReadCapacityUnits: 1 WriteCapacityUnits: 1 files: "/var/app/support/sessiontable": mode: "000444" content: | `̀{"Ref" : "SessionTable"}`̀ `̀{"Ref" : "AWS::Region"}`̀ 63 リソースタイプ識別子 リソースのプロパティを設定 (リソースタイプごとにプロパティは異なる) Ref演算子を使った参照 Fn::GetAtt, Fn::Join などの演算子や、 CloudFormationで定 義された変数も利用可 © 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.
64.
Agenda ! Elastic
Beanstalkとは? • Elastic Beanstalkの概要と⽤用語説明 ! 開発ワークフローに沿った各種機能紹介 • デプロイ • ログの確認や監視、Auto Scalingの設定 • 環境の追加とスワッピング ! Advanced Tips • VPCへのデプロイ • 設定ファイルによるコンテナカスタマイズ • 他サービスとの連携 ! まとめ 64 © 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.
65.
まとめ ! ElasticBeanstalkを使えばアプリケー ション環境の構築やデプロイを⾃自動化 可能 !
他のAWSのサービスとの連携も充実 ! 設定ファイルを⽤用いれば柔軟な環境カ スタマイズも可 環境構築やデプロイはElasticBeanstalkに任せて Happy Coding! 65 © 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.
Download now