|
| 1 | +{ |
| 2 | + "AWSTemplateFormatVersion" : "2010-09-09", |
| 3 | + |
| 4 | + "Description" : "AWS CloudFormation Sample Template AutoScalingKeepAtNSample: Create a load balanced, Auto Scaled sample website. This example creates an Auto Scaling group behind a load balancer with a simple health check using a basic getting start AMI that has a simple Apache Web Server-based PHP page. The web site is available on port 80, however, the instances can be configured to listen on any port (8888 by default). **WARNING** This template creates one or more Amazon EC2 instances and an Elastic Load Balancer. You will be billed for the AWS resources used if you create a stack from this template.", |
| 5 | + |
| 6 | + "Parameters" : { |
| 7 | + "InstanceType" : { |
| 8 | + "Description" : "WebServer EC2 instance type", |
| 9 | + "Type" : "String", |
| 10 | + "Default" : "m1.small", |
| 11 | + "AllowedValues" : [ "t1.micro","m1.small","m1.medium","m1.large","m1.xlarge","m2.xlarge","m2.2xlarge","m2.4xlarge","m3.xlarge","m3.2xlarge","c1.medium","c1.xlarge","cc1.4xlarge","cc2.8xlarge","cg1.4xlarge"], |
| 12 | + "ConstraintDescription" : "must be a valid EC2 instance type." |
| 13 | + }, |
| 14 | + |
| 15 | + "WebServerPort" : { |
| 16 | + "Description" : "TCP/IP port of the web server", |
| 17 | + "Type" : "String", |
| 18 | + "Default" : "8888" |
| 19 | + }, |
| 20 | + "KeyName" : { |
| 21 | + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", |
| 22 | + "Type" : "String" |
| 23 | + }, |
| 24 | + "SSHLocation" : { |
| 25 | + "Description" : "The IP address range that can be used to SSH to the EC2 instances", |
| 26 | + "Type": "String", |
| 27 | + "MinLength": "9", |
| 28 | + "MaxLength": "18", |
| 29 | + "Default": "0.0.0.0/0", |
| 30 | + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", |
| 31 | + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." |
| 32 | + } |
| 33 | + |
| 34 | + }, |
| 35 | + |
| 36 | + "Mappings" : { |
| 37 | + "AWSInstanceType2Arch" : { |
| 38 | + "t1.micro" : { "Arch" : "64" }, |
| 39 | + "m1.small" : { "Arch" : "64" }, |
| 40 | + "m1.medium" : { "Arch" : "64" }, |
| 41 | + "m1.large" : { "Arch" : "64" }, |
| 42 | + "m1.xlarge" : { "Arch" : "64" }, |
| 43 | + "m2.xlarge" : { "Arch" : "64" }, |
| 44 | + "m2.2xlarge" : { "Arch" : "64" }, |
| 45 | + "m2.4xlarge" : { "Arch" : "64" }, |
| 46 | + "m3.xlarge" : { "Arch" : "64" }, |
| 47 | + "m3.2xlarge" : { "Arch" : "64" }, |
| 48 | + "c1.medium" : { "Arch" : "64" }, |
| 49 | + "c1.xlarge" : { "Arch" : "64" } |
| 50 | + }, |
| 51 | + |
| 52 | + "AWSRegionArch2AMI" : { |
| 53 | + "us-east-1" : { "32" : "ami-aba768c2", "64" : "ami-81a768e8" }, |
| 54 | + "us-west-1" : { "32" : "ami-458fd300", "64" : "ami-b18ed2f4" }, |
| 55 | + "us-west-2" : { "32" : "ami-fcff72cc", "64" : "ami-feff72ce" }, |
| 56 | + "eu-west-1" : { "32" : "ami-018bb975", "64" : "ami-998bb9ed" }, |
| 57 | + "sa-east-1" : { "32" : "ami-a039e6bd", "64" : "ami-a239e6bf" }, |
| 58 | + "ap-southeast-1" : { "32" : "ami-425a2010", "64" : "ami-5e5a200c" }, |
| 59 | + "ap-southeast-2" : { "32" : "ami-b3990e89", "64" : "ami-bd990e87" }, |
| 60 | + "ap-northeast-1" : { "32" : "ami-7871c579", "64" : "ami-7671c577" } |
| 61 | + } |
| 62 | + }, |
| 63 | + |
| 64 | + "Resources" : { |
| 65 | + "WebServerGroup" : { |
| 66 | + "Type" : "AWS::AutoScaling::AutoScalingGroup", |
| 67 | + "Properties" : { |
| 68 | + "AvailabilityZones" : { "Fn::GetAZs" : "" }, |
| 69 | + "LaunchConfigurationName" : { "Ref" : "LaunchConfig" }, |
| 70 | + "MinSize" : "2", |
| 71 | + "MaxSize" : "2", |
| 72 | + "LoadBalancerNames" : [ { "Ref" : "ElasticLoadBalancer" } ] |
| 73 | + } |
| 74 | + }, |
| 75 | + |
| 76 | + "LaunchConfig" : { |
| 77 | + "Type" : "AWS::AutoScaling::LaunchConfiguration", |
| 78 | + "Properties" : { |
| 79 | + "KeyName" : { "Ref" : "KeyName" }, |
| 80 | + "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, |
| 81 | + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, |
| 82 | + "Arch" ] } ] }, |
| 83 | + "UserData" : { "Fn::Base64" : { "Ref" : "WebServerPort" }}, |
| 84 | + "SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ], |
| 85 | + "InstanceType" : { "Ref" : "InstanceType" } |
| 86 | + } |
| 87 | + }, |
| 88 | + |
| 89 | + "ElasticLoadBalancer" : { |
| 90 | + "Type" : "AWS::ElasticLoadBalancing::LoadBalancer", |
| 91 | + "Properties" : { |
| 92 | + "AvailabilityZones" : { "Fn::GetAZs" : "" }, |
| 93 | + "Listeners" : [ { |
| 94 | + "LoadBalancerPort" : "80", |
| 95 | + "InstancePort" : { "Ref" : "WebServerPort" }, |
| 96 | + "Protocol" : "HTTP" |
| 97 | + } ], |
| 98 | + "HealthCheck" : { |
| 99 | + "Target" : { "Fn::Join" : [ "", ["HTTP:", { "Ref" : "WebServerPort" }, "/"]]}, |
| 100 | + "HealthyThreshold" : "3", |
| 101 | + "UnhealthyThreshold" : "5", |
| 102 | + "Interval" : "30", |
| 103 | + "Timeout" : "5" |
| 104 | + } |
| 105 | + } |
| 106 | + }, |
| 107 | + |
| 108 | + "InstanceSecurityGroup" : { |
| 109 | + "Type" : "AWS::EC2::SecurityGroup", |
| 110 | + "Properties" : { |
| 111 | + "GroupDescription" : "Enable SSH access and HTTP access on the configured port", |
| 112 | + "SecurityGroupIngress" : |
| 113 | + [ { "IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : { "Ref" : "SSHLocation"} }, |
| 114 | + { "IpProtocol" : "tcp", "FromPort" : { "Ref" : "WebServerPort" }, "ToPort" : { "Ref" : "WebServerPort" }, "CidrIp" : "0.0.0.0/0"} ] |
| 115 | + } |
| 116 | + } |
| 117 | + }, |
| 118 | + |
| 119 | + "Outputs" : { |
| 120 | + "URL" : { |
| 121 | + "Description" : "URL of the website", |
| 122 | + "Value" : { "Fn::Join" : [ "", [ "http://", { "Fn::GetAtt" : [ "ElasticLoadBalancer", "DNSName" ]}]]} |
| 123 | + } |
| 124 | + } |
| 125 | +} |
0 commit comments