1{ 2 "AWSTemplateFormatVersion" : "2010-09-09", 3 4 "Description" : "Template Description", 5 6 "Parameters" : { 7 "InstanceType" : { 8 "Description" : "Type of instance to launch (Note: The AMI is a 32bit AMI, so the instance must be capable of running a 32bit image)", 9 "Type" : "String", 10 "Default" : "m1.small" 11 }, 12 "WebServerPort" : { 13 "Description" : "The TCP port for the Web Server", 14 "Type" : "String", 15 "Default" : "8888" 16 }, 17 "KeyPair" : { 18 "Description" : "The EC2 Key Pair to allow SSH access to the instances", 19 "Type" : "String", 20 "Default" : "FooBar" 21 } 22 }, 23 24 "Mappings" : { 25 "RegionMap" : { 26 "us-east-1" : { 27 "TestAZ" : "us-east-1a", 28 "AMI" : "ami-e08f7f89" 29 }, 30 "us-west-1" : { 31 "TestAZ" : "us-west-1a", 32 "AMI" : "ami-a38bdbe6" 33 }, 34 "eu-west-1" : { 35 "TestAZ" : "eu-west-1a", 36 "AMI" : "ami-03310577" 37 }, 38 "ap-northeast-1" : { 39 "TestAZ" : "ap-northeast-1a", 40 "AMI" : "ami-e2a3ddb0" 41 } 42 } 43 }, 44 45 "Resources" : { 46 "WebServerGroup" : { 47 "Type" : "AWS::AutoScaling::AutoScalingGroup", 48 "Properties" : { 49 "AvailabilityZones" : [ { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "TestAZ" ]} ], 50 "LaunchConfigurationName" : { "Ref" : "LaunchConfig" }, 51 "MinSize" : "2", 52 "MaxSize" : "2", 53 "LoadBalancerNames" : [ { "Ref" : "ElasticLoadBalancer" } ] 54 } 55 }, 56 57 "LaunchConfig" : { 58 "Type" : "AWS::AutoScaling::LaunchConfiguration", 59 "Properties" : { 60 "KeyName" : { "Ref" : "KeyPair" }, 61 "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]}, 62 "UserData" : { "Fn::Base64" : { "Fn::Join" : [ ":", [ { "Ref" : "WebServerPort" }]]}}, 63 "SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ], 64 "InstanceType" : { "Ref" : "InstanceType" } 65 } 66 }, 67 68 "ElasticLoadBalancer" : { 69 "Type" : "AWS::ElasticLoadBalancing::LoadBalancer", 70 "Properties" : { 71 "AvailabilityZones" : [ { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "TestAZ" ]} ], 72 "Listeners" : [ { 73 "LoadBalancerPort" : "80", 74 "InstancePort" : { "Ref" : "WebServerPort" }, 75 "Protocol" : "HTTP" 76 } ], 77 "HealthCheck" : { 78 "Target" : { "Fn::Join" : [ "", ["HTTP:", { "Ref" : "WebServerPort" }, "/"]]}, 79 "HealthyThreshold" : "3", 80 "UnhealthyThreshold" : "5", 81 "Interval" : "30", 82 "Timeout" : "5" 83 } 84 } 85 }, 86 87 "InstanceSecurityGroup" : { 88 "Type" : "AWS::EC2::SecurityGroup", 89 "Properties" : { 90 "GroupDescription" : "Enable SSH access and HTTP access on the inbound port", 91 "SecurityGroupIngress" : [ { 92 "IpProtocol" : "tcp", 93 "FromPort" : "22", 94 "ToPort" : "22", 95 "CidrIp" : "0.0.0.0/0" 96 }, 97 { 98 "IpProtocol" : "tcp", 99 "FromPort" : { "Ref" : "WebServerPort" }, 100 "ToPort" : { "Ref" : "WebServerPort" }, 101 "CidrIp" : "0.0.0.0/0" 102 } ] 103 } 104 } 105 }, 106 107 "Outputs" : { 108 "URL" : { 109 "Description" : "The URL of the Load Balanced Web Site", 110 "Value" : { "Fn::Join" : [ "", [ "http://", { "Fn::GetAtt" : [ "ElasticLoadBalancer", "DNSName" ]}]]} 111 } 112 } 113} 114