Skip to content

Commit ca6aa09

Browse files
committed
2 parents 60b7bff + ea8bdad commit ca6aa09

File tree

3 files changed

+703
-1
lines changed

3 files changed

+703
-1
lines changed

software/infrastructure/base.template

Lines changed: 398 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,398 @@
1+
{
2+
"AWSTemplateFormatVersion": "2010-09-09",
3+
"Description": "Template to launch an Amazon Linux instance and install/configure AWS command line tools.",
4+
"Mappings": {
5+
"AWSInstanceType2Arch": {
6+
"c1.medium": {
7+
"Arch": "64"
8+
},
9+
"c1.xlarge": {
10+
"Arch": "64"
11+
},
12+
"cc1.4xlarge": {
13+
"Arch": "64"
14+
},
15+
"m1.large": {
16+
"Arch": "64"
17+
},
18+
"m1.medium": {
19+
"Arch": "64"
20+
},
21+
"m1.small": {
22+
"Arch": "64"
23+
},
24+
"m1.xlarge": {
25+
"Arch": "64"
26+
},
27+
"m2.2xlarge": {
28+
"Arch": "64"
29+
},
30+
"m2.4xlarge": {
31+
"Arch": "64"
32+
},
33+
"m2.xlarge": {
34+
"Arch": "64"
35+
},
36+
"t1.micro": {
37+
"Arch": "64"
38+
}
39+
},
40+
"AWSRegionArch2AMI": {
41+
"ap-northeast-1": {
42+
"32": "ami-087acb09",
43+
"64": "ami-e47acbe5"
44+
},
45+
"ap-southeast-1": {
46+
"32": "ami-b83374ea",
47+
"64": "ami-be3374ec"
48+
},
49+
"eu-west-1": {
50+
"32": "ami-fd231b89",
51+
"64": "ami-f9231b8d"
52+
},
53+
"sa-east-1": {
54+
"32": "ami-aa855bb7",
55+
"64": "ami-a6855bbb"
56+
},
57+
"us-east-1": {
58+
"32": "ami-ed65ba84",
59+
"64": "ami-e565ba8c"
60+
},
61+
"us-west-1": {
62+
"32": "ami-978cd4d2",
63+
"64": "ami-e78cd4a2"
64+
},
65+
"us-west-2": {
66+
"32": "ami-38c64a08",
67+
"64": "ami-3ac64a0a"
68+
}
69+
}
70+
},
71+
"Outputs": {
72+
"Instance": {
73+
"Description": "DNS Name of the newly created EC2 instance",
74+
"Value": {
75+
"Fn::GetAtt": [
76+
"Ec2Instance",
77+
"PublicDnsName"
78+
]
79+
}
80+
}
81+
},
82+
"Parameters": {
83+
"InstanceName": {
84+
"Default": "Command Line Tools",
85+
"Description": "The name to tag this instance with.",
86+
"Type": "String"
87+
},
88+
"InstanceType": {
89+
"Default": "m1.medium",
90+
"Description": "EC2 instance type, e.g. t1.micro, m1.small, m1.medium, m1.large, etc.",
91+
"Type": "String"
92+
},
93+
"KeyName": {
94+
"Description": "Name of an existing EC2 KeyPair to enable SSH access to the web server",
95+
"Type": "String"
96+
}
97+
},
98+
"Resources": {
99+
"AdminUser": {
100+
"Properties": {
101+
"Path": "/",
102+
"Policies": [
103+
{
104+
"PolicyDocument": {
105+
"Statement": [
106+
{
107+
"Action": "*",
108+
"Effect": "Allow",
109+
"Resource": "*"
110+
}
111+
]
112+
},
113+
"PolicyName": "root"
114+
}
115+
]
116+
},
117+
"Type": "AWS::IAM::User"
118+
},
119+
"Ec2Instance": {
120+
"Metadata": {
121+
"AWS::CloudFormation::Init": {
122+
"config": {
123+
"files": {
124+
"/home/ec2-user/.aws-credentials": {
125+
"content": {
126+
"Fn::Join": [
127+
"",
128+
[
129+
"AWSAccessKeyId=",
130+
{
131+
"Ref": "HostKeys"
132+
},
133+
"\n",
134+
"AWSSecretKey=",
135+
{
136+
"Fn::GetAtt": [
137+
"HostKeys",
138+
"SecretAccessKey"
139+
]
140+
},
141+
"\n"
142+
]
143+
]
144+
},
145+
"group": "ec2-user",
146+
"mode": "000600",
147+
"owner": "ec2-user"
148+
},
149+
"/home/ec2-user/.s3cfg": {
150+
"content": {
151+
"Fn::Join": [
152+
"",
153+
[
154+
"[default]",
155+
"\n",
156+
"access_key = ",
157+
{
158+
"Ref": "HostKeys"
159+
},
160+
"\n",
161+
"secret_key = ",
162+
{
163+
"Fn::GetAtt": [
164+
"HostKeys",
165+
"SecretAccessKey"
166+
]
167+
},
168+
"\n"
169+
]
170+
]
171+
},
172+
"group": "ec2-user",
173+
"mode": "000600",
174+
"owner": "ec2-user"
175+
},
176+
"/home/ec2-user/credentials.json": {
177+
"content": {
178+
"Fn::Join": [
179+
"",
180+
[
181+
"{",
182+
"\n",
183+
"\"access-id\":\"",
184+
{
185+
"Ref": "HostKeys"
186+
},
187+
"\",",
188+
"\n",
189+
"\"private-key\":\"",
190+
{
191+
"Fn::GetAtt": [
192+
"HostKeys",
193+
"SecretAccessKey"
194+
]
195+
},
196+
"\",",
197+
"\n",
198+
"\"key-pair\":\"",
199+
{
200+
"Ref": "KeyName"
201+
},
202+
"\",",
203+
"\n",
204+
"\"key-pair-file\":\"",
205+
{ "Fn::Join": [ "", [ "~/", { "Ref": "KeyName" }, ".pem" ] ] },
206+
"\",",
207+
"\n",
208+
"\"region\":\"",
209+
{
210+
"Ref": "AWS::Region"
211+
},
212+
"\",",
213+
"\n",
214+
"}",
215+
"\n"
216+
]
217+
]
218+
},
219+
"group": "ec2-user",
220+
"mode": "000600",
221+
"owner": "ec2-user"
222+
},
223+
"/home/ec2-user/config.yml": {
224+
"content": {
225+
"Fn::Join": [
226+
"",
227+
[
228+
"access_key_id: ",
229+
{
230+
"Ref": "HostKeys"
231+
},
232+
"\n",
233+
"secret_access_key: ",
234+
{
235+
"Fn::GetAtt": [
236+
"HostKeys",
237+
"SecretAccessKey"
238+
]
239+
},
240+
"\n"
241+
]
242+
]
243+
},
244+
"group": "ec2-user",
245+
"mode": "000600",
246+
"owner": "ec2-user"
247+
}
248+
},
249+
"sources" : {
250+
"/usr/local/bin/s3cmd" : "http://github.com/s3tools/s3cmd/zipball/v1.1.0-beta3",
251+
"/usr/local/bin" : "http://ftp.wayne.edu/apache//maven/binaries/apache-maven-3.0.4-bin.tar.gz",
252+
"/usr/local/bin/elastic-map-reduce-ruby" : "http://elasticmapreduce.s3.amazonaws.com/elastic-mapreduce-ruby.zip"
253+
},
254+
"packages": {
255+
"rubygems" : {
256+
"rake" : [],
257+
"dnsruby" : [],
258+
"mechanize" : [],
259+
"chef" : [],
260+
"aws-sdk" : [],
261+
"systemu" : []
262+
},
263+
"yum": {
264+
"aws-apitools-cfn.noarch": [],
265+
"python-boto.noarch": [],
266+
"git": [],
267+
"java-1.6.0-openjdk-devel": [],
268+
"gcc-c++" : [],
269+
"ruby-devel" : [],
270+
"make" : [],
271+
"autoconf" : [],
272+
"automake" : [],
273+
"rubygems" : [],
274+
"libxslt-devel": [],
275+
"libxml2-devel": []
276+
}
277+
}
278+
}
279+
}
280+
},
281+
"Properties": {
282+
"ImageId": {
283+
"Fn::FindInMap": [
284+
"AWSRegionArch2AMI",
285+
{
286+
"Ref": "AWS::Region"
287+
},
288+
{
289+
"Fn::FindInMap": [
290+
"AWSInstanceType2Arch",
291+
{
292+
"Ref": "InstanceType"
293+
},
294+
"Arch"
295+
]
296+
}
297+
]
298+
},
299+
"InstanceType": {
300+
"Ref": "InstanceType"
301+
},
302+
"KeyName": {
303+
"Ref": "KeyName"
304+
},
305+
"SecurityGroups": [
306+
{
307+
"Ref": "Ec2SecurityGroup"
308+
}
309+
],
310+
"Tags" : [
311+
{
312+
"Key" : "Name",
313+
"Value" : { "Ref": "InstanceName" }
314+
}
315+
],
316+
"UserData": {
317+
"Fn::Base64": {
318+
"Fn::Join": [
319+
"",
320+
[
321+
"#!/bin/bash\n",
322+
"yum update -y\n",
323+
324+
"# Helper function\n",
325+
"function error_exit \n",
326+
"{\n",
327+
" /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref": "WaitHandle" }, "'\n",
328+
" exit 1\n",
329+
"}\n",
330+
331+
"# Install packages and write files in AWS::CloudFormation::Init\n",
332+
"/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" }, " -r Ec2Instance ",
333+
" --access-key ", { "Ref" : "HostKeys" },
334+
" --secret-key ", {"Fn::GetAtt": ["HostKeys", "SecretAccessKey"]},
335+
" --region ", { "Ref" : "AWS::Region" }, " || error_exit 'Failed to run cfn-init'\n",
336+
337+
"echo 'export AWS_ACCESS_KEY=", { "Ref" : "HostKeys" }, "' >> /home/ec2-user/.bash_profile\n",
338+
"echo 'export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY' >> /home/ec2-user/.bash_profile\n",
339+
"echo 'export AWS_SECRET_ACCESS_KEY=", {"Fn::GetAtt": ["HostKeys", "SecretAccessKey"]}, "' >> /home/ec2-user/.bash_profile\n",
340+
341+
"echo 'export AWS_CLOUDFORMATION_HOME=/opt/aws/apitools/cfn' >> /home/ec2-user/.bash_profile\n",
342+
"echo 'export PATH=$AWS_CLOUDFORMATION_HOME/bin:$PATH' >> /home/ec2-user/.bash_profile\n",
343+
"echo 'export PATH=/opt/aws/bin:$PATH' >> /home/ec2-user/.bash_profile\n",
344+
"echo 'export AWS_CREDENTIALS_FILE=/home/ec2-user/.aws-credentials' >> /home/ec2-user/.bash_profile\n",
345+
"echo 'export AWS_CREDENTIAL_FILE=$AWS_CREDENTIALS_FILE' >> /home/ec2-user/.bash_profile\n",
346+
"echo 'export PATH=/usr/local/bin/apache-maven-3.0.4/bin:$PATH' >> /home/ec2-user/.bash_profile\n",
347+
"echo 'export PATH=/usr/local/bin/elastic-map-reduce-ruby:$PATH' >> /home/ec2-user/.bash_profile\n",
348+
"echo 'export JAVA_HOME=/etc/alternatives/java_sdk' >> /home/ec2-user/.bash_profile\n",
349+
350+
"chmod +x /usr/local/bin/elastic-map-reduce-ruby/elastic-mapreduce\n",
351+
352+
"# Install s3cmd\n",
353+
"cd /usr/local/bin/s3cmd\n",
354+
"python setup.py install\n",
355+
356+
"# All is well so signal success\n",
357+
"/opt/aws/bin/cfn-signal -e 0 -r \"cfn-int setup complete\" '", { "Ref" : "WaitHandle" }, "'\n"
358+
]
359+
]
360+
}
361+
}
362+
},
363+
"Type": "AWS::EC2::Instance"
364+
},
365+
"Ec2SecurityGroup": {
366+
"Properties": {
367+
"GroupDescription": "HTTP and SSH access",
368+
"SecurityGroupIngress": [
369+
{
370+
"CidrIp": "0.0.0.0/0",
371+
"FromPort": "22",
372+
"IpProtocol": "tcp",
373+
"ToPort": "22"
374+
}
375+
]
376+
},
377+
"Type": "AWS::EC2::SecurityGroup"
378+
},
379+
"HostKeys": {
380+
"Properties": {
381+
"UserName": {
382+
"Ref": "AdminUser"
383+
}
384+
},
385+
"Type": "AWS::IAM::AccessKey"
386+
},
387+
"WaitCondition" : {
388+
"Type" : "AWS::CloudFormation::WaitCondition",
389+
"Properties" : {
390+
"Handle" : { "Ref" : "WaitHandle" },
391+
"Timeout" : "600"
392+
}
393+
},
394+
"WaitHandle": {
395+
"Type": "AWS::CloudFormation::WaitConditionHandle"
396+
}
397+
}
398+
}

0 commit comments

Comments
 (0)