Skip to content

Instantly share code, notes, and snippets.

@sjoonk
Created November 23, 2011 06:30
Show Gist options
  • Save sjoonk/1388026 to your computer and use it in GitHub Desktop.
Save sjoonk/1388026 to your computer and use it in GitHub Desktop.
AWS Facebook PHP template
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Launch your Facebook applications within minutes. This template will create a Facebook Stack and configure a social file sharing sample application that upload files to Amazon S3 and notifies your friends by posting it on your wall. **WARNING** This template takes advantage of the AWS Free Usage Tier and if you are eligible since it creates one or more Amazon EC2 instances and a Elastic Load balancer. You will be billed for the AWS resources used.",
"Parameters": {
"AppURL": {
"Default": "http://aws-facebook.s3.amazonaws.com/aws-facebook-php-v2.tar.gz",
"Description": "URL of the application to be deployed",
"Type": "String"
},
"FacebookAppId": {
"Description" : "The facebook application id",
"Type": "Number",
"MinLength": "1",
"MaxLength": "64",
"AllowedPattern" : "[0-9]+",
"ConstraintDescription" : "must contain only numeric characters and cannot contain any spaces."
},
"FacebookSecretKey": {
"Description" : "The facebook application secret key",
"Type": "String",
"MinLength": "1",
"MaxLength": "64",
"AllowedPattern" : "[a-zA-Z0-9]+",
"ConstraintDescription" : "must contain only alphanumeric characters and cannot contain any spaces."
},
"FacebookNamespace": {
"Description" : "The facebook application namespace",
"Type": "String",
"MinLength": "1",
"AllowedPattern" : "[a-z-_]+",
"MaxLength": "64",
"ConstraintDescription" : "must contain contain lowercase letters, dashes, and underscores."
},
"AWSAccessKeyId" : {
"Type" : "String",
"MinLength" : "20",
"MaxLength" : "20",
"NoEcho" : "true",
"Description" : "Enter the AWS Access Key Id of the account to query"
},
"AWSSecretAccessKey" : {
"Type" : "String",
"MinLength" : "40",
"MaxLength" : "40",
"NoEcho" : "true",
"Description" : "Enter the AWS Secret Key of the account to query"
},
"KeyName": {
"Type": "String",
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the web server"
},
"InstanceType": {
"Default": "t1.micro",
"Type": "String",
"Description" : "Type of EC2 instance for web server"
},
"OperatorEmail": {
"Default": "nobody@amazon.com",
"Description": "Email address to notify if there are any operational issues",
"Type": "String"
},
"WebServerPort": {
"Default": "8888",
"Type": "Number",
"MinValue": "1",
"MaxValue": "65535",
"Description" : "TCP/IP port for the web server"
}
},
"Resources": {
"S3Bucket" : {
"Type" : "AWS::S3::Bucket",
"Properties" : {
"AccessControl" : "Private"
}
},
"CPUAlarmHigh": {
"Properties": {
"EvaluationPeriods": "1",
"Statistic": "Average",
"Threshold": "10",
"AlarmDescription": "Alarm if CPU too high or metric disappears indicating instance is down",
"Period": "60",
"AlarmActions": [
{
"Ref": "AlarmTopic"
}
],
"Namespace": "AWS/EC2",
"InsufficientDataActions": [
{
"Ref": "AlarmTopic"
}
],
"Dimensions": [
{
"Name": "AutoScalingGroupName",
"Value": {
"Ref": "WebServerGroup"
}
}
],
"ComparisonOperator": "GreaterThanThreshold",
"MetricName": "CPUUtilization"
},
"Type": "AWS::CloudWatch::Alarm"
},
"TooManyUnhealthyHostsAlarm": {
"Properties": {
"EvaluationPeriods": "1",
"Statistic": "Average",
"Threshold": "0",
"AlarmDescription": "Alarm if there are too many unhealthy hosts.",
"Period": "60",
"AlarmActions": [
{
"Ref": "AlarmTopic"
}
],
"Namespace": "AWS/ELB",
"InsufficientDataActions": [
{
"Ref": "AlarmTopic"
}
],
"Dimensions": [
{
"Name": "LoadBalancerName",
"Value": {
"Ref": "ElasticLoadBalancer"
}
}
],
"ComparisonOperator": "GreaterThanThreshold",
"MetricName": "UnHealthyHostCount"
},
"Type": "AWS::CloudWatch::Alarm"
},
"EC2SecurityGroup": {
"Properties": {
"SecurityGroupIngress": [
{
"FromPort": "22",
"CidrIp": "0.0.0.0/0",
"ToPort": "22",
"IpProtocol": "tcp"
},
{
"FromPort": {
"Ref": "WebServerPort"
},
"CidrIp": "0.0.0.0/0",
"ToPort": {
"Ref": "WebServerPort"
},
"IpProtocol": "tcp"
}
],
"GroupDescription": "HTTP and SSH access"
},
"Type": "AWS::EC2::SecurityGroup"
},
"RequestLatencyAlarmHigh": {
"Properties": {
"EvaluationPeriods": "1",
"Statistic": "Average",
"Threshold": "1",
"AlarmDescription": "Alarm if there aren't any requests coming through",
"Period": "60",
"AlarmActions": [
{
"Ref": "AlarmTopic"
}
],
"Namespace": "AWS/ELB",
"InsufficientDataActions": [
{
"Ref": "AlarmTopic"
}
],
"Dimensions": [
{
"Name": "LoadBalancerName",
"Value": {
"Ref": "ElasticLoadBalancer"
}
}
],
"ComparisonOperator": "GreaterThanThreshold",
"MetricName": "Latency"
},
"Type": "AWS::CloudWatch::Alarm"
},
"ElasticLoadBalancer": {
"Properties": {
"Listeners": [
{
"InstancePort": {
"Ref": "WebServerPort"
},
"PolicyNames": [
"p1"
],
"Protocol": "HTTP",
"LoadBalancerPort": "80"
}
],
"HealthCheck": {
"HealthyThreshold": "2",
"Timeout": "5",
"Interval": "10",
"UnhealthyThreshold": "5",
"Target": {
"Fn::Join": [
"",
[
"HTTP:",
{
"Ref": "WebServerPort"
},
"/",{"Ref" : "FacebookNamespace" },"/"
]
]
}
},
"AvailabilityZones": [
{
"Fn::Join": [
"",
[
{
"Ref": "AWS::Region"
},
"a"
]
]
}
],
"LBCookieStickinessPolicy": [
{
"CookieExpirationPeriod": "30",
"PolicyName": "p1"
}
]
},
"Type": "AWS::ElasticLoadBalancing::LoadBalancer"
},
"WebServerGroup": {
"Properties": {
"LoadBalancerNames": [
{
"Ref": "ElasticLoadBalancer"
}
],
"MinSize": "1",
"LaunchConfigurationName": {
"Ref": "LaunchConfig"
},
"AvailabilityZones": [
{
"Fn::Join": [
"",
[
{
"Ref": "AWS::Region"
},
"a"
]
]
}
],
"MaxSize": "3"
},
"Type": "AWS::AutoScaling::AutoScalingGroup"
},
"AlarmTopic": {
"Properties": {
"Subscription": [
{
"Endpoint": {
"Ref": "OperatorEmail"
},
"Protocol": "email"
}
]
},
"Type": "AWS::SNS::Topic"
},
"LaunchConfig": {
"Properties": {
"SecurityGroups": [
{
"Ref": "EC2SecurityGroup"
}
],
"ImageId": {
"Fn::FindInMap": [
"AWSRegionArch2AMI",
{
"Ref": "AWS::Region"
},
{
"Fn::FindInMap": [
"AWSInstanceType2Arch",
{
"Ref": "InstanceType"
},
"Arch"
]
}
]
},
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash -ex\n",
"yum -y install git-core\n",
"yum -y install php-pear\n",
"pear install Crypt_HMAC2-1.0.0\n",
"pear install HTTP_Request-1.4.4\n",
"pear channel-discover pear.amazonwebservices.com\n",
"pear install aws/sdk\n",
"cd /var/www/html","\n",
"rm -f index.php","\n",
"mkdir ", {"Ref" : "FacebookNamespace" } ,"\n",
"cd ",{"Ref" : "FacebookNamespace" } ,"\n",
"curl ",{"Ref": "AppURL" } ," | tar xz --strip-components 1","\n",
"git clone git://github.com/facebook/php-sdk.git","\n",
"chmod -R 755 /var/www/html/",{"Ref" : "FacebookNamespace" }, "\n",
"chown -R root:root /var/www/html/",{"Ref" : "FacebookNamespace" }, "\n",
"AWSAccessKeyId=" , {"Ref" : "AWSAccessKeyId" }, "\n",
"AWSSecretAccessKey=" , {"Ref" : "AWSSecretAccessKey" }, "\n",
"FacebookAppId=" , {"Ref" : "FacebookAppId" }, "\n",
"FacebookSecretKey=" , {"Ref" : "FacebookSecretKey" }, "\n",
"FacebookNamespace=" , {"Ref" : "FacebookNamespace" }, "\n",
"S3BucketName=" , {"Ref" : "S3Bucket" }, "\n",
"echo \"AWSAccessKeyId=$AWSAccessKeyId" ,"\n",
"AWSSecretAccessKey=$AWSSecretAccessKey" ,"\n",
"FacebookAppId=$FacebookAppId" ,"\n",
"FacebookSecretKey=$FacebookSecretKey" ,"\n",
"FacebookNamespace=$FacebookNamespace" ,"\n",
"S3BucketName=$S3BucketName\" > /opt/fb_config.txt","\n",
"chmod 744 /opt/fb_config.txt","\n",
"sed -i '/^[a-z\/ ]/ s/^/#/' /etc/rc.local","\n",
"touch /var/lock/subsys/local","\n",
"sed \"s/Listen 80/Listen 0.0.0.0:",{"Ref":"WebServerPort"},"/g\" < /etc/httpd/conf/httpd.conf >/etc/httpd/conf/hwphp-httpd.conf","\n",
"/usr/sbin/apachectl -k start -f /etc/httpd/conf/hwphp-httpd.conf","\n"
]
]
}
},
"KeyName": {
"Ref": "KeyName"
},
"InstanceType": {
"Ref": "InstanceType"
}
},
"Type": "AWS::AutoScaling::LaunchConfiguration"
}
},
"Mappings" : { "AWSInstanceType2Arch" : {
"t1.micro" : { "Arch" : "64" },
"m1.small" : { "Arch" : "32" },
"m1.large" : { "Arch" : "64" },
"m1.xlarge" : { "Arch" : "64" },
"m2.xlarge" : { "Arch" : "64" },
"m2.2xlarge" : { "Arch" : "64" },
"m2.4xlarge" : { "Arch" : "64" },
"c1.medium" : { "Arch" : "32" },
"c1.xlarge" : { "Arch" : "64" },
"cc1.4xlarge" : { "Arch" : "64" }
},
"AWSRegionArch2AMI" : {
"us-east-1" : { "32" : "ami-c813e0a1", "64" : "ami-c213e0ab" },
"us-west-1" : { "32" : "ami-09c7974c", "64" : "ami-0bc7974e" },
"eu-west-1" : { "32" : "ami-6bc2f61f", "64" : "ami-6fc2f61b" },
"ap-southeast-1" : { "32" : "ami-70f28c22", "64" : "ami-72f28c20" },
"ap-northeast-1" : { "32" : "ami-ac03a8ad", "64" : "ami-b003a8b1" }
}
},
"Outputs": {
"SiteURL": {
"Value": {
"Fn::Join": [
"",
[
"http://",
{
"Fn::GetAtt": [
"ElasticLoadBalancer",
"DNSName"
]
},
"/",{"Ref" : "FacebookNamespace" },"/"
]
]
},
"Description" : "URL of the website"
},
"S3BucketSecureURL" : {
"Value" : { "Fn::Join" : [ "", [ "https://", { "Fn::GetAtt" : [ "S3Bucket", "DomainName" ] } ] ] },
"Description" : "Name of S3 bucket to hold user uploaded files"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment