Skip to content

Instantly share code, notes, and snippets.

@usmanismail
Created October 20, 2012 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save usmanismail/3923120 to your computer and use it in GitHub Desktop.
Save usmanismail/3923120 to your computer and use it in GitHub Desktop.
A cloud front template to bring up a seyren node
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation Sample Template creates a seyren application. The template uses the WaitCondition resource to synchronize creation of the stack with the application becoming healthy. **WARNING** This template creates an Amazon EC2 instance and an Elastic IP Address. You will be billed for the AWS resources used if you create a stack from this template.",
"Parameters" : {
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance",
"Type" : "String"
},
"GraphiteUrl" : {
"Description" : "The graphite url where you want to load data from",
"Type" : "String"
},
"SeyrenUrl" : {
"Description" : "The location of your seyren instance. Default: http://localhost:8080/seyren",
"Type" : "String",
"Default" : "http://localhost:8080/seyren"
},
"MongoUrl" : {
"Description" : "The mongo connection string. Default: mongodb://localhost:27017/seyren",
"Type" : "String",
"Default" : "mongodb://localhost:27017/seyren"
},
"SmtpHost" : {
"Description" : "The smtp server to send email notifications from. Default: localhost",
"Type" : "String",
"Default" : "localhost"
},
"SmtpPort" : {
"Description" : "The smtp server port. Default: 25",
"Type" : "String",
"Default" : "25"
},
"SmtpUsername" : {
"Description" : "The smtp server username if authenticated SMTP is used. Default: ``",
"Type" : "String",
"Default" : ""
},
"SmtpPassword" : {
"Description" : "The smtp server password if authenticated SMTP is used. Default: ``",
"Type" : "String",
"Default" : ""
},
"InstanceType" : {
"Description" : "WebServer EC2 instance type",
"Type" : "String",
"Default" : "m1.small",
"AllowedValues" : ["m1.small","m1.medium","m1.large","m1.xlarge","m2.xlarge","m2.2xlarge","m2.4xlarge","c1.medium","c1.xlarge","cc1.4xlarge","cc2.8xlarge","cg1.4xlarge"],
"ConstraintDescription" : "must be a valid EC2 instance type."
}
},
"Mappings" : {
"AWSInstanceType2Arch" : {
"t1.micro" : { "Arch" : "64" },
"m1.small" : { "Arch" : "64" },
"m1.medium" : { "Arch" : "64" },
"m1.large" : { "Arch" : "64" },
"m1.xlarge" : { "Arch" : "64" },
"m2.xlarge" : { "Arch" : "64" },
"m2.2xlarge" : { "Arch" : "64" },
"m2.4xlarge" : { "Arch" : "64" },
"c1.medium" : { "Arch" : "64" },
"c1.xlarge" : { "Arch" : "64" },
"cc1.4xlarge" : { "Arch" : "64HVM" },
"cc2.8xlarge" : { "Arch" : "64HVM" },
"cg1.4xlarge" : { "Arch" : "64HVM" }
},
"AWSRegionArch2AMI" : {
"us-east-1" : { "32" : "ami-31814f58", "64" : "ami-1b814f72", "64HVM" : "ami-0da96764" },
"us-west-2" : { "32" : "ami-38fe7308", "64" : "ami-30fe7300", "64HVM" : "NOT_YET_SUPPORTED" },
"us-west-1" : { "32" : "ami-11d68a54", "64" : "ami-1bd68a5e", "64HVM" : "NOT_YET_SUPPORTED" },
"eu-west-1" : { "32" : "ami-973b06e3", "64" : "ami-953b06e1", "64HVM" : "NOT_YET_SUPPORTED" },
"ap-southeast-1" : { "32" : "ami-b4b0cae6", "64" : "ami-beb0caec", "64HVM" : "NOT_YET_SUPPORTED" },
"ap-northeast-1" : { "32" : "ami-0644f007", "64" : "ami-0a44f00b", "64HVM" : "NOT_YET_SUPPORTED" },
"sa-east-1" : { "32" : "ami-3e3be423", "64" : "ami-3c3be421", "64HVM" : "NOT_YET_SUPPORTED" }
}
},
"Resources" : {
"Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"KeyName" : { "Ref" : "KeyName" },
"SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],
"ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
{ "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
"InstanceType" : { "Ref" : "InstanceType" },
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["",[
"#!/bin/bash -ex","\n",
"yum install java-1.7.0-openjdk-devel.x86_64 -y\n",
"#### Install MongoDB ####\n",
"cd /opt\n",
"curl http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.2.0.tgz > mongo.tgz\n",
"tar -zxvf mongo.tgz \n",
"mv mongodb-linux-x86_64-2.2.0 mongodb\n",
"mkdir -p /data/db\n",
"mkdir -p /var/log/mongodb\n",
"cat > /etc/mongod.conf << EOF\n",
"# Append logs to /var/log/mongodb/mongo.log\n",
"logpath = /var/log/mongodb/mongo.log\n",
"logappend = true\n",
"fork = true\n",
"EOF\n",
"cd mongodb/bin\n",
"chmod 700 ./mongod\n",
"./mongod --config /etc/mongod.conf\n",
"#### Install Seyren ####\n",
"cd /opt\n",
"wget -O /opt/maven.tar.gz http://mirror.olnevhost.net/pub/apache/maven/maven-3/3.0.4/binaries/apache-maven-3.0.4-bin.tar.gz\n",
"wget -O /opt/seyren.tar https://github.com/scobal/seyren/tarball/master\n",
"tar -zxvf maven.tar.gz\n",
"tar -xvf seyren.tar\n",
"export M2_HOME=/opt/apache-maven-3.0.4\n",
"export M2=$M2_HOME/bin\n",
"export PATH=$M2:$PATH\n",
"cd scobal-seyren*\n",
"mvn clean package\n",
"#### Start Seyren ####\n",
"export GRAPHITE_URL=", {"Ref" : "GraphiteUrl"}, "\n",
"export SEYREN_URL=", {"Ref" : "SeyrenUrl"}, "\n",
"export MONGO_URL=", {"Ref" : "MongoUrl"}, "\n",
"export SMTP_HOST=", {"Ref" : "SmtpHost"}, "\n",
"export SMTP_PORT=", {"Ref" : "SmtpPort"}, "\n",
"export SMTP_USERNAME=", {"Ref" : "SmtpUsername"}, "\n",
"export SMTP_PASSWORD=", {"Ref" : "SmtpPassword"}, "\n",
"curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\" : \"SUCCESS\",",
"\"Reason\" : \"Seyren is ready\",",
"\"UniqueId\" : \"Seyren\",",
"\"Data\" : \"Done\"}' ",
"\"", {"Ref" : "WaitForInstanceWaitHandle"},"\"\n",
"nohup java -jar seyren-web/target/dependency/jetty-runner.jar --path /seyren seyren-web/target/*.war 2>&1\n"
]]}}
}
},
"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable Access to Rails application via port 3000 and SSH access via port 22",
"SecurityGroupIngress" : [
{"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0" },
{"IpProtocol" : "tcp", "FromPort" : "8080", "ToPort" : "8080", "CidrIp" : "0.0.0.0/0" }
]
}
},
"WaitForInstanceWaitHandle" : {
"Type" : "AWS::CloudFormation::WaitConditionHandle",
"Properties" : {
}
},
"WaitForInstance" : {
"Type" : "AWS::CloudFormation::WaitCondition",
"DependsOn" : "Ec2Instance",
"Properties" : {
"Handle" : {"Ref" : "WaitForInstanceWaitHandle"},
"Timeout" : "600"
}
}
},
"Outputs" : {
"WebsiteURL" : {
"Description" : "The URL for the newly created Rails application",
"Value" : { "Fn::Join" : ["", [ "http://", { "Fn::GetAtt" : [ "Ec2Instance", "PublicDnsName" ] }, ":3000" ]]}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment