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",
103
"Policies" : [ { "Ref": "WebServerAccessPolicy"} ]
106
"WebServerAccessPolicy" : {
107
"Type" : "OS::Heat::AccessPolicy",
109
"AllowedResources" : [ "WikiDatabase" ]
113
"Type" : "AWS::IAM::AccessKey",
115
"UserName" : {"Ref": "CfnUser"}
118
"WebServerRestartPolicy" : {
119
"Type" : "OS::Heat::HARestarter",
121
"InstanceId" : { "Ref" : "WikiDatabase" }
124
"HttpFailureAlarm": {
125
"Type": "AWS::CloudWatch::Alarm",
127
"AlarmDescription": "Restart the WikiDatabase if httpd fails > 3 times in 10 minutes",
128
"MetricName": "ServiceFailure",
129
"Namespace": "system/linux",
130
"Statistic": "SampleCount",
132
"EvaluationPeriods": "1",
134
"AlarmActions": [ { "Ref": "WebServerRestartPolicy" } ],
135
"ComparisonOperator": "GreaterThanThreshold"
139
"Type": "AWS::EC2::Instance",
141
"AWS::CloudFormation::Init" : {
144
"/etc/cfn/cfn-credentials" : {
145
"content" : { "Fn::Join" : ["", [
146
"AWSAccessKeyId=", { "Ref" : "WebServerKeys" }, "\n",
147
"AWSSecretKey=", {"Fn::GetAtt": ["WebServerKeys",
148
"SecretAccessKey"]}, "\n"
155
"/etc/cfn/cfn-hup.conf" : {
156
"content" : { "Fn::Join" : ["", [
158
"stack=", { "Ref" : "AWS::StackName" }, "\n",
159
"credential-file=/etc/cfn/cfn-credentials\n",
160
"region=", { "Ref" : "AWS::Region" }, "\n",
161
"interval=", { "Ref" : "HupPollInterval" }, "\n"
168
"/etc/cfn/notify-on-httpd-restarted" : {
169
"content" : { "Fn::Join" : ["", [
171
"/opt/aws/bin/cfn-push-stats --watch ",
172
{ "Ref" : "HttpFailureAlarm" },
173
" --service-failure\n"
180
"/tmp/cfn-hup-crontab.txt" : {
181
"content" : { "Fn::Join" : ["", [
184
"* * * * * /opt/aws/bin/cfn-hup -f\n"
191
"/tmp/setup.mysql" : {
192
"content" : { "Fn::Join" : ["", [
193
"CREATE DATABASE ", { "Ref" : "DBName" }, ";\n",
194
"GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" },
195
".* TO '", { "Ref" : "DBUsername" }, "'@'localhost'\n",
196
"IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n",
197
"FLUSH PRIVILEGES;\n",
205
"/etc/cfn/hooks.conf" : {
206
"content": { "Fn::Join" : ["", [
207
"[cfn-http-restarted]\n",
208
"triggers=service.restarted\n",
209
"path=Resources.WikiDatabase.Metadata\n",
210
"action=/etc/cfn/notify-on-httpd-restarted\n",
229
"mysqld" : { "enabled" : "true", "ensureRunning" : "true" },
230
"httpd" : { "enabled" : "true", "ensureRunning" : "true" },
231
"crond" : { "enabled" : "true", "ensureRunning" : "true" }
238
"ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" },
239
{ "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
240
"InstanceType" : { "Ref" : "InstanceType" },
241
"KeyName" : { "Ref" : "KeyName" },
242
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
244
"# Helper function\n",
245
"function error_exit\n",
247
" /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n",
251
"/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" },
253
" --access-key ", { "Ref" : "WebServerKeys" },
254
" --secret-key ", {"Fn::GetAtt": ["WebServerKeys", "SecretAccessKey"]},
255
" --region ", { "Ref" : "AWS::Region" },
256
" || error_exit 'Failed to run cfn-init'\n",
258
"# Setup MySQL root password and create a user\n",
259
"mysqladmin -u root password '", { "Ref" : "DBRootPassword" },
260
"' || error_exit 'Failed to initialize root password'\n",
262
"mysql -u root --password='", { "Ref" : "DBRootPassword" },
263
"' < /tmp/setup.mysql || error_exit 'Failed to create database.'\n",
265
"sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n",
266
"sed --in-place --e s/database_name_here/", { "Ref" : "DBName" },
267
"/ --e s/username_here/", { "Ref" : "DBUsername" },
268
"/ --e s/password_here/", { "Ref" : "DBPassword" },
269
"/ /usr/share/wordpress/wp-config.php\n",
271
"systemctl restart httpd.service\n",
273
"# install cfn-hup crontab\n",
274
"crontab /tmp/cfn-hup-crontab.txt\n",
276
"# All is well so signal success\n",
277
"/opt/aws/bin/cfn-signal -e 0 -r \"Wiki server setup complete\" '",
278
{ "Ref" : "WaitHandle" }, "'\n"
284
"Type" : "AWS::CloudFormation::WaitConditionHandle"
288
"Type" : "AWS::CloudFormation::WaitCondition",
289
"DependsOn" : "WikiDatabase",
291
"Handle" : {"Ref" : "WaitHandle"},
300
"Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WikiDatabase", "PublicIp" ]}, "/wordpress"]] },
301
"Description" : "URL for Wordpress wiki"