Created
March 4, 2013 20:13
-
-
Save usmanismail/5085216 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Description": "A template to install mysql and jetty", | |
"Parameters": { | |
"KeyName": { | |
"Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", | |
"Type": "String" | |
}, | |
"ContextUrl": { | |
"Description": "A URL for the jetty context file", | |
"Type": "String" | |
}, | |
"WarUrl": { | |
"Description": "A URL for the jetty war file", | |
"Type": "String" | |
}, | |
"MySqlDump": { | |
"Description": "A URL for the mysql dump to be imported", | |
"Type": "String" | |
}, | |
"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 mysql-server\n", | |
"mysql -uroot -e 'create database getsatisfaction;'\n", | |
"curl http://mirrors.med.harvard.edu/eclipse/jetty/stable-7/dist/jetty-distribution-7.6.9.v20130131.tar.gz > jetty.tgz\n", | |
"tar -zxvf jetty.tgz \n", | |
"ln -s jetty-distribution-7.6.9.v20130131 jetty\n", | |
"curl ", | |
{ | |
"Ref": "ContextUrl" | |
}, | |
" > jetty/contexts/getsatisfaction.xml\n", | |
"curl ", | |
{ | |
"Ref": "WarUrl" | |
}, | |
"> jetty/webapps/getsatisfaction.war\n", | |
"curl ", | |
{ | |
"Ref": "MySqlDump" | |
}, | |
" > mysql_dump.sql\n", | |
"mysql -uroot getsatisfaction < mysql_dump.sql\n", | |
"curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\" : \"SUCCESS\",", | |
"\"Reason\" : \"Seyren is ready\",", | |
"\"UniqueId\" : \"Seyren\",", | |
"\"Data\" : \"Done\"}' ", | |
"\"", | |
{ | |
"Ref": "WaitForInstanceWaitHandle" | |
}, | |
"\"\n | |
"cd jetty\n", | |
"nohup java -jar start.jar 2>&1\n" | |
] | |
] | |
} | |
} | |
} | |
}, | |
"InstanceSecurityGroup": { | |
"Type": "AWS::EC2::SecurityGroup", | |
"Properties": { | |
"GroupDescription": "Enable Access to Jetty application via port 8080 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 jetty application", | |
"Value": { | |
"Fn::Join": [ | |
"", | |
[ | |
"http://", | |
{ | |
"Fn::GetAtt": [ | |
"Ec2Instance", | |
"PublicDnsName" | |
] | |
}, | |
":8080" | |
] | |
] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment