Created
August 19, 2015 18:39
-
-
Save geertj/204c46fc20b6fa7c76ab to your computer and use it in GitHub Desktop.
CloudFormation template for Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Description": "Scalable Wordpress instance", | |
"Parameters": { | |
"InstanceType": { | |
"Type": "String", | |
"Description": "Instance type", | |
"Default": "t2.medium", | |
"AllowedValues": [ "t2.medium", "t2.large" ] | |
}, | |
"SubnetId": { | |
"Type": "AWS::EC2::Subnet::Id", | |
"Description": "Subnet ID for VPC" | |
}, | |
"KeyName": { | |
"Type": "String", | |
"Description": "Keypair name" | |
} | |
}, | |
"Mappings": { | |
"Images": { | |
"us-east-1": { "Value": "ami-12663b7a" }, | |
"us-west-1": { "Value": "ami-a540a5e1" }, | |
"us-west-2": { "Value": "ami-4dbf9e7d" } | |
} | |
}, | |
"Resources": { | |
"WebServer0": { | |
"Type": "AWS::EC2::Instance", | |
"Properties": { | |
"ImageId": { "Fn::FindInMap": [ "Images", { "Ref": "AWS::Region" }, "Value" ] }, | |
"InstanceType": { "Ref": "InstanceType" }, | |
"SubnetId": { "Ref": "SubnetId" }, | |
"KeyName": { "Ref": "KeyName" }, | |
"UserData": { "Fn::Base64": { "Fn::Join": [ "", [ | |
"#!/bin/sh\n", | |
"curl -O https://bootstrap.pypa.io/get-pip.py\n", | |
"python get-pip.py\n", | |
"pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n", | |
"/opt/aws/bin/cfn-init -v", | |
" --region ", { "Ref" : "AWS::Region" }, | |
" --stack ", { "Ref" : "AWS::StackName" }, | |
" --resource WebServer0\n", | |
"yum -y install httpd php php-mysql\n", | |
"cd /var/www/html\n", | |
"curl -sL https://wordpress.org/latest.tar.gz | tar xfz -\n", | |
"chown -R root:root wordpress\n", | |
"sed -e 's/database_name_here/wordpress/'", | |
" -e 's/username_here/wordpress/'", | |
" -e 's/password_here/smartvm/'", | |
" -e 's/localhost/", { "Fn::GetAtt": [ "Database", "PrivateIp" ] }, "/'", | |
" < wordpress/wp-config-sample.php > wordpress/wp-config.php\n", | |
"echo 'RedirectMatch ^/$ /wordpress' > /etc/httpd/conf.d/wordpress.conf\n", | |
"setsebool -P httpd_can_network_connect on\n", | |
"systemctl enable httpd && systemctl start httpd\n" | |
] ] } } | |
} | |
}, | |
"Database": { | |
"Type": "AWS::EC2::Instance", | |
"Properties": { | |
"ImageId": { "Fn::FindInMap": [ "Images", { "Ref": "AWS::Region" }, "Value" ] }, | |
"InstanceType": { "Ref": "InstanceType" }, | |
"SubnetId": { "Ref": "SubnetId" }, | |
"KeyName": { "Ref": "KeyName" }, | |
"UserData": { "Fn::Base64": { "Fn::Join": [ "", [ | |
"#!/bin/sh\n", | |
"curl -O https://bootstrap.pypa.io/get-pip.py\n", | |
"python get-pip.py\n", | |
"pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n", | |
"/opt/aws/bin/cfn-init -v", | |
" --region ", { "Ref" : "AWS::Region" }, | |
" --stack ", { "Ref" : "AWS::StackName" }, | |
" --resource Database\n", | |
"yum -y install mariadb-server\n", | |
"systemctl enable mariadb && systemctl start mariadb\n", | |
"mysql mysql << EOM\n", | |
" CREATE DATABASE wordpress;\n", | |
" GRANT ALL PRIVILEGES ON wordpress.* to wordpress IDENTIFIED BY 'smartvm';\n", | |
" DELETE FROM user WHERE user = '';\n", | |
" FLUSH PRIVILEGES;\n", | |
"EOM\n" | |
] ] } } | |
} | |
} | |
}, | |
"Outputs": { | |
"URL": { | |
"Description": "URL of the blog", | |
"Value": { "Fn::Join": [ "", [ "http://", { "Fn::GetAtt": [ "WebServer0", "PublicIp" ] }, "/" ] ] } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment