はじめての Elastic Beanstalk Amazon Data Services Japan
Elastic Beanstalk とは AWS 上のベストプラクティス構成を自動作成 コードをデプロイするだけで Web アプリケーションを開始 Instance WAR deploy! Elastic Load Balancer Amazon RDS Instance CloudWatch Auto scaling Group
ElasticBeanstalk の論理構成 Application Environment URL Environment URL Environment URL Environment Configuration Environment Configuration Environment Configuration Version WAR/ZIP WAR/ZIP WAR/ZIP WAR/ZIP WAR/ZIP Configuration Template
各環境の中を覗くと Environment URL この環境が自動で構成されている ElasticLoadBalanceing Manageme nt Console SNS HM HM CloudWatch S3 eclipse EC2 AutoScaling EC2 Security Group
Application アプリケーションの作成
アプリケーションと環境の作成 希望のアプリケーションコンテナを選択して Start を押す 6
アプリケーションと環境の作成 環境の構成が終わるのを待つ 7
アプリケーションと環境の作成 初期バージョンにアクセス Click 8
アプリケーションと環境の作成 デプロイされたサンプルアプリケーションを確認 9
ここまでに出来上がった構成 Application Default Environment URL Environment Configuration Version WAR/ZIP http://default-environment- XXXXXX.elasticbeanstalk.com サンプルアプリケーション
マネージメントコンソールからコードをデプロイ WAR ファイルや ZIP で固めたプロジェクトなど Check バージョンに付ける名前 アップロードするファイルを選択 11
Git でコードをデプロイ ~ 準備編 ~ 作業環境の用意 ( 既にあればスキップ ) EC2 インスタンスを起動 (t1.micro で十分 ) ログインして git をインストール $ sudo yum y install git ElasticBeanstalk の CLI ツールをダウンロード 下記 URL から最新版の URL を取得 http://aws.amazon.com/code/6752709412171743 ダウンロードと解凍 ( 下記例では Version 2.3) $ wget https://s3.amazonaws.com/elasticbeanstalk/cli/aws- ElasticBeanstalk-CLI-2.3.zip $ unzip AWS-ElasticBeanstalk-CLI-2.3.zip 12
Git でコードをデプロイ ~ プロジェクトセットアップ編 ~ プロジェクトを作成して初期化 $ mkdir helloworld $ cd helloworld $ git init AWS Dev Tool を使ってデプロイに関するコンフィグ スクリプトを走らせて git の拡張コマンドをインストール $ ~/AWS-ElasticBeanstalk-CLI-2.3/AWSDevTools/Linux/AWSDevTools-RepositorySetup.sh aws.config コマンドでデプロイに関するコンフィグを設定 $ 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 13
Git でコードをデプロイ ~ 実施編 ~ コードを開発 ローカルでテスト $ cat > index.php <html><head><title>php Test</title></head> <body><?php echo '<h1>hello, World!</h1>';?></body></html> Ctrl+d Git でローカルレポジトリに変更をコミット $ git add index.php $ 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 14
更新されたコードのデプロイを確認 更新が完了するとステータスが再びグリーンに Running Version も更新される 15
各バージョンの一覧を確認 バージョンタブを選択 任意のバージョンを選択してロールバックすることも可能 16
ここまでに出来上がった構成 Application Default Environment URL Environment Configuration サンプルアプリケーション Version WAR/ZIP http://default-environment- XXXXXX.elasticbeanstalk.com WAR/ZIP 最後にデプロイしたバージョン
ステージング環境の追加 環境名 環境に割り当てる URL ( 要 Global Unique) デプロイするバージョンを指定 ( ここでは再びサンプルを選択 ) 18
新環境の初期設定 使用するインスタンスタイプ インスタンスにログインするための SSH キーペア名 ( 任意 ) 19
追加された環境の確認 20
ここまでに出来上がった構成 Application Default Environment URL Environment Configuration サンプルアプリケーション Version WAR/ZIP http://default-environment- XXXXXX.elasticbeanstalk.com Staging Environment WAR/ZIP 新たにデプロイしたバージョン URL Environment Configuration
環境のスワッピング ステージング環境を本番環境に移行する場合など DNS の切り替えにより実施される 入れ替え元 入れ替え先 22
環境スワップが実行されたことを確認 今まで Default-Environment についていた URL が Staging-Environment に 23
ここまでに出来上がった構成 Application Default Environment URL Environment Configuration サンプルアプリケーション Version WAR/ZIP http://default-environment- XXXXXX.elasticbeanstalk.com Staging Environment WAR/ZIP 新たにデプロイしたバージョン URL Environment Configuration