38
ナウなヤングにCloudFormation流行ってほしい 菅原 元気

ナウなヤングにCloud Formationが流行ってほしい

Embed Size (px)

Citation preview

Page 1: ナウなヤングにCloud Formationが流行ってほしい

ナウなヤングにCloudFormationが流行ってほしい

菅原元気

Page 2: ナウなヤングにCloud Formationが流行ってほしい

注意

『おめぇCloudFormationわかってねぇよ!』

というかたは、後学のため、後ほど詰めにきてください(煽ってません)

Page 3: ナウなヤングにCloud Formationが流行ってほしい

自己紹介

菅原元気

@sgwr_dts / id:winebarrel

https://bitbucket.org/winebarrel

https://github.com/winebarrel

白金台の方から来ました

Page 4: ナウなヤングにCloud Formationが流行ってほしい
Page 5: ナウなヤングにCloud Formationが流行ってほしい

例の界隈で出てくるソフトウェア

• Docker

• Vagrant

• Serf

• ...etc

Page 6: ナウなヤングにCloud Formationが流行ってほしい

CloudFomationはないの...?

Page 7: ナウなヤングにCloud Formationが流行ってほしい

CloudFormationとは

• EC2やELBなどを使ったAWSサービスのシステム構築

を、設定ファイル(テンプレート)を元に行えるサー

ビス

• テンプレートを自由に作成できるため、自分好みのシステム構成が可能

• テンプレートは、AWSのサービスを操るための新しい

言語

([AWSマイスターシリーズ] AWS CloudFormationより引用)

Page 8: ナウなヤングにCloud Formationが流行ってほしい

CloudFormationとは

Infrastructure as Code!

DockerやVagrantと同じでコンテキストで

語られていい気がする…

Page 9: ナウなヤングにCloud Formationが流行ってほしい

しかし…

ナウなヤングにはウケそうもない…

Page 10: ナウなヤングにCloud Formationが流行ってほしい

