2
"AWSTemplateFormatVersion" : "2010-09-09",
4
"Description" : "AWS CloudFormation Sample Template WordPress_Multi_Instance: WordPress is web software you can use to create a beautiful website or blog. This template installs two instances: one running a WordPress deployment and the other using a local MySQL database to store the data.",
9
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
14
"Description" : "WebServer EC2 instance type",
16
"Default" : "m1.large",
17
"AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ],
18
"ConstraintDescription" : "must be a valid EC2 instance type."
22
"Default": "wordpress",
23
"Description" : "The WordPress database name",
27
"AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
28
"ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
34
"Description" : "The WordPress database admin account username",
38
"AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
39
"ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
45
"Description" : "The WordPress database admin account password",
49
"AllowedPattern" : "[a-zA-Z0-9]*",
50
"ConstraintDescription" : "must contain only alphanumeric characters."
56
"Description" : "Root password for MySQL",
60
"AllowedPattern" : "[a-zA-Z0-9]*",
61
"ConstraintDescription" : "must contain only alphanumeric characters."
63
"LinuxDistribution": {
65
"Description" : "Distribution of choice",
67
"AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ]
71
"Description" : "Interval for cfn-hup",
77
"AWSInstanceType2Arch" : {
78
"t1.micro" : { "Arch" : "32" },
79
"m1.small" : { "Arch" : "32" },
80
"m1.large" : { "Arch" : "64" },
81
"m1.xlarge" : { "Arch" : "64" },
82
"m2.xlarge" : { "Arch" : "64" },
83
"m2.2xlarge" : { "Arch" : "64" },
84
"m2.4xlarge" : { "Arch" : "64" },
85
"c1.medium" : { "Arch" : "32" },
86
"c1.xlarge" : { "Arch" : "64" },
87
"cc1.4xlarge" : { "Arch" : "64" }
90
"F18" : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" },
91
"F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" },
92
"U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" },
93
"RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" },
94
"RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" },
95
"RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" }
101
"Type" : "AWS::IAM::User"
104
"Type" : "AWS::IAM::AccessKey",
106
"UserName" : {"Ref": "CfnUser"}
109
"WebServerRestartPolicy" : {
110
"Type" : "OS::Heat::HARestarter",
112
"InstanceId" : { "Ref" : "WikiDatabase" }
115
"HeartbeatFailureAlarm": {
116
"Type": "AWS::CloudWatch::Alarm",
117
"DependsOn" : "WaitCondition",
119
"AlarmDescription": "Restart the WikiDatabase if we miss a heartbeat",
120
"MetricName": "Heartbeat",
121
"Namespace": "system/linux",
122
"Statistic": "SampleCount",
124
"EvaluationPeriods": "1",
126
"AlarmActions": [ { "Ref": "WebServerRestartPolicy" } ],
127
"ComparisonOperator": "LessThanThreshold"
131
"Type": "AWS::EC2::Instance",
133
"AWS::CloudFormation::Init" : {
136
"/etc/cfn/cfn-credentials" : {
137
"content" : { "Fn::Join" : ["", [
138
"AWSAccessKeyId=", { "Ref" : "WebServerKeys" }, "\n",
139
"AWSSecretKey=", {"Fn::GetAtt": ["WebServerKeys",
140
"SecretAccessKey"]}, "\n"
146
"/etc/cfn/cfn-hup.conf" : {
147
"content" : { "Fn::Join" : ["", [
149
"stack=", { "Ref" : "AWS::StackName" }, "\n",
150
"credential-file=/etc/cfn/cfn-credentials\n",
151
"region=", { "Ref" : "AWS::Region" }, "\n",
152
"interval=", { "Ref" : "HupPollInterval" }, "\n"
158
"/tmp/cfn-hup-crontab.txt" : {
159
"content" : { "Fn::Join" : ["", [
162
"* * * * * /opt/aws/bin/cfn-hup -f\n",
163
"* * * * * /opt/aws/bin/cfn-push-stats ",
164
" --watch ", { "Ref" : "HeartbeatFailureAlarm" },
172
"/tmp/setup.mysql" : {
173
"content" : { "Fn::Join" : ["", [
174
"CREATE DATABASE ", { "Ref" : "DBName" }, ";\n",
175
"GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" },
176
".* TO '", { "Ref" : "DBUsername" }, "'@'localhost'\n",
177
"IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n",
178
"FLUSH PRIVILEGES;\n",
197
"mysqld" : { "enabled" : "true", "ensureRunning" : "true" },
198
"httpd" : { "enabled" : "true", "ensureRunning" : "true" },
199
"crond" : { "enabled" : "true", "ensureRunning" : "true" }
206
"ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" },
207
{ "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
208
"InstanceType" : { "Ref" : "InstanceType" },
209
"KeyName" : { "Ref" : "KeyName" },
210
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
212
"# Helper function\n",
213
"function error_exit\n",
215
" /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n",
219
"/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" },
221
" --region ", { "Ref" : "AWS::Region" },
222
" || error_exit 'Failed to run cfn-init'\n",
224
"# Setup MySQL root password and create a user\n",
225
"mysqladmin -u root password '", { "Ref" : "DBRootPassword" },
226
"' || error_exit 'Failed to initialize root password'\n",
228
"mysql -u root --password='", { "Ref" : "DBRootPassword" },
229
"' < /tmp/setup.mysql || error_exit 'Failed to create database.'\n",
231
"sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n",
232
"sed --in-place --e s/database_name_here/", { "Ref" : "DBName" },
233
"/ --e s/username_here/", { "Ref" : "DBUsername" },
234
"/ --e s/password_here/", { "Ref" : "DBPassword" },
235
"/ /usr/share/wordpress/wp-config.php\n",
237
"systemctl restart httpd.service\n",
239
"# install cfn-hup crontab\n",
240
"crontab /tmp/cfn-hup-crontab.txt\n",
242
"# All is well so signal success\n",
243
"/opt/aws/bin/cfn-signal -e 0 -r \"Wiki server setup complete\" '",
244
{ "Ref" : "WaitHandle" }, "'\n"
250
"Type" : "AWS::CloudFormation::WaitConditionHandle"
254
"Type" : "AWS::CloudFormation::WaitCondition",
255
"DependsOn" : "WikiDatabase",
257
"Handle" : {"Ref" : "WaitHandle"},
265
"Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WikiDatabase", "PublicIp" ]}, "/wordpress"]] },
266
"Description" : "URL for Wordpress wiki"