aws black belt techシリーズ aws cloudformation

Download AWS Black Belt Techシリーズ  AWS CloudFormation

Post on 26-Jan-2015

107 views

Category:

Technology

0 download

Embed Size (px)

DESCRIPTION

AWS Black Belt Tech Webinar 2014 (旧マイスターシリーズ) AWS CloudFormation

TRANSCRIPT

  • 1. AWS CloudFormation AWS Black Belt Tech Webinar 2014 ()

2. CloudFormation CloudFormer CloudFormation 3. CloudFormation CloudFormer CloudFormation 4. AWS CloudFormation EC2ELBAWS JSON AWS Test DriveCloudFormation http://aws.amazon.com/jp/testdrive/japan/ 5. S3 CloudWatch Elastic Load Balancing EC2 EC2 Auto Scaling SNS Cloud Formation AWS CloudFormation 6. BlogWeb AZ DBEC2 7. CloudFormation AWS EC2ELBRDS 8. AWS Elastic Beanstalk OpsWorks CloudFormation 9. CloudFormation CloudFormationOpsWorksElasticBeanstalk CloudFormation DR CloudFormation DR 10. CloudFormationDR http://aws.amazon.com/jp/solutions/case-studies/astellas/ 11. 1/2 ParametersOutputs60 1/29 SQSDead letter queue 2/10 Redshift 3/19 ELBLoggingConnection draining 4/2 CloudTrailCloudFormation 5/5 Amazon S3 5/6 Amazon Kinesis 6/17 EBSVPC Peering http://aws.amazon.com/releasenotes/AWS-CloudFormation/1755579460043566 12. CloudFormation CloudFormer CloudFormation 13. CloudFormation Web Server App Server 14. AWS Management Console AWS Command Line Toolhttp://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/ 15. AWS Management Console-1 16. 3 S3 AWS Management Console-2 17. AWS Management Console-3 18. AWS Management Console-4 19. AWS Management Console-5 20. AWS Management Console-6 21. Events CREATE_IN_PROGRESS AWS Management Console-7 22. AWS Management Console-8 CREATE_COMPLETE Outputs DNSEIP 23. AWS Management Console-9 Events 24. CloudFormation CloudFormer CloudFormation 25. { "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" } ] } } } } CloudFormation JSON 26. http://aws.amazon.com/jp/cloudformation/aws-cloudformation- templates/ 27. { "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 } } 2010-09-09 CloudFormation KeyPairDB Hashtable AMI-ID EC2RDS CloudFormation DNSEIP Resources 28. { "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 KeyPairDB 29. "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 30. Type String Number CommaDelimitedList Default NoEcho ***** AllowedValues [true,false] AllowedPattern [a-zA-Z]* MaxLength MinLength MaxValue MinValue Description ConstraintDescription AllowedPatternMaxLength Parameters 31. Resources : { MyServer:{ Type":AWS::EC2::Instance", Properties : { KeyName: { Ref : MyKeyName}, "Tags": [ { Key: OwnerAge,Value: { Ref: Age } }, { Key": OwnerName",Value: { Ref: FirstName } } ], }}} Ref Parameters Ref 32. http://docs.amazonwebservices.com/AWSCloudFormation/latest/UserGuide/ index.html?intrinsic-function-reference.html Function MapFunction ParameterRefFunction 8 Ref Fn::Base64Base64 Fn::FindInMapMap Fn::GetAtt"Fn::GetAtt" : [ "MyELB" , "DNSName"] Fn::GetAZs Fn::JoinFn::Join : [ :, [ a, b] ] a:b Fn::SelectIndexList { Fn::Select : [ 1, [ Jan, Feb, Mar, Apr, Jun ] ] } Feb Condition FunctionsFn::IfFn::OrFunction 33. http://docs.aws.amazon.com/AWSCloudFormation/latest/ UserGuide/pseudo-parameter-reference.html Pseudo Parameter Ref AWS::Region AWS::StackIdID AWS::StackName AWS::AccountIdAWSID AWS::NoticationARNsnotication Amazon Resource Names(ARNs) AWS::NoValueCloudFormation Resources" : { MyServer":{ Type":AWS::EC2::Instance", Properties : { KeyName: { Ref : AWS::StackName}, Tags : { Ref : AWS::Region} }}} "DBSnapshotIdentifier" : { "Fn::If" : [ "UseDBSnapshot", {"Ref" : "DBSnapshotName"}, {"Ref" : "AWS::NoValue"} ]} UseDBSnapshotTrue DBSnapshotIdentierDBSnapshotName UseDBSnapshotFalse CloudFormationDBSnapshotIdentier =DBSnapshotIdentier 34. { "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 35. "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 Regionap-northeast-1 AMI IDami-300ca731 myKey-japan Regionus-west-1AMI ID ami-3bc9997e myKey-west 36. Mappings FunctionFind::InMap "Fn::FindInMap" : [ "MapName", "Key", "Value"] MapName,key,ValueRef "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 37. { "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 38. "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 EnvTypeproduction CreateProdResources EnvTypeproduction test 39. "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 ResourcesCondition 40. { "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 EC2RDS 41. Resources" : { "MyInstance": { "Type": "AWS::EC2::Instance", "Properties": { "DisableApiTermination": "FALSE", "ImageId": "ami-a1b6fda0", InstanceType": "t1.micro", "KeyName": { "Ref": "MyKeyName" } , "Monitoring": "false", } } } EC2ELB, RDS Resources 42. CloudFormation Web http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template- resource-type-ref.html 43. Attributes DeletionPolicy Delete (Default) / Retain / Snapshot DependsOn Metadata UpdatePolicy AWS::AutoScaling::AutoScalingGroup Auto ScalingRolling Update MaxBatchSizeMinInstancesInServicePauseTime 44. { "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 DNSEIP Outputs 45. Outputs URLDBIAM ID 46. "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 47. EC2 DB CloudFormation(Depends on DeletionPolicyRetain Tips "Resources" : { "myS3Bucket" : { "Type" : "AWS::S3::Bucket", "DeletionPolicy" : "Retain" }} 48. CloudFormation AWS::CloudFormation::StackURL Parame