1. JSON{

"AWSTemplateFormatVersion" : "2010-09-09",

"Description" : "AWS CloudFormation Sample Template Insoshi_Multi_AZ: Insoshi is an open source social networking platform in Ruby on Rails. This template installs a highly-available, scalable Insoshi deployment using a

multi-az Amazon RDS database instance for storage and using an S3 bucket for photos and thumbnails. It demonstrates using the AWS CloudFormation bootstrap scripts to install the packages and files necessary to deploy

Insoshi, Rails, MySQL and all dependent packages at instance launch time. **WARNING** This template creates one or more Amazon EC2 instances, an S3 bucket, and Amazon RDS database instance and other AWS

resources. You will be billed for the AWS resources used if you create a stack from this template.",

"Parameters" : {

"KeyName": {

"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",

"Type": "String",

"MinLength": "1",

"MaxLength": "255",

"AllowedPattern" : "[¥¥x20-¥¥x7E]*",

"ConstraintDescription" : "can contain only ASCII characters."

},

"DBName": {

"Default": "insoshi",

"Description" : "MySQL database name",

"Type": "String",

"MinLength": "1",

"MaxLength": "64",

"AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",

"ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."

},

"DBUsername": {

"NoEcho": "true",

"Description" : "Username for MySQL database access",

"Type": "String",

Page 11: ナウなヤングにCloud Formationが流行ってほしい

1. JSON

JSONはいい子です!でも

•コメント書けない•ファイル分割できない

Page 12: ナウなヤングにCloud Formationが流行ってほしい

ないわー

Page 13: ナウなヤングにCloud Formationが流行ってほしい

1. JSON

"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [

"#!/bin/bash -v¥n",

"yum update -y aws-cfn-bootstrap¥n",

"# Helper function¥n",

"function error_exit¥n",

"{¥n",

" /opt/aws/bin/cfn-signal -e 1 -r ¥"$1¥" '", { "Ref" : "WaitHandle" }, "'¥n",

" exit 1¥n",

"}¥n",

"# Install Apache Web Server, MySQL and Drupal¥n",

"/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackId" }, " -r WebServer ",

Page 14: ナウなヤングにCloud Formationが流行ってほしい

ないわー

Page 15: ナウなヤングにCloud Formationが流行ってほしい

2. Cloud-Init / cfn-init

Cloud-InitCloud-init is the defacto multi-distribution package that

handles early initialization of a cloud instance.

cfn-initThe cfn-init helper script reads template metadata from

the AWS::CloudFormation::Init key

Page 16: ナウなヤングにCloud Formationが流行ってほしい

2. Cloud-Init / cfn-init

• cfn-initはrpmあります。Ubuntsuもにもインストールできます

o http://aws.amazon.com/developertools/40

26240853893296

• しかし、、、まずCloud-Init / cfn-init入りのAMI作らないといけないの?sshでコマンドたたくだけってできないの?

Page 17: ナウなヤングにCloud Formationが流行ってほしい

ないわー

Page 18: ナウなヤングにCloud Formationが流行ってほしい

3. スタック

• リソース(EC2インスタンスやS3バケット、RDSインスタンスなど)の

集合のこと

• スタック単位でリソースの管理が可能。スタック破棄を実行すると、ス

タックにひもづくリソースを破棄することが可能

• 使用するリソースおよびリソースの構築順は、テンプレートの依存関係で

決定

([AWSマイスターシリーズ] AWS CloudFormationより引用)

Page 19: ナウなヤングにCloud Formationが流行ってほしい

3. スタック

理念は分かる。しかし

• サーバが増えたり減ったりするサービスだと管理しにくい

• スタックとリソースのひも付けは選択できるが、それをテンプレートに書くのは間違ってるだろ!

Page 20: ナウなヤングにCloud Formationが流行ってほしい

ないわー

Page 21: ナウなヤングにCloud Formationが流行ってほしい

4. ツール

AWS CLIはいい子ですよ?http://docs.aws.amazon.com/cli/latest/reference/cloudformation/

でも、いまいちいけてない

Page 22: ナウなヤングにCloud Formationが流行ってほしい

4. ツール

あと、ブログとか「Web GUIからこのように操作します」とか

書いちゃうのはいかがなものかと思う…

Page 23: ナウなヤングにCloud Formationが流行ってほしい

ないわー

Page 24: ナウなヤングにCloud Formationが流行ってほしい

しかし

Page 25: ナウなヤングにCloud Formationが流行ってほしい

CloudFormationには夢がある

※発表者はジョジョ5部を読んだことがありません

Page 26: ナウなヤングにCloud Formationが流行ってほしい

CloudFormationには夢がある

• サーバ群を構築するのは、VagrantやDocker

より直感的でわかりやすい(と思う)

• AWSユーザに関しては本番環境でテンプレートが使える

• CIで!CIで!使える(はず)

Page 27: ナウなヤングにCloud Formationが流行ってほしい

CI?

サーバ群構築を自動化できると

• 可用性のテストを自動化できる(MHAとかLVSとかHeartbeatとか)

• 負荷テストを自動化できる• サービス間連携のテストを自動化できる

Page 28: ナウなヤングにCloud Formationが流行ってほしい

まさに未来

Page 29: ナウなヤングにCloud Formationが流行ってほしい

未来に向かって

がんばってみました

Page 30: ナウなヤングにCloud Formationが流行ってほしい

Kumogata

https://github.com/winebarrel/kumogata

Page 31: ナウなヤングにCloud Formationが流行ってほしい

Kumogata

• CloudFormationの薄いラッパーです

• Ruby DSLを使えます(JSONも使えます)AWSTemplateFormatVersion "2010-09-09"Description (<<-EOS).undent Kumogata Sample Template You can use Here document!EOSParameters do

InstanceType doDefault "t1.micro"Description "Instance Type"Type "String"endendResources domyEC2Instance do

Type "AWS::EC2::Instance"

Page 32: ナウなヤングにCloud Formationが流行ってほしい

Kumogata

• スタックを使うか使わないかは任意(テンプレートに書く必要はない)

• Cloud-Init / cfn-initがなくてもsshでセットアップできます

• 便利CLIが付いてきます

Page 33: ナウなヤングにCloud Formationが流行ってほしい

Demo

Page 34: ナウなヤングにCloud Formationが流行ってほしい

Demo

…は長いので端折ります

See https://github.com/winebarrel/kumogata#demo

Page 35: ナウなヤングにCloud Formationが流行ってほしい

Please try it out!是非!

Page 36: ナウなヤングにCloud Formationが流行ってほしい

Please try it out!是非!…というほどでもないです

Page 37: ナウなヤングにCloud Formationが流行ってほしい

まとめ

• とはいえサーバ群のテンプレート化は夢があります。o 冗長化のテストとか自動化できたらうれしいですよねぇ…

• なのでCloudFormationがナウなヤングに流行ってほしいです

Page 38: ナウなヤングにCloud Formationが流行ってほしい

まとめ

• 誰かテスト部分作ってください!

負荷テストはruby-jmeterでいいかも…