-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate.json
1 lines (1 loc) · 30.2 KB
/
template.json
1
{"Description":"AWS CloudFormation Sample Template Drupal_Multi_AZ. Drupal is an open source content management platform powering millions of websites and applications. This template installs a highly-available, scalable Drupal deployment using a multi-az Amazon RDS database instance for storage. It uses the AWS CloudFormation bootstrap scripts to install packages and files at instance launch time. **WARNING** This template creates one or more Amazon EC2 instances, an Elastic Load Balancer and an Amazon RDS database. You will be billed for the AWS resources used if you create a stack from this template.","Parameters":{"DBUsername":{"Type":"String","Description":"The Drupal database admin account username","Default":"hpacadmin","MinLength":"1","AllowedPattern":"[a-zA-Z][a-zA-Z0-9]*","NoEcho":"true","MaxLength":"16","ConstraintDescription":"must begin with a letter and contain only alphanumeric characters."},"SitePassword":{"Type":"String","Description":"The Drupal site admin account password","MinLength":"1","AllowedPattern":"[a-zA-Z0-9]*","NoEcho":"true","MaxLength":"41","ConstraintDescription":"must contain only alphanumeric characters."},"InstanceType":{"Default":"m1.small","Type":"String","ConstraintDescription":"must be a valid EC2 instance type.","Description":"WebServer EC2 instance type"},"SiteName":{"Default":"HPAC Drupal","Type":"String","Description":"HPAC Drupal Web Site"},"DBClass":{"Default":"db.m1.small","Type":"String","ConstraintDescription":"must select a valid database instance type.","Description":"Database instance class","AllowedValues":["db.m1.small","db.m1.large","db.m1.xlarge","db.m2.xlarge","db.m2.2xlarge","db.m2.4xlarge"]},"SiteEMail":{"Default":"[email protected]","Type":"String","Description":"EMail for site adminitrator"},"SiteAdmin":{"Type":"String","Description":"The HPAC Drupal site admin account username","Default":"hpacadmin","MinLength":"1","AllowedPattern":"[a-zA-Z][a-zA-Z0-9]*","MaxLength":"16","ConstraintDescription":"must begin with a letter and contain only alphanumeric characters."},"WebServerCapacitySingle":{"Description":"The initial number of WebServer instances","Default":"1","Type":"Number","MaxValue":"1","MinValue":"1","ConstraintDescription":"must be between 1 and 1 EC2 instances."},"DBAllocatedStorage":{"Description":"The size of the database (Gb)","Default":"5","Type":"Number","MaxValue":"1024","MinValue":"5","ConstraintDescription":"must be between 5 and 1024Gb."},"Label":{"MinLength":"1","Type":"String","Description":"A label to distinguish this deployment from others","MaxLength":"255"},"SSHLocation":{"Type":"String","Description":"The IP address range that can be used to SSH to the EC2 instances","Default":"128.103.0.0/16","MinLength":"9","AllowedPattern":"(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})","MaxLength":"18","ConstraintDescription":"must be a valid IP CIDR range of the form x.x.x.x/x."},"KeyName":{"Type":"String","Description":"HPAC EC2 KeyPair to enable SSH access to the instances","MinLength":"1","AllowedPattern":"[\\x20-\\x7E]*","MaxLength":"255","ConstraintDescription":"can contain only ASCII characters."},"DBPassword":{"Type":"String","Description":"The Drupal database admin account password","MinLength":"8","AllowedPattern":"[a-zA-Z0-9]*","NoEcho":"true","MaxLength":"41","ConstraintDescription":"must contain only alphanumeric characters."},"MultiAZDatabase":{"Default":"true","Type":"String","ConstraintDescription":"must be either true or false.","Description":"Create a multi-AZ MySQL Amazon RDS database instance","AllowedValues":["true","false"]},"S3LoggingRole":{"Default":"S3LoggingAccess","Type":"String","ConstraintDescription":"Must be a valid IAM Role","Description":"Role that allow S3 Logging"},"DBName":{"Type":"String","Description":"The Drupal database name","Default":"hpacdrupaldb","MinLength":"1","AllowedPattern":"[a-zA-Z][a-zA-Z0-9]*","MaxLength":"64","ConstraintDescription":"must begin with a letter and contain only alphanumeric characters."},"WebServerCapacity":{"Description":"The initial number of WebServer instances","Default":"3","Type":"Number","MaxValue":"5","MinValue":"2","ConstraintDescription":"must be between 1 and 5 EC2 instances."}},"AWSTemplateFormatVersion":"2010-09-09","Outputs":{"WebsiteURL":{"Description":"Drupal Website","Value":{"Fn::Join":["",["http://",{"Fn::GetAtt":["ElasticLoadBalancer","DNSName"]}]]}},"MasterJDBCConnectionString":{"Description":"JDBC connection string for the master database","Value":{"Fn::Join":["",["jdbc:mysql://",{"Fn::GetAtt":["MasterDB","Endpoint.Address"]},":",{"Fn::GetAtt":["MasterDB","Endpoint.Port"]},"/",{"Ref":"DBName"}]]}},"ReplicaJDBCConnectionString":{"Description":"JDBC connection string for the replica database","Value":{"Fn::Join":["",["jdbc:mysql://",{"Fn::GetAtt":["ReplicaDB","Endpoint.Address"]},":",{"Fn::GetAtt":["ReplicaDB","Endpoint.Port"]},"/",{"Ref":"DBName"}]]}},"MySQLConnectionString":{"Description":"Connection string for the MySQL database","Value":{"Fn::Join":["",["mysql://",{"Fn::GetAtt":["ReplicaDB","Endpoint.Address"]},":",{"Fn::GetAtt":["ReplicaDB","Endpoint.Port"]},"/",{"Ref":"DBName"}]]}}},"Resources":{"S3Bucket":{"DeletionPolicy":"Retain","Type":"AWS::S3::Bucket"},"DBSecurityGroup":{"Type":"AWS::RDS::DBSecurityGroup","Properties":{"DBSecurityGroupIngress":{"EC2SecurityGroupName":{"Ref":"WebServerSecurityGroup"}},"GroupDescription":"Frontend Access"}},"ReplicaDB":{"Type":"AWS::RDS::DBInstance","Properties":{"DBInstanceClass":{"Ref":"DBClass"},"SourceDBInstanceIdentifier":{"Ref":"MasterDB"},"DBInstanceIdentifier":{"Fn::Join":["",[{"Ref":"Label"},"ReadReplicaDatabase"]]},"Tags":[{"Key":"Name","Value":{"Fn::Join":["",[{"Ref":"Label"}," - ","Read Replica Database"]]}}]}},"WebServerSecurityGroup":{"Type":"AWS::EC2::SecurityGroup","Properties":{"SecurityGroupIngress":[{"ToPort":"80","IpProtocol":"tcp","SourceSecurityGroupOwnerId":{"Fn::GetAtt":["ElasticLoadBalancer","SourceSecurityGroup.OwnerAlias"]},"SourceSecurityGroupName":{"Fn::GetAtt":["ElasticLoadBalancer","SourceSecurityGroup.GroupName"]},"FromPort":"80"},{"ToPort":"22","IpProtocol":"tcp","FromPort":"22","CidrIp":{"Ref":"SSHLocation"}}],"GroupDescription":"Enable HTTP access via port 80, locked down to requests from the load balancer only and SSH access"}},"AdminServerGroup":{"Type":"AWS::AutoScaling::AutoScalingGroup","Properties":{"DesiredCapacity":{"Ref":"WebServerCapacitySingle"},"Tags":[{"Value":{"Fn::Join":["",[{"Ref":"Label"}," - ","Admin Instance"]]},"PropagateAtLaunch":"true","Key":"Name"}],"MinSize":"1","MaxSize":"1","LaunchConfigurationName":{"Ref":"AdminLaunchConfig"},"AvailabilityZones":["us-east-1a"]}},"WebServerGroup1":{"Type":"AWS::AutoScaling::AutoScalingGroup","Properties":{"DesiredCapacity":{"Ref":"WebServerCapacity"},"Tags":[{"Value":{"Ref":"Label"},"PropagateAtLaunch":"true","Key":"Label"},{"Value":{"Fn::Join":["",[{"Ref":"Label"}," - ","Web Instance"]]},"PropagateAtLaunch":"true","Key":"Name"}],"LoadBalancerNames":[{"Ref":"ElasticLoadBalancer"}],"MinSize":"1","MaxSize":"5","LaunchConfigurationName":{"Ref":"LaunchConfig1"},"AvailabilityZones":["us-east-1a","us-east-1d"]}},"BucketPolicy":{"Type":"AWS::S3::BucketPolicy","Properties":{"PolicyDocument":{"Version":"2008-10-17","Id":"UploadPolicy","Statement":[{"Action":["s3:GetObject","s3:PutObject","s3:PutObjectACL"],"Sid":"EnableReadWrite","Resource":{"Fn::Join":["",["arn:aws:s3:::",{"Ref":"S3Bucket"},"/*"]]},"Effect":"Allow","Principal":{"AWS":{"Fn::GetAtt":["S3User","Arn"]}}}]},"Bucket":{"Ref":"S3Bucket"}}},"S3User":{"Type":"AWS::IAM::User","Properties":{"Path":"/","Policies":[{"PolicyName":"root","PolicyDocument":{"Statement":[{"Action":"s3:*","Resource":"*","Effect":"Allow"}]}}]}},"S3Keys":{"Type":"AWS::IAM::AccessKey","Properties":{"UserName":{"Ref":"S3User"}}},"AdminLaunchConfig":{"Type":"AWS::AutoScaling::LaunchConfiguration","Properties":{"UserData":{"Fn::Base64":{"Fn::Join":["",["#!/bin/bash -v\n","export CFN_WaitHandle='",{"Ref":"WaitHandle"},"'\n","export CFN_StackId=",{"Ref":"AWS::StackId"},"\n","export CFN_Region=",{"Ref":"AWS::Region"},"\n","# MORE INJECTED BELOW \n","#!/bin/bash -v\n","\n","\n","\n","\n","\n","\n","yum update -y aws-cfn-bootstrap\n","\n","# Helper function\n","function error_exit\n","{\n"," /opt/aws/bin/cfn-signal -e 1 -r \"$1\" ${CFN_WaitHandle}\n"," exit 1\n","}\n","\n","\n","# Do some basic setup through CFN\n","/opt/aws/bin/cfn-init -s ${CFN_StackId} \\\n"," -r AdminLaunchConfig \\\n"," --region ${CFN_Region} || error_exit 'Failed to run cfn-init'\n","\n","#\n","# Load params as an environment\n","#\n","[ -r /etc/cloud-env.sh ] && source /etc/cloud-env.sh\n","\n","#==================================================\n","#\n","# From here down, the Parameters are available\n","# as environment variables.\n","#\n","# Add build steps from here down ...\n","#\n","#==================================================\n","\n","RPMS=\"httpd php php-mysql php-gd php-xml php-mbstring mysql gcc\"\n","RPMS=\"$RPMS make libstdc++-devel gcc-c++ fuse fuse-devel\"\n","RPMS=\"$RPMS libcurl-devel libxml2-devel openssl-devel mailcap git python-dateutil\"\n","\n","yum -y install $RPMS\n","\n","# Install s3cmd\n","# Added for Splunk functionality start\n","cd /home/ec2-user\n","git clone https://github.com/s3tools/s3cmd.git\n","cd s3cmd\n","python setup.py install\n","\n","# Enable system logging to s3\n","cat <<\\syslogEOF > /etc/logrotate.d/syslog\n","/var/log/cron\n","/var/log/maillog\n","/var/log/messages\n","/var/log/secure\n","/var/log/spooler\n","{\n"," missingok\n"," sharedscripts\n"," dateext\n"," dateformat -%Y-%m-%d-%s\n"," postrotate\n"," /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true\n"," BUCKET=boot_camp_logging_bucket\n"," INSTANCE_ID=`curl --silent http://169.254.169.254/latest/meta-data/instance-id | sed -e \"s/i-//\"`\n"," /usr/bin/s3cmd -m text/plain sync /var/log/messages-* s3://${BUCKET}/${INSTANCE_ID}/var/log/\n"," /usr/bin/s3cmd -m text/plain sync /var/log/cron-* s3://${BUCKET}/${INSTANCE_ID}/var/log/\n"," /usr/bin/s3cmd -m text/plain sync /var/log/maillog-* s3://${BUCKET}/${INSTANCE_ID}/var/log/\n"," /usr/bin/s3cmd -m text/plain sync /var/log/secure-* s3://${BUCKET}/${INSTANCE_ID}/var/log/\n"," /usr/bin/s3cmd -m text/plain sync /var/log/spooler-* s3://${BUCKET}/${INSTANCE_ID}/var/log/\n"," endscript\n","}\n","syslogEOF\n","\n","# Enable apache logging to s3\n","cat <<\\httpdEOF > /etc/logrotate.d/httpd\n","/var/log/httpd/*log {\n"," missingok\n"," notifempty\n"," sharedscripts\n"," dateext\n"," dateformat -%Y-%m-%d-%s\n"," postrotate\n"," BUCKET=boot_camp_logging_bucket\n"," INSTANCE_ID=`curl --silent http://169.254.169.254/latest/meta-data/instance-id | sed -e \"s/i-//\"`\n"," /usr/bin/s3cmd -m text/plain sync /var/log/httpd/*log s3://${BUCKET}/${INSTANCE_ID}/var/log/httpd/\n"," /sbin/service httpd reload > /dev/null 2>/dev/null || true\n"," endscript\n","}\n","httpdEOF\n","\n","mv /etc/cron.daily/logrotate /etc/cron.hourly/.\n","# Added for Splunk functionality end\n","\n","# Install s3fs\n","cd /home/ec2-user/s3fs/s3fs-1.61\n","./configure --prefix=/usr\n","make\n","make install\n","\n","# Move the website files to the top level\n","mv /var/www/html/drupal-7.8/* /var/www/html\n","mv /var/www/html/drupal-7.8/.htaccess /var/www/html\n","rm -Rf /var/www/html/drupal-7.8\n","\n","# Mount the S3 bucket\n","mv /var/www/html/sites/default/files /var/www/html/sites/default/files_original\n","mkdir -p /var/www/html/sites/default/files\n","s3fs -o allow_other -o use_cache=/tmp ${CFN_S3Bucket} /var/www/html/sites/default/files || error_exit 'Failed to mount the S3 bucket'\n","echo `hostname` >> /var/www/html/sites/default/files/hosts\n","\n","# Make changes to Apache Web Server configuration\n","sed -i 's/AllowOverride None/AllowOverride All/g' /etc/httpd/conf/httpd.conf\n","if [ -x /home/ec2-user/append_rewriterule.sh ]; then\n"," /home/ec2-user/append_rewriterule.sh\n","fi\n","service httpd restart\n","\n","# Only execute the site install if we are the first host up - otherwise we'll end up losing all the data\n","read first < /var/www/html/sites/default/files/hosts\n","if [ `hostname` = $first ]\n","then\n"," # Create the site in Drupal\n"," cd /var/www/html\n","\n"," DB_URL=mysql://${DB_Username}:${DB_Password}@${DB_Hostname}:${DB_Port}/${DB_Name}\n","\n"," ~ec2-user/drush/drush site-install standard \\\n"," --yes \\\n"," --site-name=\"${APP_SiteName}\" \\\n"," --site-mail=\"${APP_EMail}\" \\\n"," --account-name=\"${APP_SiteAdmin}\" \\\n"," --account-pass=\"${APP_SitePassword}\" \\\n"," --db-url=${DB_URL} \\\n"," --db-prefix=drupal_\n","\n"," # use the S3 bucket for shared file storage\n"," cp -R sites/default/files_original/* sites/default/files\n"," cp -R sites/default/files_original/.htaccess sites/default/files\n","fi\n","\n","# Copy settings.php file since everything else is configured\n","cp /home/ec2-user/settings.php /var/www/html/sites/default\n","rm /home/ec2-user/settings.php\n","mysql -u ${DB_Username} -p${DB_Password} -h ${DB_Hostname} -D ${DB_Name} -e 'update drupal_block set status = 0 where delta = \"login\"'\n","\n","# Start services\n","chkconfig httpd on && service httpd restart \n","chkconfig sendmail on && service sendmail restart \n","\n","# All is well so signal success\n","/opt/aws/bin/cfn-signal -e 0 -r \"Drupal setup complete\" ${CFN_WaitHandle}\n","\n","#======================================\n","#\n","# Install New Relic PHP module\n","#\n","#======================================\n"," NewRelicLicenseKey=\"a07c47adbd81980f702b1a9b42b5638d6fd81334\"\n","\tNR_REPO=\"http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm\"\n","\tNPI_INSTALL_URL=\"https://download.newrelic.com/npi/release/install-npi-linux-redhat-x64.sh\"\n","\texport NR_INSTALL_SILENT=true\n","\texport NR_INSTALL_KEY=${NewRelicLicenseKey}\n","\t# environment variables for NPI -- New Relic Plugin Installer\n","\texport LICENSE_KEY=${NewRelicLicenseKey}\n","\texport UNATTENDED=true\n","\t# function to install some helpful utilities\n","\tinstall_stuff() {\n","\t\tyum -y --enablerepo=epel install crudini\n","\t}\n","\t# function to install newrelic yum repo and use yum to install packages\n","\tinstall_new_relic() {\n","\t\trpm -Uvh ${NR_REPO}\n","\t\tyum -y install newrelic-php5\n","\t\tnewrelic-install install\n","\t\tyum -y install newrelic-sysmond\n","\t\tbash -c \"$(curl -sSL ${NPI_INSTALL_URL})\"\n","\t}\n","\t# function to locate and install configuration files for newrelic\n","\tconfig_new_relic() {\n","\t\tcp /etc/php.d/newrelic.ini /etc/php.d/newrelic.ini.orig\n","\t\tif [ -r /opt/aws/bootstrap/newrelic.ini ]; then\n","\t\t\tcp /opt/aws/bootstrap/newrelic.ini /etc/php.d/newrelic.ini\n","\t\telse\n","\t\t\tnrsysmond-config --set license_key=${NewRelicLicenseKey}\n","\t\tfi\n","\t\tcrudini --set /etc/php.d/newrelic.ini newrelic newrelic.appname \"${CodeFolder}_${CodeEnvironment}\"\n","\t}\n","\t# function to restart newrelic and apache after newrelic.ini has been updated\n","\tnrrestart() {\n","\t\t# Commenting the line below so that httpd doesn't actually start until the end of the execution of all helper scripts.\n","\t\t# service httpd restart\n","\t\tservice newrelic-sysmond restart\n","\t}\n","\t## MAIN ##\n","\tinstall_stuff\n","\tinstall_new_relic\n","\tconfig_new_relic\n","\tnrrestart\n"]]}},"ImageId":{"Fn::FindInMap":["AWSRegionArch2AMI",{"Ref":"AWS::Region"},{"Fn::FindInMap":["AWSInstanceType2Arch",{"Ref":"InstanceType"},"Arch"]}]},"KeyName":{"Ref":"KeyName"},"SecurityGroups":[{"Ref":"WebServerSecurityGroup"}],"IamInstanceProfile":{"Ref":"InstanceProfile"},"InstanceType":{"Ref":"InstanceType"}},"Metadata":{"AWS::CloudFormation::Init":{"config":{"files":{"/home/ec2-user/settings.php":{"content":{"Fn::Join":["",["<?php\n","\n","$databases = array (\n"," 'default' =>\n"," array (\n"," 'default' =>\n"," array (\n"," 'database' => '",{"Ref":"DBName"},"',\n"," 'username' => '",{"Ref":"DBUsername"},"',\n"," 'password' => '",{"Ref":"DBPassword"},"',\n"," 'host' => '",{"Fn::GetAtt":["MasterDB","Endpoint.Address"]},"',\n"," 'port' => '",{"Fn::GetAtt":["MasterDB","Endpoint.Port"]},"',\n"," 'driver' => 'mysql',\n"," 'prefix' => 'drupal_',\n"," ),\n"," ),\n",");\n","\n","$update_free_access = FALSE;\n","\n","$drupal_hash_salt = '0c3R8noNALe3shsioQr5hK1dMHdwRfikLoSfqn0_xpA';\n","\n","ini_set('session.gc_probability', 1);\n","ini_set('session.gc_divisor', 100);\n","ini_set('session.gc_maxlifetime', 200000);\n","ini_set('session.cookie_lifetime', 2000000);\n"]]},"owner":"root","group":"root","mode":"000444"},"/etc/passwd-s3fs":{"content":{"Fn::Join":["",[{"Ref":"S3Keys"},":",{"Fn::GetAtt":["S3Keys","SecretAccessKey"]},"\n"]]},"owner":"root","group":"root","mode":"000400"},"/etc/cloud-env.sh":{"content":{"Fn::Join":["",["export CFN_WaitHandle='",{"Ref":"WaitHandle"},"'\n","export CFN_StackId=",{"Ref":"AWS::StackId"},"\n","export CFN_Region=",{"Ref":"AWS::Region"},"\n","export CFN_S3Bucket=",{"Ref":"S3Bucket"},"\n","export APP_SiteName=",{"Ref":"SiteName"},"\n","export APP_SiteAdmin='",{"Ref":"SiteAdmin"},"'\n","export APP_SiteEmail=",{"Ref":"SiteEMail"},"\n","export APP_SitePassword=",{"Ref":"SitePassword"},"\n","export DB_Username=",{"Ref":"DBUsername"},"\n","export DB_Password=",{"Ref":"DBPassword"},"\n","export DB_Name=",{"Ref":"DBName"},"\n","export DB_Hostname=",{"Fn::GetAtt":["MasterDB","Endpoint.Address"]},"\n","export DB_Port=",{"Fn::GetAtt":["MasterDB","Endpoint.Port"]},"\n"]]},"owner":"root","group":"root","mode":"000400"}},"sources":{"/home/ec2-user":"http://ftp.drupal.org/files/projects/drush-7.x-4.5.tar.gz","/var/www/html":"http://ftp.drupal.org/files/projects/drupal-7.8.tar.gz","/home/ec2-user/s3fs":"http://s3fs.googlecode.com/files/s3fs-1.61.tar.gz"}}}}},"ElasticLoadBalancer":{"Type":"AWS::ElasticLoadBalancing::LoadBalancer","Properties":{"HealthCheck":{"HealthyThreshold":"2","Interval":"10","Target":"HTTP:80/","Timeout":"5","UnhealthyThreshold":"5"},"LBCookieStickinessPolicy":[{"PolicyName":"CookieBasedPolicy","CookieExpirationPeriod":"30"}],"AvailabilityZones":["us-east-1a","us-east-1d"],"Listeners":[{"InstancePort":"80","PolicyNames":["CookieBasedPolicy"],"LoadBalancerPort":"80","Protocol":"HTTP"}]},"Metadata":{"Comment":"Configure the Load Balancer with a simple health check and cookie-based stickiness"}},"WaitCondition":{"Type":"AWS::CloudFormation::WaitCondition","Properties":{"Handle":{"Ref":"WaitHandle"},"Timeout":"3000"},"DependsOn":"WebServerGroup1"},"MasterDB":{"DeletionPolicy":"Snapshot","Type":"AWS::RDS::DBInstance","Properties":{"Engine":"MySQL","MultiAZ":{"Ref":"MultiAZDatabase"},"DBSecurityGroups":[{"Ref":"DBSecurityGroup"}],"Tags":[{"Key":"Name","Value":{"Fn::Join":["",[{"Ref":"Label"}," - ","Master Database"]]}}],"MasterUsername":{"Ref":"DBUsername"},"MasterUserPassword":{"Ref":"DBPassword"},"AllocatedStorage":{"Ref":"DBAllocatedStorage"},"EngineVersion":"5.6","DBInstanceClass":{"Ref":"DBClass"},"DBName":{"Ref":"DBName"},"DBInstanceIdentifier":{"Fn::Join":["",[{"Ref":"Label"},"MasterDatabase"]]}}},"LaunchConfig1":{"Type":"AWS::AutoScaling::LaunchConfiguration","Properties":{"UserData":{"Fn::Base64":{"Fn::Join":["",["#!/bin/bash -v\n","export CFN_WaitHandle='",{"Ref":"WaitHandle"},"'\n","export CFN_StackId=",{"Ref":"AWS::StackId"},"\n","export CFN_Region=",{"Ref":"AWS::Region"},"\n","# MORE INJECTED BELOW \n","#!/bin/bash -v\n","\n","\n","\n","\n","\n","\n","yum update -y aws-cfn-bootstrap\n","\n","# Helper function\n","function error_exit\n","{\n"," /opt/aws/bin/cfn-signal -e 1 -r \"$1\" ${CFN_WaitHandle}\n"," exit 1\n","}\n","\n","\n","# Do some basic setup through CFN\n","/opt/aws/bin/cfn-init -s ${CFN_StackId} \\\n"," -r LaunchConfig1 \\\n"," --region ${CFN_Region} || error_exit 'Failed to run cfn-init'\n","\n","#\n","# Load params as an environment\n","#\n","[ -r /etc/cloud-env.sh ] && source /etc/cloud-env.sh\n","\n","#==================================================\n","#\n","# From here down, the Parameters are available\n","# as environment variables.\n","#\n","# Add build steps from here down ...\n","#\n","#==================================================\n","\n","RPMS=\"httpd php php-mysql php-gd php-xml php-mbstring mysql gcc\"\n","RPMS=\"$RPMS make libstdc++-devel gcc-c++ fuse fuse-devel\"\n","RPMS=\"$RPMS libcurl-devel libxml2-devel openssl-devel mailcap git python-dateutil\"\n","\n","yum -y install $RPMS\n","\n","# Install s3cmd\n","# Added for Splunk functionality start\n","cd /home/ec2-user\n","git clone https://github.com/s3tools/s3cmd.git\n","cd s3cmd\n","python setup.py install\n","\n","# Enable system logging to s3\n","cat <<\\syslogEOF > /etc/logrotate.d/syslog\n","/var/log/cron\n","/var/log/maillog\n","/var/log/messages\n","/var/log/secure\n","/var/log/spooler\n","{\n"," missingok\n"," sharedscripts\n"," dateext\n"," dateformat -%Y-%m-%d-%s\n"," postrotate\n"," /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true\n"," BUCKET=boot_camp_logging_bucket\n"," INSTANCE_ID=`curl --silent http://169.254.169.254/latest/meta-data/instance-id | sed -e \"s/i-//\"`\n"," /usr/bin/s3cmd -m text/plain sync /var/log/messages-* s3://${BUCKET}/${INSTANCE_ID}/var/log/\n"," /usr/bin/s3cmd -m text/plain sync /var/log/cron-* s3://${BUCKET}/${INSTANCE_ID}/var/log/\n"," /usr/bin/s3cmd -m text/plain sync /var/log/maillog-* s3://${BUCKET}/${INSTANCE_ID}/var/log/\n"," /usr/bin/s3cmd -m text/plain sync /var/log/secure-* s3://${BUCKET}/${INSTANCE_ID}/var/log/\n"," /usr/bin/s3cmd -m text/plain sync /var/log/spooler-* s3://${BUCKET}/${INSTANCE_ID}/var/log/\n"," endscript\n","}\n","syslogEOF\n","\n","# Enable apache logging to s3\n","cat <<\\httpdEOF > /etc/logrotate.d/httpd\n","/var/log/httpd/*log {\n"," missingok\n"," notifempty\n"," sharedscripts\n"," dateext\n"," dateformat -%Y-%m-%d-%s\n"," postrotate\n"," BUCKET=boot_camp_logging_bucket\n"," INSTANCE_ID=`curl --silent http://169.254.169.254/latest/meta-data/instance-id | sed -e \"s/i-//\"`\n"," /usr/bin/s3cmd -m text/plain sync /var/log/httpd/*log s3://${BUCKET}/${INSTANCE_ID}/var/log/httpd/\n"," /sbin/service httpd reload > /dev/null 2>/dev/null || true\n"," endscript\n","}\n","httpdEOF\n","\n","mv /etc/cron.daily/logrotate /etc/cron.hourly/.\n","# Added for Splunk functionality end\n","\n","# Install s3fs\n","cd /home/ec2-user/s3fs/s3fs-1.61\n","./configure --prefix=/usr\n","make\n","make install\n","\n","# Move the website files to the top level\n","mv /var/www/html/drupal-7.8/* /var/www/html\n","mv /var/www/html/drupal-7.8/.htaccess /var/www/html\n","rm -Rf /var/www/html/drupal-7.8\n","\n","# Mount the S3 bucket\n","mv /var/www/html/sites/default/files /var/www/html/sites/default/files_original\n","mkdir -p /var/www/html/sites/default/files\n","s3fs -o allow_other -o use_cache=/tmp ${CFN_S3Bucket} /var/www/html/sites/default/files || error_exit 'Failed to mount the S3 bucket'\n","echo `hostname` >> /var/www/html/sites/default/files/hosts\n","\n","# Make changes to Apache Web Server configuration\n","sed -i 's/AllowOverride None/AllowOverride All/g' /etc/httpd/conf/httpd.conf\n","if [ -x /home/ec2-user/append_rewriterule.sh ]; then\n"," /home/ec2-user/append_rewriterule.sh\n","fi\n","service httpd restart\n","\n","# Only execute the site install if we are the first host up - otherwise we'll end up losing all the data\n","read first < /var/www/html/sites/default/files/hosts\n","if [ `hostname` = $first ]\n","then\n"," # Create the site in Drupal\n"," cd /var/www/html\n","\n"," DB_URL=mysql://${DB_Username}:${DB_Password}@${DB_Hostname}:${DB_Port}/${DB_Name}\n","\n"," ~ec2-user/drush/drush site-install standard \\\n"," --yes \\\n"," --site-name=\"${APP_SiteName}\" \\\n"," --site-mail=\"${APP_EMail}\" \\\n"," --account-name=\"${APP_SiteAdmin}\" \\\n"," --account-pass=\"${APP_SitePassword}\" \\\n"," --db-url=${DB_URL} \\\n"," --db-prefix=drupal_\n","\n"," # use the S3 bucket for shared file storage\n"," cp -R sites/default/files_original/* sites/default/files\n"," cp -R sites/default/files_original/.htaccess sites/default/files\n","fi\n","\n","# Copy settings.php file since everything else is configured\n","cp /home/ec2-user/settings.php /var/www/html/sites/default\n","rm /home/ec2-user/settings.php\n","mysql -u ${DB_Username} -p${DB_Password} -h ${DB_Hostname} -D ${DB_Name} -e 'update drupal_block set status = 0 where delta = \"login\"'\n","\n","# Start services\n","chkconfig httpd on && service httpd restart \n","chkconfig sendmail on && service sendmail restart \n","\n","# All is well so signal success\n","/opt/aws/bin/cfn-signal -e 0 -r \"Drupal setup complete\" ${CFN_WaitHandle}\n","\n","#======================================\n","#\n","# Install New Relic PHP module\n","#\n","#======================================\n"," NewRelicLicenseKey=\"a07c47adbd81980f702b1a9b42b5638d6fd81334\"\n","\tNR_REPO=\"http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm\"\n","\tNPI_INSTALL_URL=\"https://download.newrelic.com/npi/release/install-npi-linux-redhat-x64.sh\"\n","\texport NR_INSTALL_SILENT=true\n","\texport NR_INSTALL_KEY=${NewRelicLicenseKey}\n","\t# environment variables for NPI -- New Relic Plugin Installer\n","\texport LICENSE_KEY=${NewRelicLicenseKey}\n","\texport UNATTENDED=true\n","\t# function to install some helpful utilities\n","\tinstall_stuff() {\n","\t\tyum -y --enablerepo=epel install crudini\n","\t}\n","\t# function to install newrelic yum repo and use yum to install packages\n","\tinstall_new_relic() {\n","\t\trpm -Uvh ${NR_REPO}\n","\t\tyum -y install newrelic-php5\n","\t\tnewrelic-install install\n","\t\tyum -y install newrelic-sysmond\n","\t\tbash -c \"$(curl -sSL ${NPI_INSTALL_URL})\"\n","\t}\n","\t# function to locate and install configuration files for newrelic\n","\tconfig_new_relic() {\n","\t\tcp /etc/php.d/newrelic.ini /etc/php.d/newrelic.ini.orig\n","\t\tif [ -r /opt/aws/bootstrap/newrelic.ini ]; then\n","\t\t\tcp /opt/aws/bootstrap/newrelic.ini /etc/php.d/newrelic.ini\n","\t\telse\n","\t\t\tnrsysmond-config --set license_key=${NewRelicLicenseKey}\n","\t\tfi\n","\t\tcrudini --set /etc/php.d/newrelic.ini newrelic newrelic.appname \"${CodeFolder}_${CodeEnvironment}\"\n","\t}\n","\t# function to restart newrelic and apache after newrelic.ini has been updated\n","\tnrrestart() {\n","\t\t# Commenting the line below so that httpd doesn't actually start until the end of the execution of all helper scripts.\n","\t\t# service httpd restart\n","\t\tservice newrelic-sysmond restart\n","\t}\n","\t## MAIN ##\n","\tinstall_stuff\n","\tinstall_new_relic\n","\tconfig_new_relic\n","\tnrrestart\n"]]}},"ImageId":{"Fn::FindInMap":["AWSRegionArch2AMI",{"Ref":"AWS::Region"},{"Fn::FindInMap":["AWSInstanceType2Arch",{"Ref":"InstanceType"},"Arch"]}]},"KeyName":{"Ref":"KeyName"},"SecurityGroups":[{"Ref":"WebServerSecurityGroup"}],"IamInstanceProfile":{"Ref":"InstanceProfile"},"InstanceType":{"Ref":"InstanceType"}},"Metadata":{"AWS::CloudFormation::Init":{"config":{"files":{"/home/ec2-user/append_rewriterule.sh":{"content":{"Fn::Join":["",["#!/bin/bash\n","sed -i '/RewriteEngine on/a RewriteRule ^(scripts|profile|includes|cron\\.php|install\\.php|update\\.php|xmlrpc\\.php|filter($|/)|user($|/)|admin($|/)) - [F,L]' /var/www/html/.htaccess\n"]]},"owner":"root","group":"root","mode":"000544"},"/home/ec2-user/settings.php":{"content":{"Fn::Join":["",["<?php\n","\n","$databases = array (\n"," 'default' =>\n"," array (\n"," 'default' =>\n"," array (\n"," 'database' => '",{"Ref":"DBName"},"',\n"," 'username' => '",{"Ref":"DBUsername"},"',\n"," 'password' => '",{"Ref":"DBPassword"},"',\n"," 'host' => '",{"Fn::GetAtt":["MasterDB","Endpoint.Address"]},"',\n"," 'port' => '",{"Fn::GetAtt":["MasterDB","Endpoint.Port"]},"',\n"," 'driver' => 'mysql',\n"," 'prefix' => 'drupal_',\n"," ),\n"," ),\n",");\n","\n","$update_free_access = FALSE;\n","\n","$drupal_hash_salt = '0c3R8noNALe3shsioQr5hK1dMHdwRfikLoSfqn0_xpA';\n","\n","ini_set('session.gc_probability', 1);\n","ini_set('session.gc_divisor', 100);\n","ini_set('session.gc_maxlifetime', 200000);\n","ini_set('session.cookie_lifetime', 2000000);\n"]]},"owner":"root","group":"root","mode":"000444"},"/etc/passwd-s3fs":{"content":{"Fn::Join":["",[{"Ref":"S3Keys"},":",{"Fn::GetAtt":["S3Keys","SecretAccessKey"]},"\n"]]},"owner":"root","group":"root","mode":"000400"},"/etc/cloud-env.sh":{"content":{"Fn::Join":["",["export CFN_WaitHandle='",{"Ref":"WaitHandle"},"'\n","export CFN_StackId='",{"Ref":"AWS::StackId"},"'\n","export CFN_Region='",{"Ref":"AWS::Region"},"'\n","export CFN_S3Bucket='",{"Ref":"S3Bucket"},"'\n","export APP_SiteName='",{"Ref":"SiteName"},"'\n","export APP_SiteAdmin='",{"Ref":"SiteAdmin"},"'\n","export APP_SiteEmail='",{"Ref":"SiteEMail"},"'\n","export APP_SitePassword='",{"Ref":"SitePassword"},"'\n","export DB_Username='",{"Ref":"DBUsername"},"'\n","export DB_Password='",{"Ref":"DBPassword"},"'\n","export DB_Name='",{"Ref":"DBName"},"'\n","export DB_Hostname='",{"Fn::GetAtt":["MasterDB","Endpoint.Address"]},"'\n","export DB_Port='",{"Fn::GetAtt":["MasterDB","Endpoint.Port"]},"'\n"]]},"owner":"root","group":"root","mode":"000400"}},"sources":{"/home/ec2-user":"http://ftp.drupal.org/files/projects/drush-7.x-4.5.tar.gz","/var/www/html":"http://ftp.drupal.org/files/projects/drupal-7.8.tar.gz","/home/ec2-user/s3fs":"http://s3fs.googlecode.com/files/s3fs-1.61.tar.gz"}}}}},"InstanceProfile":{"Type":"AWS::IAM::InstanceProfile","Properties":{"Path":"/","Roles":[{"Ref":"S3LoggingRole"}]}},"WaitHandle":{"Type":"AWS::CloudFormation::WaitConditionHandle"}},"Mappings":{"AWSInstanceType2Arch":{"m1.medium":{"Arch":"64"},"m3.2xlarge":{"Arch":"64"},"cc2.8xlarge":{"Arch":"64HVM"},"m1.large":{"Arch":"64"},"m2.2xlarge":{"Arch":"64"},"m1.small":{"Arch":"64"},"c1.medium":{"Arch":"64"},"cg1.4xlarge":{"Arch":"64HVM"},"m1.xlarge":{"Arch":"64"},"m2.xlarge":{"Arch":"64"},"t1.micro":{"Arch":"64"},"m2.4xlarge":{"Arch":"64"},"c1.xlarge":{"Arch":"64"},"m3.xlarge":{"Arch":"64"},"cc1.4xlarge":{"Arch":"64HVM"}},"AWSRegionArch2AMI":{"us-east-1":{"64HVM":"ami-a8cd60c1","32":"ami-a0cd60c9","64":"ami-aecd60c7"},"ap-northeast-1":{"64HVM":"NOT_YET_SUPPORTED","32":"ami-2a19aa2b","64":"ami-2819aa29"},"eu-west-1":{"64HVM":"ami-67555113","32":"ami-61555115","64":"ami-6d555119"},"ap-southeast-1":{"64HVM":"NOT_YET_SUPPORTED","32":"ami-220b4a70","64":"ami-3c0b4a6e"},"ap-southeast-2":{"64HVM":"NOT_YET_SUPPORTED","32":"ami-8f990eb5","64":"ami-95990eaf"},"us-west-2":{"64HVM":"NOT_YET_SUPPORTED","32":"ami-46da5576","64":"ami-48da5578"},"us-west-1":{"64HVM":"NOT_YET_SUPPORTED","32":"ami-7d4c6938","64":"ami-734c6936"},"sa-east-1":{"64HVM":"NOT_YET_SUPPORTED","32":"ami-f836e8e5","64":"ami-fe36e8e3"}}}}