© Copyright 2015, TDC Software Engineering Inc. All rights reserved. 1
AWS-CLI OpsWorksを使ってみよう
第 1 版
AWS-UG CLI#11
島田雄太
© Copyright 2015, TDC Software Engineering Inc. All rights reserved. 2
はじめに
やっていること:自社サービスのインフラ構築と運用
今までいじったもの:<WEB>apache
<AP> tomcat/Jboss
<DB> postgresql/mysql
<監視>nagios/sensu(挑戦中)
<ネットワーク> FW/L3,L2スイッチ など
好きなAWSサービス:route53
AWS歴:一年ちょっと
© Copyright 2015, TDC Software Engineering Inc. All rights reserved. 3
OpsWorksについて
OpsWorks:アプリケーションを容易にデプロイ及び操作出来るツール。(Webサイトより)
主な手順
①スタックの作成
②レイヤーの作成
③Chefレシピの設定
④インスタンスの作成
⇒細かな説明は割愛します。
スタック
レイヤー
レイヤー
レイヤー
LB
WEB/AP
DB
© Copyright 2015, TDC Software Engineering Inc. All rights reserved. 4
OpsWorksについて
自分の考えるOpsWorksの使い方
⇒時間や負荷によってアプリケーションサイズを変更出来る!
⇒これを使って、EC2上で動かすバッチサーバを必要なときだけ起動・停止させて、
コスト削減が出来ないか。
⇒せっかく取り組んでいるCLIで実施しよう!
© Copyright 2015, TDC Software Engineering Inc. All rights reserved. 5
やってみた
①スタックの作成
戻り値
※OpsWorksのEndPointはus-east-1のみ
$ aws opsworks --region us-east-1 create-stack ¥
--name “TEST_Stack01" ¥
--vpc-id "vpc-XXXXXXXX" ¥
--service-role-arn "arn:aws:iam::XXXXXXXXXXXX:role/aws-opsworks-service-role" ¥
--default-instance-profile-arn "arn:aws:iam::XXXXXXXXXXXX:instance-profile/aws-opsworks-ec2-role" ¥
--default-os "Custom" ¥
--hostname-theme "Clouds" ¥
--default-availability-zone "ap-northeast-1c" ¥
--default-subnet-id "subnet-xxxxxxxx" ¥
--configuration-manager "Name=Chef,Version=11.10" ¥
--chef-configuration "ManageBerkshelf=false,BerkshelfVersion=3.1.3" ¥
--stack-region "ap-northeast-1" ¥
--default-ssh-key-name “test_key"
戻り値
{
"StackId": “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
© Copyright 2015, TDC Software Engineering Inc. All rights reserved. 6
やってみた
②レイヤーの作成
$ cat << EOT >> custom-recipe.json
{
"Setup": ["opsworks_initial_setup","ssh_host_keys","ssh_users","mysql::client","dependencies","ebs"],
"Configure": ["ssh_users","mysql::client","agent_version"],
"Deploy": ["deploy::default"],
"Undeploy": [],
"Shutdown": ["opsworks_shutdown::default"]
}
EOT
$ aws opsworks --region us-east-1 create-layer ¥
--stack-id " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx " ¥
--type "custom" ¥
--name “TEST Layer01" ¥
--shortname “test-layer" ¥
--enable-auto-healing ¥
--auto-assign-elastic-ips ¥
--no-auto-assign-public-ips ¥
--custom-recipes file://./custom-recipe.json ¥
--install-updates-on-boot
© Copyright 2015, TDC Software Engineering Inc. All rights reserved. 7
やってみた
戻り値
{
"LayerId": “yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"
}
© Copyright 2015, TDC Software Engineering Inc. All rights reserved. 8
やってみた
③インスタンスの作成
戻り値
$ aws opsworks --region us-east-1 create-instance ¥
--stack-id " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx " ¥
--layer-ids “yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy " ¥
--instance-type "t2.micro" ¥
--auto-scaling-type "timer" ¥
--subnet-id "subnet-xxxxxxxx" ¥
--availability-zone "ap-northeast-1c" ¥
--virtualization-type "hvm" ¥
--os "Custom" ¥
--ami-id "ami-zzzzzzzz" ¥
--architecture "x86_64"
{
"InstanceId": “zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz"
}
© Copyright 2015, TDC Software Engineering Inc. All rights reserved. 9
やってみた
④タイマー用のjsonファイル作成
$ cat << EOT >> time-base.json
{
"Sunday": {
"5": "off"
},
"Monday": {
"5": "off"
},
"Tuesday": {
"5": "off"
},
"Wednesday": {
"5": "off"
},
"Thursday": {
"5": "off"
},
"Friday": {
"8": "on",
“9": "off"
},
"Saturday": {
"5": "off"
}
}
EOT
© Copyright 2015, TDC Software Engineering Inc. All rights reserved. 10
やってみた
⑤タイマーの設定をインスタンスに割り当てる
戻り値
$ aws opsworks --region us-east-1 set-time-based-auto-scaling ¥
--instance-id " zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz " ¥
--auto-scaling-schedule file://./time-base.json
戻り値なし
© Copyright 2015, TDC Software Engineering Inc. All rights reserved. 11
以上になります。
ご清聴ありがとうございました!

OpsWorks aws-cli#11

  • 1.
    © Copyright 2015,TDC Software Engineering Inc. All rights reserved. 1 AWS-CLI OpsWorksを使ってみよう 第 1 版 AWS-UG CLI#11 島田雄太
  • 2.
    © Copyright 2015,TDC Software Engineering Inc. All rights reserved. 2 はじめに やっていること:自社サービスのインフラ構築と運用 今までいじったもの:<WEB>apache <AP> tomcat/Jboss <DB> postgresql/mysql <監視>nagios/sensu(挑戦中) <ネットワーク> FW/L3,L2スイッチ など 好きなAWSサービス:route53 AWS歴:一年ちょっと
  • 3.
    © Copyright 2015,TDC Software Engineering Inc. All rights reserved. 3 OpsWorksについて OpsWorks:アプリケーションを容易にデプロイ及び操作出来るツール。(Webサイトより) 主な手順 ①スタックの作成 ②レイヤーの作成 ③Chefレシピの設定 ④インスタンスの作成 ⇒細かな説明は割愛します。 スタック レイヤー レイヤー レイヤー LB WEB/AP DB
  • 4.
    © Copyright 2015,TDC Software Engineering Inc. All rights reserved. 4 OpsWorksについて 自分の考えるOpsWorksの使い方 ⇒時間や負荷によってアプリケーションサイズを変更出来る! ⇒これを使って、EC2上で動かすバッチサーバを必要なときだけ起動・停止させて、 コスト削減が出来ないか。 ⇒せっかく取り組んでいるCLIで実施しよう!
  • 5.
    © Copyright 2015,TDC Software Engineering Inc. All rights reserved. 5 やってみた ①スタックの作成 戻り値 ※OpsWorksのEndPointはus-east-1のみ $ aws opsworks --region us-east-1 create-stack ¥ --name “TEST_Stack01" ¥ --vpc-id "vpc-XXXXXXXX" ¥ --service-role-arn "arn:aws:iam::XXXXXXXXXXXX:role/aws-opsworks-service-role" ¥ --default-instance-profile-arn "arn:aws:iam::XXXXXXXXXXXX:instance-profile/aws-opsworks-ec2-role" ¥ --default-os "Custom" ¥ --hostname-theme "Clouds" ¥ --default-availability-zone "ap-northeast-1c" ¥ --default-subnet-id "subnet-xxxxxxxx" ¥ --configuration-manager "Name=Chef,Version=11.10" ¥ --chef-configuration "ManageBerkshelf=false,BerkshelfVersion=3.1.3" ¥ --stack-region "ap-northeast-1" ¥ --default-ssh-key-name “test_key" 戻り値 { "StackId": “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }
  • 6.
    © Copyright 2015,TDC Software Engineering Inc. All rights reserved. 6 やってみた ②レイヤーの作成 $ cat << EOT >> custom-recipe.json { "Setup": ["opsworks_initial_setup","ssh_host_keys","ssh_users","mysql::client","dependencies","ebs"], "Configure": ["ssh_users","mysql::client","agent_version"], "Deploy": ["deploy::default"], "Undeploy": [], "Shutdown": ["opsworks_shutdown::default"] } EOT $ aws opsworks --region us-east-1 create-layer ¥ --stack-id " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx " ¥ --type "custom" ¥ --name “TEST Layer01" ¥ --shortname “test-layer" ¥ --enable-auto-healing ¥ --auto-assign-elastic-ips ¥ --no-auto-assign-public-ips ¥ --custom-recipes file://./custom-recipe.json ¥ --install-updates-on-boot
  • 7.
    © Copyright 2015,TDC Software Engineering Inc. All rights reserved. 7 やってみた 戻り値 { "LayerId": “yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" }
  • 8.
    © Copyright 2015,TDC Software Engineering Inc. All rights reserved. 8 やってみた ③インスタンスの作成 戻り値 $ aws opsworks --region us-east-1 create-instance ¥ --stack-id " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx " ¥ --layer-ids “yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy " ¥ --instance-type "t2.micro" ¥ --auto-scaling-type "timer" ¥ --subnet-id "subnet-xxxxxxxx" ¥ --availability-zone "ap-northeast-1c" ¥ --virtualization-type "hvm" ¥ --os "Custom" ¥ --ami-id "ami-zzzzzzzz" ¥ --architecture "x86_64" { "InstanceId": “zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz" }
  • 9.
    © Copyright 2015,TDC Software Engineering Inc. All rights reserved. 9 やってみた ④タイマー用のjsonファイル作成 $ cat << EOT >> time-base.json { "Sunday": { "5": "off" }, "Monday": { "5": "off" }, "Tuesday": { "5": "off" }, "Wednesday": { "5": "off" }, "Thursday": { "5": "off" }, "Friday": { "8": "on", “9": "off" }, "Saturday": { "5": "off" } } EOT
  • 10.
    © Copyright 2015,TDC Software Engineering Inc. All rights reserved. 10 やってみた ⑤タイマーの設定をインスタンスに割り当てる 戻り値 $ aws opsworks --region us-east-1 set-time-based-auto-scaling ¥ --instance-id " zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz " ¥ --auto-scaling-schedule file://./time-base.json 戻り値なし
  • 11.
    © Copyright 2015,TDC Software Engineering Inc. All rights reserved. 11 以上になります。 ご清聴ありがとうございました!