-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathEC2Test.template
83 lines (81 loc) · 2.53 KB
/
EC2Test.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "",
"Parameters" : {
"KeyName": {
"Type": "AWS::EC2::KeyPair::KeyName",
"Description": "Name of an existing EC2 KeyPair to enable SSH access to the ECS instances"
},
"VpcId": {
"Type": "AWS::EC2::VPC::Id",
"Description": "VPC in which to create stack"
},
"SubnetId": {
"Type": "AWS::EC2::Subnet::Id",
"Description": "Subnet in which to create container instances"
},
"UserDataUrl": {
"Type": "String",
"Description": "Url to a user-data script"
}
},
"Resources" : {
"Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : "ami-b73b63a0",
"KeyName" : { "Ref" : "KeyName" },
"InstanceType": "t2.micro",
"Tags" : [ {"Key" : "Name", "Value" : "EC2-UserData-Test"}],
"SecurityGroupIds" : [{ "Ref" : "InstanceSecurityGroup" }],
"SubnetId": {"Ref": "SubnetId"},
"UserData" : {"Fn::Base64": {
"Fn::Join": [
"",
[
"Content-Type: multipart/mixed; boundary=\"==BOUNDARY==\"\n",
"MIME-Version: 1.0\n",
"\n",
"--==BOUNDARY==\n",
"MIME-Version: 1.0\n",
"Content-Type: text/x-shellscript; charset=\"us-ascii\"\n",
"#!/bin/bash\n",
"echo \"Part1\" >> /var/log/order.log\n",
"echo \"Executing: Part1\"\n",
"--==BOUNDARY==\n",
"MIME-Version: 1.0\n",
"Content-Type: text/x-shellscript; charset=\"us-ascii\"\n",
"#!/bin/bash\n",
"echo \"Part2\" >> /var/log/order.log\n",
"echo \"Executing: Part2\"\n",
"--==BOUNDARY==\n",
"MIME-Version: 1.0\n",
"Content-Type: text/x-include-url; charset=\"us-ascii\"\n",
"\n",
{"Fn::Sub": "${UserDataUrl}\n"},
"--==BOUNDARY==\n",
]]}
}
}
},
"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Allow http to client host",
"VpcId" : {"Ref" : "VpcId"},
"SecurityGroupIngress" : [{
"IpProtocol" : "tcp",
"FromPort" : "22",
"ToPort" : "22",
"CidrIp" : "0.0.0.0/0"
}]
}
}
},
"Outputs": {
"EC2IP": {
"Description": "Private IP of instance",
"Value": {"Fn::GetAtt": ["Ec2Instance", "PrivateIp"]}
}
}
}