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 Parameter Outputs Tips "Resources" : { "WebServer" : { "Type" : "AWS::CloudFormation::Stack", "Properties" : { "TemplateURL" : https://s3.amazonaws.com/hoge.template" ]]}, "Parameters" : { "KeyName" : { "Ref" : "KeyName" }, "InstanceType" : { "Ref" : "InstanceType"}, }}, 49. JSON CloudFormation Parameter Management ConsoleOutputs 50. CloudFormation CloudFormer 51. EC2 EC2 AutoScaling CloudFormer CloudFormer Web 52. CloudFormer CloudFormerCloudFormation EC2EC2 EC2 AMI AMI ID CloudFormer 53. CloudFormer 1. 2. CloudFormer https://aws.amazon.com/developertools/6460180344805680 3. CloudFormerEC2t1.micro 4. CloudFormerURL 5. Amazon S3 6. CloudFormerDelete 54. CloudFormer 55. CloudFormer 56. CloudFormer ParameterOutputs 57. CloudFormation CloudFormer CloudFormation 58. CloudFormation CloudFormationAWS CloudFormation CloudFormation 59. CloudFormation CloudFormation Baked-AMI CloudFormationAMI AMI AMI 60. CloudFormation Baked- AMI AMI AMI DR AMI/ DB RDSAWS 61. userdata() AMIAMI 16KB 62. cloud-init Amazon Linux EC2userdata #! RHEL http://aws.amazon.com/articles/2519228458631605 WindowsEC2CongService 63. cloud-init User Data Cloud-inituserdata EC2 64. CloudFormationuserdata EC2UserData "MyInstance": { "Type": "AWS::EC2::Instance", "Properties": { "ImageId" : "ami-dcfa4edd", "KeyName" : { "Ref" : "KeyName" }, "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ "#!/bin/bashn", "log='/tmp/init.log'n", "apt-get update &>> $logn", "apt-get install -y ruby &>> $logn", "cd /tmpn", "wget http://rubygems.org/rubygems.tgz &>> $logn", "tar zxf rubygems.tgz &>> $logn", "cd rubygemsn", "ruby setup.rb --no-format-executable &>> $logn", ] ] } } } 65. CloudFormation CloudFormationUserDataRef Fn::GetAttr RDSEndPointUserData "Resources" : { "MyInstance": { "Type": "AWS::EC2::Instance", "Properties": { "ImageId" : "ami-dcfa4edd", "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ "#!/bin/bashn", "cd /home/ec2-usern", { "Fn::Join" : ["", [ "echo ", {"Fn::GetAtt" : ["DBInstance", "Endpoint.Address"]} , "> db.confn" ]]} ]]} } } }, "DBInstance" : { "Type": "AWS::RDS::DBInstance", } } 66. CloudFormation helper scripts EC2 userdata Amazon Linux AMI Yum http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn- helper-scripts-reference.html 4 cfn-init, cfn-get-metadata, cfn-signal, cfn-hup 67. cfn-init Metadata AWS::CloudFormation::Init CongsetsCommandsFilesGroupsPackagesServicesSourcesUsers "Resources": { "MyInstance": { "Type": "AWS::EC2::Instance", "Metadata" : { "AWS::CloudFormation::Init" : { "config" : { "sources" : { : }, "packages" : { : } "files" : { : } "services" : { : } } } }, "Properties": { : } } source,package,les,services 68. cfn-init sources URL Tar,zip,tar+gzip,tar+bz2 packages apt, yum, rubygems, python, rpm "sources" : { "/etc/myapp" : "https://s3.amazonaws.com/mybucket/myapp.tar.gz" } "packages" : { "yum" : { "httpd" : [], "php" : [], }, "rubygems" : { "chef" : [ "0.10.2" ], }} 69. cfn-init les "files" : { "/app/db.conf" : { "content" : { "Fn::Join" : ["", [ "db.name=", {"Ref" : "DBName"}, "n", "db.user=", {"Ref" : "DBUser"}, "n", "db.pass=", {"Ref" : "DBPassword" },"n", "db.host=", {"Fn::GetAtt" : ["DBInstance", "Endpoint.Address"]}, "n", ]] }, "mode" : "000644", "owner" : "root", "group" : "root" } "/etc/myapp/myapp-init.pp" : { "source" : "https://s3.amazonaws.com/myapp/myapp-init.pp", "mode" : "100644", "owner" : "root", "group" : "wheel" }} S3 70. cfn-init services sysvinit "services" : { "sysvinit" : { "nginx" : { "enabled" : "true", "ensureRunning" : "true", "files" : ["/etc/nginx/nginx.conf"], "sources" : ["/var/www/html"] }, "php-fastcgi" : { "enabled" : "true", "ensureRunning" : "true", "packages" : { "yum" : ["php", "spawn-fcgi"] } } } cfn-init OS cfg-init 71. "Properties": { "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ "#!/bin/bashn", "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" }, " -r WebServer ", " --access-key ", { "Ref" : "HostKeys" }, " --secret-key ", {"Fn::GetAtt": ["HostKeys", "SecretAccessKey"]}, " --region ", { "Ref" : "AWS::Region" }, "n", ]]}} } cfn-init cfn-init User-datacfn-initcloud-init 72. cfn-get-metadata Metadata cfn-signal WaitCondition cfn-signal cfn-hup StackUpdateAPI https://s3.amazonaws.com/cloudformation-examples/BoostrappingApplicationsWithAWSCloudFormation.pdf 73. cfn-init cfn-init User-datacfn-initcloud-init "Properties": { "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ "#!/bin/bashn", "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" }, " -r WebServer ", " --access-key ", { "Ref" : "HostKeys" }, " --secret-key ", {"Fn::GetAtt": ["HostKeys", "SecretAccessKey"]}, " --region ", { "Ref" : "AWS::Region" }, "n", ]]}}} 74. CloudFormation CloudFormer CloudFormation 75. AWS EC2RDS CloudFormation Elastic BeanstalkOpsWorks 76. Cloud Formation Samples http://aws.amazon.com/jp/cloudformation/aws-cloudformation-templates/ AWS CloudFormation http://aws.amazon.com/jp/cloudformation/aws-cloudformation-articles-and- tutorials/ BootstrappingApplicationsWithAWSCloudFormation https://s3.amazonaws.com/cloudformation-examples/ BoostrappingApplicationsWithAWSCloudFormation.pdf AWS CloudFormation http://aws.amazon.com/jp/cloudformation/faqs/ 77. Webinar AWS http://aws.amazon.com/jp/aws-jp-introduction/


Top Related