More Related Content Similar to AWS Black Belt Tech シリーズ 2015 - AWS CloudFormation (20) More from Amazon Web Services Japan (20) AWS Black Belt Tech シリーズ 2015 - AWS CloudFormation12. 12
最近のアップデート
日付 主なアップデート
2015/11/4 AWS::EC2::VolumeリソースにおけるAutoEnableIOプロパティサ
ポート
2015/10/1 CodeDeploy, SimpleAD, EC2::PlacementGroup, SpotFleet,
Lambda, CloudWatch Logs, RDS::DBCluster, WorkSpacesの追加
2015/10/1 ElastiCache, OpsWorks, S3, IAM関連のアップデート
2015/10/1 AWS CloudFormation Designerの提供開始
2015/8/24 AWS::EC2::VPCEndpoint の追加。ElasticBeansTalk, Lambda,
OpsWorks, RDS, S3関連のアップデート
2015/8/3 AWS:EFS関連の追加
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/ReleaseHistory.html
20. 20
カテゴリ プロダクト 解説
マイクロソフト Web Application Proxy and ADFS Web Application Proxy および Active Directory Federation
Services (AD FS) を、新規または既存の AWS インフラストラク
チャにデプロイ
Lync Server 2013 小規模または中規模の Microsoft Lync Server 2013 環境を AWS に
構築して、高い可用性と災害対策を実現
Exchange Server 2013 新規または既存の Amazon VPC のいずれかを選択して、可用性の高
い AWS のアーキテクチャにデプロイ
Windows PowerShell DSC Microsoft Windows PowerShell DSC プルサーバーまたはプッシュ
サーバー環境を AWS に構築
SharePoint Server 2013 Microsoft SharePoint Server 2013 を SQL Server AlwaysOn
Availability Groups with WSFC をデータベース層としてデプロイ
SQL Server 2012 and 2014 with
WSFC
Windows Server Failover Clustering (WSFC) と SQL Server
AlwaysOn Availability Groups を活用した高可用性ソリューション
Remote Desktop Gateway リモートデスクトップゲートウェイと RDP による保護されたリモー
ト管理ソリューション
Active Directory Domain Services クラウドのみまたはハイブリッドアーキテクチャを選択可能
2015/11/19現在で提供されている
クイックスタートリファレンス(マイクロソフト)
21. 21
カテゴリ プロダクト 解説
SAP SAP Business One, version
for SAP HANA
SAP Business One の SAP HANA バージョンを、クラウド
の新規または既存の AWS インフラストラクチャにデプロイ
SAP HANA 複数ノードの SAP HANA クラスターを AWS に構築
Trend Micro Deep Security Trend Micro Deep Security 9.5 をデプロイします。このソ
リューションは、新規または既存の AWS インフラストラク
チャ
MongoDB 柔軟でスケーラブル、かつコスト効率の優れた方法で
MongoDB を AWS にデプロイ
Cloudera Enterprise Data
Hub
Cloudera Director と AWS サービスを統合し、複数ノード
の Cloudera Enterprise Data Hub (EDH) クラスターを構
築
Magento Magento Community EditionをAWS上に展開します。
Magentoは、E-コマースWebサイトのためのオープンソース
のコンテンツ管理システムです。
2015/11/19現在で提供されている
クイックスタートリファレンス(SAP, Security,…)
24. 24
テンプレートとスニペット
テンプレート
• Auto Scaling
• Amazon DynamoDB
• Amazon EC2
• Amazon ElastiCache
• AWS Elastic Beanstalk
• Elastic Load Balancing
• AWS Identity and Access Management
• AWS OpsWorks
• Amazon Relational Database Service
• Amazon Redshift
• Amazon Route 53
• Amazon Simple Storage Service
• Amazon Simple Queue Service
• Amazon Virtual Private Cloud
テンプレートスニペット
• 一般的なテンプレートスニペット
• Auto Scaling テンプレートスニペット
• AWS CloudFormation テンプレートスニペット
• Amazon CloudFront のテンプレートスニペット
• Amazon CloudWatch テンプレートスニペット
• Amazon CloudWatch Logs テンプレートスニペット
• Amazon EC2 テンプレートスニペット
• Amazon EC2 Container Service テンプレートスニペット
• Amazon Elastic File System サンプルテンプレート
• Elastic Beanstalk テンプレートスニペット
• Elastic Load Balancing テンプレートのスニペット
• AWS Identity and Access Management のテンプレートスニペット
• AWS Lambda テンプレート
• AWS OpsWorks テンプレートスニペット
• Amazon Redshift テンプレートスニペット
• Amazon RDS テンプレートスニペット
• Amazon Route 53 テンプレートスニペット
• Amazon S3 テンプレートスニペット
• Amazon SNS テンプレートスニペット
• Amazon SQS テンプレートスニペット
http://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/cfn-sample-templates.html
26. 26
AWS CloudFormationがサポートする主なサービス
Amazon EC2
Amazon EC2 Container Service
AWS Lambda (including event sources – New)
Auto Scaling (including Spot Fleet - New)
Amazon VPC
Elastic Load Balancing
Amazon Route 53
Amazon CloudFront
Amazon RDS
Amazon Redshift
Amazon DynamoDB
Amazon ElastiCache
Amazon RDS for Aurora (New)
Amazon S3
AWS IAM (including managed policies)
Simple AD (New)
Amazon Kinesis
Amazon SNS
Amazon SQS
AWS CloudFormation
AWS CloudTrail
Amazon CloudWatch
AWS Data Pipeline
AWS Elastic Beanstalk
AWS OpsWorks
AWS CodeDeploy (New)
Amazon WorkSpaces (New)
http://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html
29. 29
AWS CloudFormation
テンプレートの例③
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources" : {
"HelloBucket" : {
"Type" : "AWS::S3::Bucket",
"Properties" : {
"AccessControl" : "PublicRead",
"WebsiteConfiguration" : {
"IndexDocument" : "index.html",
"ErrorDocument" : "error.html"
}
}
}
}
}
HelloBucketというAmazon S3バ
ケットを作るテンプレート
↓
AccessControlに「PublicRead」
を指定。
↓
Webサイトとして公開するために、
index.htmlと、ErrorDocumentの
設定を行う。
33. 33
スタックの起動方法
• AWS Management Consoleから起動
• コマンドラインツールも利用可能
– AWS Command Line Tool:http://aws.amazon.com/cli/
• 各種SDKでもサポート
– Java : http://aws.amazon.com/jp/sdkforjava/
– .NET : http://aws.amazon.com/jp/sdkfornet/
– PHP : http://aws.amazon.com/jp/sdkforphp/
– Ruby :
http://docs.aws.amazon.com/AWSSdkDocsRuby/latest/DeveloperGuide/ruby-dg-
setup.html
– JavaScript : http://aws.amazon.com/documentation/sdkforjavascript/
– Python : http://docs.pythonboto.org/en/latest/
44. 44
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : “Sample",
"Parameters" : {
"KeyName" : {
"Description" : “Sample key,
"Type" : "String"
}
},
"Mappings" : {
},
"Resources" : {
"Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],
"KeyName" : { "Ref" : "KeyName" },
"ImageId" : { "Fn::FindInMap" : [
"RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]}
}
},
"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable SSH access via port 22",
"SecurityGroupIngress" : [ {
"IpProtocol" : "tcp",
"FromPort" : "22",
"ToPort" : "22",
"CidrIp" : "0.0.0.0/0"
} ]
}
}
}
}
テンプレート
• AWS CloudFormationの心臓部
• スタック構築の設計図
– どのリソースをどう起動するかがすべ
て記述されている
• JSONフォーマットで記述
46. 46
{
"AWSTemplateFormatVersion" : “2010-09-09",
"Description" : "Valid JSON strings up to 4K",
"Parameters" : {
set of parameters
},
"Mappings" : {
set of mappings
},
“Conditions" : {
set of conditions
},
"Resources" : {
set of resources
},
"Outputs" : {
set of outputs
}
}
テンプレートのバージョン
テンプレートの詳細(説明文)
CloudFormation実行時にユーザ入力を求める
パラメータを定義する
(KeyPairの名前や、DBのユーザ名など)
Hashtableのようなもの
キーに応じて値を特定出来る
(例:リージョンに応じたAMI-IDなど)
EC2やRDSなど、スタックを構成する
リソースを定義
スタック構築後にCloudFormationから出力させ
る値(例:DNS名やEIPの値など)
条件名と条件判断内容を登録する。この条件名は
Resourcesなどでリソース作成時に利用できる。
テンプレートの要素
47. 47
{
"AWSTemplateFormatVersion" : “2010-09-09",
"Description" : "Valid JSON strings up to 4K",
"Parameters" : {
set of parameters
},
"Mappings" : {
set of mappings
},
“Conditions" : {
set of conditions
},
"Resources" : {
set of resources
},
"Outputs" : {
set of outputs
}
}
Parameters
CloudFormation実行時にユーザ入力を求める
パラメータを定義する
(KeyPairの名前や、DBのユーザ名など)
48. 48
"Parameters": {
"Age":{
"Type":"Number",
"Default" : "30",
"MinValue": "20",
"MaxValue": "60",
"Description":"input your age."
},
"FirstName":{
"Type":"String",
"Description":"input your first name."
},
"MyKeyName": {
"Description" : "Input your key pair.",
"Type" : "String"
}
},
Parametersとは
• スタック構築時に値を定義することができる
• データ型、デフォルト値、最大最小値など型が設定可能
49. 49
プロパティ 内容
Type データ型 “String” “Number” “CommaDelimitedList”
Default デフォルト値
NoEcho 入力時に*****となる(パスワードなどに使用)
AllowedValues 入力可能値の一覧指定 (例:[“true”,”false”] )
AllowedPattern 正規表現で入力可能パターンを指定(例:[a-zA-Z]*)
MaxLength 最大文字数
MinLength 最小文字数
MaxValue 最大値
MinValue 最小値
Description プロパティの詳細説明
ConstraintDescription 入力した値がAllowedPatternやMaxLengthなどの制約に引っかかった時に表示する説明
(どのような制約があるかの説明を記述)
• 以下のプロパティが利用可能
Parametersのプロパティ
52. 52
http://docs.aws.amazon.com/AWSCloudFormation/latest/
UserGuide/pseudo-parameter-reference.html
疑似パラメータ参照(Pseudo Parameter)
• あらかじめ定義された擬似パラメータ群で“Ref”により参照できる
• 利用可能なパラメータは下記の通り
– AWS::Region → リージョン名を取得
– AWS::StackId → スタックIDを取得
– AWS::StackName → スタック名を取得
– AWS::AccountId → AWSアカウントIDを取得
– AWS::NotificationARNs → notification Amazon Resource Names(ARNs)を取得
– AWS::NoValue → 指定されたプロパティを無視するようCloudFormationに伝える
例)
“Resources" : {
“MyServer":{
“Type":“AWS::EC2::Instance",
“Properties” : {
“KeyName”: { “Ref” : “AWS::StackName”},
“Tags” : { “Ref” : “AWS::Region”}
}}}
"DBSnapshotIdentifier" : {
"Fn::If" : [
"UseDBSnapshot",
{"Ref" : "DBSnapshotName"},
{"Ref" : "AWS::NoValue"}
]}
UseDBSnapshotがTrueのとき
「DBSnapshotIdentifier」としてDBSnapshotNameの値を使う
UseDBSnapshotがFalseのとき
CloudFormationはプロパティ「DBSnapshotIdentifier」が定義され
ていないものとして動作する(=DBSnapshotIdentifierを無視する)
53. 53
{
"AWSTemplateFormatVersion" : “2010-09-09",
"Description" : "Valid JSON strings up to 4K",
"Parameters" : {
set of parameters
},
"Mappings" : {
set of mappings
},
“Conditions" : {
set of conditions
},
"Resources" : {
set of resources
},
"Outputs" : {
set of outputs
}
}
Mappings
Hashtableのようなもの
キーに応じて値を特定出来る
(例:リージョンに応じたAMI-IDなど)
54. 54
"Mappings" : {
"RegionTable" : {
"us-east-1" : {
"AMI" : "ami-8c1fece5“,
“KeyPair” : “myKey-east”
},
"us-west-1" : {
"AMI" : "ami-3bc9997e“,
“KeyPair” : “myKey-west”
},
"ap-northeast-1" : {
"AMI" : "ami-300ca731“,
“KeyPair” : “myKey-japan”
}}},
Mappingsにテーブルの定義を行う
(この例の場合、”RegionTable”という
名称でMappingを定義)
Mappingsとは
• キーと値のマッピングテーブルを管理できる
• リージョンやユーザ入力パラメータによって、値が変わるものに利用
• Mappingsを利用することでテンプレートの再利用性が向上
Regionが”ap-northeast-1”であれば、
AMI IDは”ami-300ca731”でキーペアの
名前は”myKey-japan”とする
Regionが”us-west-1”であれば、AMI ID
は”ami-3bc9997e”でキーペアの名前
は”myKey-west”とする
55. 55
Mappingsの使い方
• Functionの”Find::InMap”を使って値を取得
例)"Fn::FindInMap" : [ "MapName", "Key", "Value"]
• MapName,key,Valueには”Ref”が利用可能
"Mappings" : {
"RegionTable" : {
"us-east-1" : {
"AMI" : "ami-8c1fece5“,
“KeyPair” : “myKey-east”
},
“us-west-1” : {
“AMI” : “ami-3bc9997e“,
“KeyPair” : “myKey-west”
},
"ap-northeast-1" : {
"AMI" : "ami-300ca731“,
“KeyPair” : “myKey-japan”
}
}
},
“Fn::FindInTemplate”
"Parameters": {
“region":{
"Type":"String",
"Description":”input your region selection."
}}
“Resources" : {
“MyServer":{
“Type":“AWS::EC2::Instance",
“Properties” : {
“ImageId”: {
“Fn:FindInMap” : [ “RegionTable” , { “Ref” : “region” },“AMI” ]
},
}
}
}
リージョン名はユーザ入力
入力されたリージョンに合致す
るAMIの値を取得する
ユーザ入力が”ap-northeast-1”の場合、最
終的な戻り値は”ami-300ca731”となる
56. 56
{
"AWSTemplateFormatVersion" : “2010-09-09",
"Description" : "Valid JSON strings up to 4K",
"Parameters" : {
set of parameters
},
"Mappings" : {
set of mappings
},
“Conditions" : {
set of conditions
},
"Resources" : {
set of resources
},
"Outputs" : {
set of outputs
}
}
Conditions
条件名と条件判断内容を登録する。この条件名は
Resourcesなどでリソース作成時に利用できる。
57. 57
"Parameters" : {
"EnvType" : {
"Description" : "Environment type.",
"Default" : "test",
"Type" : "String",
"AllowedValues" : [“production", "test"],
"ConstraintDescription" : "must specify prod or test."
}
},
"Conditions" : {
"CreateProdResources" : {"Fn::Equals" : [{"Ref" : "EnvType"}, “production"]}
},
Conditionsとは
• 条件名と成立条件を列挙
• Resourcesセクションなどで、『ある条件が成立しているときのみリ
ソースを起動』といった条件ベースの制御が可能
• 本番環境と検証環境で構成が異なる場合に便利
EnvTypeパラメータの値が”production”であれ
ば、CreateProdResources条件が成立
パラメータEnvTypeの値は、『production』
『test』のいずれかをユーザが入力する
58. 58
"Resources" : {
"EC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]}
}},
"NewVolume" : {
"Type" : "AWS::EC2::Volume",
"Condition" : "CreateProdResources",
"Properties" : {
"Size" : "100",
"AvailabilityZone" : { "Fn::GetAtt" : [ "EC2Instance", "AvailabilityZone" ]}
}},
“MountPoint” : {
“Type” : “AWS::EC2::VolumeAttachment”,
“Condition” : “CreateProdResources”,
“Properties” : {
“InstanceId” : { “Ref” : “EC2Instance” },
“VolumeId” : { “Ref” : “NewVolume” },
“Device” : “/dev/sdh”
}}}
Conditionsとは
CreateProdResourcesが成立している
ときに限り、本番環境のみに存在する
EBSをアタッチする
CreateProdResourcesが成立している
ときに限り、本番環境のみで利用する
EBSボリュームをプロビジョニング
• Resourcesで”Condition”を指定すると、指定した条件が成立している
場合に限り、そのリソースが起動されるようになる。
59. 59
{
"AWSTemplateFormatVersion" : “2010-09-09",
"Description" : "Valid JSON strings up to 4K",
"Parameters" : {
set of parameters
},
"Mappings" : {
set of mappings
},
“Conditions" : {
set of conditions
},
"Resources" : {
set of resources
},
"Outputs" : {
set of outputs
}
}
Resources
EC2やRDSなど、スタックを構成する
リソースを定義
60. 60
“Resources" : {
"MyInstance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"DisableApiTermination": "FALSE",
"ImageId": "ami-a1b6fda0",
“InstanceType": "t1.micro",
"KeyName": { "Ref": "MyKeyName" } ,
"Monitoring": "false",
}
}
}
• EC2やELB, RDSなど、起動するサービスを指定
• リソースごとに決められたプロパティを設定する
Resourcesとは
リソースタイプの定義
リソースごとのプロパティ
62. 62
Attributes
• リソースの振る舞いや関係を制御する
• DeletionPolicy
– スタック削除時のリソースの扱い(Delete (Default) / Retain / Snapshot)
• DependsOn
– リソース間の依存関係を明示的に記述
• Metadata
• UpdatePolicy
– AWS::AutoScaling::AutoScalingGroupリソースのみ
– Auto ScalingのRolling Updateでの挙動を制御
• MaxBatchSize、MinInstancesInService、PauseTime
63. 63
{
"AWSTemplateFormatVersion" : “2010-09-09",
"Description" : "Valid JSON strings up to 4K",
"Parameters" : {
set of parameters
},
"Mappings" : {
set of mappings
},
“Conditions" : {
set of conditions
},
"Resources" : {
set of resources
},
"Outputs" : {
set of outputs
}
}
スタック構築後にCloudFormationから出力させ
る値(例:DNS名やEIPの値など)
Outputs
65. 65
"Outputs" : {
"InstanceId" : {
"Description" : "InstanceId of the newly created EC2 instance",
"Value" : { "Ref" : "Ec2Instance" }
},
"AZ" : {
"Description" : "Availability Zone of the newly created EC2 instance",
"Value" : { "Fn::GetAtt" : [ "Ec2Instance", "AvailabilityZone" ] }
},
"ApplicationURL" : {
"Description" : "URL of running web application",
"Value" :
{ "Fn::Join": ["", [ "http://", { "Fn::GetAtt": [ "Ec2Instance" , "PublicIp"] } , "/index.html"] ] }
}
}
出力データの名称を定義
説明
値の指定
Functionを使って文字列を加工
Outputsの定義
66. 66
• リソース定義にEC2インスタンスが必須ではない
– DB構築だけ、オートスケールだけ、アラーム設定だけでもOK
• 参照関係があると、依存関係があるとみなされる。相互参照や循環参
照はエラーとなる
• 参照関係がある部分は、参照の整合性が取れるよう起動順を
CloudFormationが決定(Depends onで明示的に指定も可)
• スタックを破棄すると、スタックにひもづくリソースは破棄される
– ただし”DeletionPolicy”を”Retain”にすると破棄されない
テンプレートのTips
"Resources" : {
"myS3Bucket" : {
"Type" : "AWS::S3::Bucket",
"DeletionPolicy" : "Retain"
}}
67. 67
• CloudFormationで生成されたリソースには自動でスタック名などの
タグが付与される
• 管理者がリソースを識別できるよう、明示的なタグの付与を推奨
• テンプレートは入れ子にすることが可能。あるテンプレートから、別
のテンプレートを呼ぶことができる
– リソースタイプに “AWS::CloudFormation::Stack“を指定しURLを指定すると、
そのテンプレートを読み込む
– 呼び出された側に対するParameterの引き渡しや、呼び出し側で呼び出された側の
Outputsを参照することが可能
テンプレートのTips
"Resources" : {
"WebServer" : {
"Type" : "AWS::CloudFormation::Stack",
"Properties" : {
"TemplateURL" : “https://s3.amazonaws.com/hoge.template" ]]},
"Parameters" : {
"KeyName" : { "Ref" : "KeyName" },
"InstanceType" : { "Ref" : "InstanceType"},
}},
88. 88
AWS CloudFormationのヘルパー
• スタックの一部として作成する Amazon EC2 インスタンスでソフトウェ
アをインストールしたりサービスを開始したりするために使用できる
Python ヘルパースクリプトのセットが用意されています。
• cfn-init:
– リソースメタデータの取得と解釈、パッケージのインストール、ファイルの作成、およびサービス
の開始で使用されます。
• cfn-signal:
– AWS CloudFormation CreationPolicy または WaitCondition にシグナルを送信するためのシン
プルなラッパー。スタック内の他のリソースと、準備ができたアプリケーションを同期させること
ができます。
• cfn-get-metadata:
– リソースに対して定義されたすべてのメタデータ、またはリソースメタデータの特定のキーやサブ
ツリーへのパスを簡単に取得できるようにするラッパースクリプト。
• cfn-hup:
– メタデータへの更新を確認し、変更が検出されたときにカスタムフックを実行するデーモン。
http://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/cfn-helper-scripts-reference.html
89. 89
cloud-init (AWS::CloudFormation::Init )
• Amazon Linuxに入っている、初期設定ツール
• EC2インスタンスの起動時に、userdataに記述されたスクリプトを
実行する
– 「#!」 で始まる文字列の場合のみ、スクリプトを実行
• ロケール変更、アプリインストール、ファイル書き換えなどが可能
• RHELでも利用可能
• WindowsではEC2ConfigService
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/cfn-init.html
91. 91
"Resources" : {
"Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"KeyName" : { "Ref" : "KeyName" },
"SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],
"ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["",[
"#!/bin/bash -ex","n",
"yum -y install gcc-c++ make","n",
"yum -y install mysql-devel sqlite-devel","n",
"yum -y install ruby-rdoc rubygems ruby-mysql ruby-devel","n",
"gem install --no-ri --no-rdoc rails","n",
"gem install --no-ri --no-rdoc mysql","n",
"gem install --no-ri --no-rdoc sqlite3","n",
"rails new myapp","n",
"cd myapp","n",
"rails server -d","n",
"curl -X PUT -H 'Content-Type:' --data-binary '{"Status" : "SUCCESS",",
""Reason" : "The application myapp is ready",",
""UniqueId" : "myapp",",
""Data" : "Done"}' ",
""", {"Ref" : "WaitForInstanceWaitHandle"},""n" ]]}}
}
}
EC2InstanceのPropatiesのUserDataを使って、コマンドを実行する方法
EC2起動時のアプリケーション展開とアップデート
97. 97
AWS CloudFormationでの
セキュリティ実装の適用例
Bas
tion
Web Web
NAT
Web Web
Bas
tion
Private
Segment
(Web)
Public
Segment
Log Jump
Private
Segment
(DB)
Protected
Segment
Public Subnet (DMZ) Public Subnet (DMZ)
Private Subnet (Private) Private Subnet (Private)
Private Subnet (Private) Private Subnet (Private)
Private Subnet (Protected) Private Subnet (Protected)
1. S3 BucketPolicyの定義
2. CloudTrailの設定とBucketの設置
3. IAM Groupの作成
4. IAM Userの作成とGroupへ所属
5. VPC作成
6. SG、NACL定義
7. RouteTables定義
8. Subnet作成
- Multi-AZ(2AZ@Tokyo)による冗
長性の確保
- ネットワークのセグメントは
Public、Private、Protectedに分割
9. InternetGatewayの設置
10.RT、NACL、SG割り当て
11.外部接続用にNAT、Proxyサーバー
の設置 Jump
Bas
tion
NAT
98. 98
EC2の設定
{
"Type" : "AWS::EC2::Instance",
"Properties" : {
"AvailabilityZone" : String,
"BlockDeviceMappings" : [ EC2 Block Device Mapping, ... ],
"DisableApiTermination" : Boolean,
"EbsOptimized" : Boolean,
"IamInstanceProfile" : String,
"ImageId" : String,
"InstanceInitiatedShutdownBehavior" : String,
"InstanceType" : String,
"KernelId" : String,
"KeyName" : String,
"Monitoring" : Boolean,
"NetworkInterfaces" : [ EC2 Network Interface, ... ],
"PlacementGroupName" : String,
"PrivateIpAddress" : String,
"RamdiskId" : String,
"SecurityGroupIds" : [ String, ... ],
"SecurityGroups" : [ String, ... ],
"SourceDestCheck" : Boolean,
"SubnetId" : String,
"Tags" : [ EC2 Tag, ... ],
"Tenancy" : String,
"UserData" : String,
"Volumes" : [ EC2 MountPoint, ... ]
}
}
AWS::EC2::Instance
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html
セキュリティ関連設定
EC2をAPIを通じてTerminateさせない
IAMポリシーの付与
SSHキーペアの指定
Security Groupの設定
Tagによる分類
User Dataによる起動処理
Deployする際は複数AZにまたがる展開を考慮
考慮事項
OSより上のレイヤーにおける機能の実装はUser
Dataを用いたcloud-init、cfn-init、もしくはChef等
のツールの利用を検討する
99. 99
Security Groupの設定
{
"Type" : "AWS::EC2::SecurityGroup",
"Properties" :
{
"GroupDescription" : String,
"SecurityGroupEgress" : [ Security Group Rule, ... ],
"SecurityGroupIngress" : [ Security Group Rule, ... ],
"Tags" : [ Resource Tag, ... ],
"VpcId" : String
}
}
AWS::EC2::SecurityGroup
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group.html
{
"CidrIp" : String,
"DestinationSecurityGroupId" : String,
"FromPort" : Number,
"GroupId" : String,
"IpProtocol" : String,
"ToPort" : Number
}
{
"GroupName" : String
"GroupId" : String
"IpProtocol" : String
"CidrIp" : String
"SourceSecurityGroupName" : String
"SourceSecurityGroupId" : String
"SourceSecurityGroupOwnerId" : String
"FromPort" : Number
"ToPort" : Number
}
100. 100
EC2:サンプルコード
"Host1" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"InstanceType" : { "Ref" : "HostInstanceType" },
"KeyName" : { "Ref" : "KeyName" },
"DisableApiTermination" : "True",
"Monitoring" : "true",
"SubnetId" : { "Ref" : "HostSubnets" },
"ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" :
"HostInstanceType" }, "Arch" ] } ] },
"SecurityGroupIds" : [{ "Ref" : "HostSecurityGroup" }]
}
},
"HostSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable access to others",
"VpcId" : { "Ref" : "VPCId" },
"SecurityGroupIngress" : [ { "IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0"} ],
"SecurityGroupEgress" : [{ "IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0"}]
}
},
APIでのTermination
を禁止
102. 102
まとめ
• 開発や本運用に必要な、互いに関連する AWS リソースのコ
レクションを作成しておき、そのリソースを適切な順序でプ
ロビジョニング可能。
• クイックスタートやサンプルテンプレートも充実。
• AWS CloudFormation Degsignerで、ドラッグアンドド
ロップインターフェイスを使用して、テンプレートを図とし
て視覚化し、編集することも可能。
• 利用料金は無料。EC2やRDSなどリソースの利用料金のみ。