Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2015
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 10.16 KB | None | 0 0
  1. {
  2.   "AWSTemplateFormatVersion" : "2010-09-09",
  3.  
  4.   "Description" : "AWS CloudFormation Sample Template WordPress_Single_Instance_With_RDS: WordPress is web software you can use to create a website or blog. This template installs a single-instance WordPress deployment that uses an Amazon RDS database instance for storage. It demonstrates using the AWS CloudFormation bootstrap scripts to install packages and files when an instance is launched. **WARNING** This template creates an Amazon EC2 instance and an Amazon RDS database instance. You will be billed for the AWS resources used if you create a stack from this template.",
  5.  
  6.   "Parameters" : {
  7.  
  8.     "KeyName": {
  9.       "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
  10.       "Type": "String",
  11.       "MinLength": "1",
  12.       "MaxLength": "255",
  13.       "AllowedPattern" : "[\\x20-\\x7E]*",
  14.       "ConstraintDescription" : "can contain only ASCII characters."
  15.     },
  16.  
  17.     "InstanceType" : {
  18.       "Description" : "WebServer EC2 instance type",
  19.       "Type" : "String",
  20.       "Default" : "t2.micro",
  21.       "AllowedValues" : [ "t1.micro", "t2.micro", "t2.small", "t2.medium", "m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge" ],
  22.       "ConstraintDescription" : "must be a valid EC2 instance type."
  23.     },
  24.  
  25.     "myVPC": {
  26.         "Description" : "Id of my VPC",
  27.         "Type"        : "String",
  28.         "Default"     : "vpc-1bcf9e7e"
  29.     },
  30.  
  31.     "MySubnet": {
  32.         "Description" : "My subnet from my VPC",
  33.         "Type": "String",
  34.         "Default": "subnet-75eec810"
  35.     },  
  36.  
  37.     "DBClass" : {
  38.       "Default" : "db.t2.micro",
  39.       "Description" : "Database instance class",
  40.       "Type" : "String",
  41.       "AllowedValues" : [ "db.t1.micro", "db.t2.micro", "db.t2.small", "db.t2.medium", "db.m3.medium", "db.m3.large", "db.m3.xlarge", "db.m3.2xlarge" ],
  42.       "ConstraintDescription" : "must select a valid database instance type."
  43.     },
  44.  
  45.     "DBName" : {
  46.       "Default": "wordpress",
  47.       "Description" : "The WordPress database name",
  48.       "Type": "String",
  49.       "MinLength": "1",
  50.       "MaxLength": "64",
  51.       "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
  52.       "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
  53.     },
  54.  
  55.     "DBUsername" : {
  56.       "Default": "admin",
  57.       "NoEcho": "true",
  58.       "Description" : "The WordPress database admin account username",
  59.       "Type": "String",
  60.       "MinLength": "1",
  61.       "MaxLength": "16",
  62.       "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
  63.       "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
  64.     },
  65.  
  66.     "DBPassword" : {
  67.       "Default": "password",
  68.       "NoEcho": "true",
  69.       "Description" : "The WordPress database admin account password",
  70.       "Type": "String",
  71.       "MinLength": "8",
  72.       "MaxLength": "41",
  73.       "AllowedPattern" : "[a-zA-Z0-9]*",
  74.       "ConstraintDescription" : "must contain only alphanumeric characters."
  75.     },
  76.  
  77.     "DBAllocatedStorage" : {
  78.       "Default": "5",
  79.       "Description" : "The size of the database (Gb)",
  80.       "Type": "Number",
  81.       "MinValue": "5",
  82.       "MaxValue": "1024",
  83.       "ConstraintDescription" : "must be between 5 and 1024Gb."
  84.     },
  85.     "SSHLocation" : {
  86.       "Description" : " The IP address range that can be used to SSH to the EC2 instances",
  87.       "Type": "String",
  88.       "MinLength": "9",
  89.       "MaxLength": "18",
  90.       "Default": "0.0.0.0/0",
  91.       "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
  92.       "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x."
  93.     }
  94.   },
  95.  
  96.   "Mappings" : {
  97.       "AWSInstanceType2Arch" : {
  98.       "t1.micro"    : { "Arch" : "PV64"  },
  99.       "t2.micro"    : { "Arch" : "HVM64"  },
  100.       "t2.small"    : { "Arch" : "HVM64"  },
  101.       "t2.medium"   : { "Arch" : "HVM64"  },
  102.       "m3.medium"   : { "Arch" : "PV64"   },
  103.       "m3.large"    : { "Arch" : "PV64"   },
  104.       "m3.xlarge"   : { "Arch" : "PV64"   },
  105.       "m3.2xlarge"  : { "Arch" : "PV64"   }
  106.     },
  107.  
  108.     "AWSRegionArch2AMI" : {
  109.       "us-east-1"      : { "PV64" : "ami-7c807d14", "HVM64" : "ami-76817c1e" },
  110.       "us-west-2"      : { "PV64" : "ami-1b3b462b", "HVM64" : "ami-d13845e1" },
  111.       "us-west-1"      : { "PV64" : "ami-a8d3d4ed", "HVM64" : "ami-f0d3d4b5" },
  112.       "eu-west-1"      : { "PV64" : "ami-672ce210", "HVM64" : "ami-892fe1fe" },
  113.       "ap-southeast-1" : { "PV64" : "ami-56b7eb04", "HVM64" : "ami-a6b6eaf4" },
  114.       "ap-northeast-1" : { "PV64" : "ami-25dd9324", "HVM64" : "ami-29dc9228" },
  115.       "ap-southeast-2" : { "PV64" : "ami-6bf99c51", "HVM64" : "ami-d9fe9be3" },
  116.       "sa-east-1"      : { "PV64" : "ami-c7e649da", "HVM64" : "ami-c9e649d4" },
  117.       "us-gov-west-1"  : { "PV64" : "ami-ab4a2d88", "HVM64" : "ami-a54a2d86" },
  118.       "cn-north-1"     : { "PV64" : "ami-cab82af3", "HVM64" : "ami-ccb82af5" }
  119.     }
  120.   },
  121.  
  122.   "Resources" : {
  123.  
  124.     "WebServer": {
  125.       "Type": "AWS::EC2::Instance",
  126.       "Metadata" : {
  127.         "AWS::CloudFormation::Init" : {
  128.           "config" : {
  129.             "packages" : {
  130.               "yum" : {
  131.                 "httpd"     : [],
  132.                 "php"       : [],
  133.                 "php-mysql" : []
  134.               }
  135.             },
  136.             "sources" : {
  137.               "/var/www/html" : "http://wordpress.org/latest.tar.gz"
  138.             },
  139.             "files" : {
  140.               "/var/www/html/wordpress/wp-config.php" : {
  141.                 "content" : { "Fn::Join" : ["", [
  142.                   "<?php\n",
  143.                   "define('DB_NAME',          '", {"Ref" : "DBName"}, "');\n",
  144.                   "define('DB_USER',          '", {"Ref" : "DBUsername"}, "');\n",
  145.                   "define('DB_PASSWORD',      '", {"Ref" : "DBPassword" }, "');\n",
  146.                   "define('DB_HOST',          '", {"Fn::GetAtt" : ["DBInstance", "Endpoint.Address"]},"');\n",
  147.                   "define('DB_CHARSET',       'utf8');\n",
  148.                   "define('DB_COLLATE',       '');\n"
  149.                 ]] },
  150.                 "mode" : "000644",
  151.                 "owner" : "root",
  152.                 "group" : "root"
  153.               }
  154.             },
  155.             "services" : {
  156.               "sysvinit" : {
  157.                 "httpd"    : { "enabled" : "true", "ensureRunning" : "true" },
  158.                 "sendmail" : { "enabled" : "false", "ensureRunning" : "false" }
  159.               }
  160.             }
  161.           }
  162.         }
  163.       },
  164.       "Properties": {
  165.         "SubnetId": { "Ref": "MySubnet" },
  166.         "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
  167.                           { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
  168.         "InstanceType"   : { "Ref" : "InstanceType" },
  169.         "SecurityGroups" : [ {"Ref" : "WebServerSecurityGroup"} ],
  170.         "KeyName"        : { "Ref" : "KeyName" },
  171.         "UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
  172.           "#!/bin/bash\n",
  173.           "yum update -y aws-cfn-bootstrap\n",
  174.  
  175.           "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackId" }, " -r WebServer ",
  176.           "         --region ", { "Ref" : "AWS::Region" }, "\n",
  177.  
  178.           "/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "WaitHandle" }, "'\n",
  179.  
  180.           "# Setup correct file ownership\n",
  181.           "chown -R apache:apache /var/www/html/wordpress\n",
  182.          
  183.           "# Add keys and salts to the config file\n",
  184.           "wp_config=/var/www/html/wordpress/wp-config.php\n",
  185.           "GET https://api.wordpress.org/secret-key/1.1/salt/ >> $wp_config\n",
  186.           "echo \"define('WPLANG'            , '');\" >> $wp_config\n",
  187.           "echo \"define('WP_DEBUG'          , false);\" >> $wp_config\n",
  188.           "echo \"\\$table_prefix  = 'wp_';\" >> $wp_config\n",
  189.           "echo \"if ( !defined('ABSPATH') )\" >> $wp_config\n",
  190.           "echo \"    define('ABSPATH', dirname(__FILE__) . '/');\" >> $wp_config\n",
  191.           "echo \"require_once(ABSPATH . 'wp-settings.php');\" >> $wp_config\n"
  192.  
  193.         ]]}}
  194.       }
  195.     },
  196.  
  197.     "WaitHandle" : {
  198.       "Type" : "AWS::CloudFormation::WaitConditionHandle"
  199.     },
  200.  
  201.     "WaitCondition" : {
  202.       "Type" : "AWS::CloudFormation::WaitCondition",
  203.       "DependsOn" : "WebServer",
  204.       "Properties" : {
  205.         "Handle" : {"Ref" : "WaitHandle"},
  206.         "Timeout" : "600"
  207.       }
  208.     },
  209.  
  210.     "DBInstance" : {
  211.       "Type": "AWS::RDS::DBInstance",
  212.       "Properties": {
  213.         "DBSubnetGroupName" : { "Ref" : "MyDBSubnetGroup" },
  214.         "VPCSecurityGroups" : [ { "Ref" : "DBSecurityGroup" } ],
  215.         "DBName"            : { "Ref" : "DBName" },
  216.         "Engine"            : "MySQL",
  217.         "MasterUsername"    : { "Ref" : "DBUsername" },
  218.         "DBInstanceClass"   : { "Ref" : "DBClass" },
  219.         "DBSecurityGroups"  : [{ "Ref" : "DBSecurityGroup" }],
  220.         "AllocatedStorage"  : { "Ref" : "DBAllocatedStorage" },
  221.         "MasterUserPassword": { "Ref" : "DBPassword" }
  222.       }
  223.     },
  224.  
  225.     "DBSecurityGroup": {
  226.       "Type": "AWS::RDS::DBSecurityGroup",
  227.       "Properties": {
  228.         "EC2VpcId" : { "Ref" : "myVPC" },
  229.         "DBSecurityGroupIngress": { "EC2SecurityGroupName": { "Ref": "WebServerSecurityGroup"} },
  230.         "GroupDescription"      : "Frontend Access"
  231.       }
  232.     },
  233.  
  234.     "WebServerSecurityGroup" : {
  235.       "Type" : "AWS::EC2::SecurityGroup",
  236.       "Properties" : {
  237.         "VpcId" : {"Ref" : "myVPC"},
  238.         "GroupDescription" : "Enable HTTP access via port 80 and SSH access",
  239.         "SecurityGroupIngress" : [
  240.           {"IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0"},
  241.           {"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : { "Ref" : "SSHLocation"}}
  242.         ]
  243.       }
  244.     },
  245.  
  246.     "MyDBSubnetGroup" : {
  247.       "Type" : "AWS::RDS::DBSubnetGroup",
  248.       "Properties" : {
  249.         "DBSubnetGroupDescription" : "Subnets available for the RDS DB Instance",
  250.         "SubnetIds" : [ { "Ref" : "MySubnet" } ]
  251.       }
  252.     }
  253.   },
  254.  
  255.   "Outputs" : {
  256.     "WebsiteURL" : {
  257.       "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicDnsName" ]}, "/wordpress"]] },
  258.       "Description" : "WordPress Website"
  259.     }
  260.   }
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement