Advertisement
Guest User

Untitled

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