-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcfn-template.json
186 lines (183 loc) · 5.05 KB
/
cfn-template.json
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Description of what this template contains. i.e. which service it runs",
"Parameters" : {
"MYCONTAINERVAR1" : {
"Description" : "Application Environment Variable 1",
"Type" : "String",
"Default" : ""
},
"MYCONTAINERVAR2" : {
"Description" : "Application Environment Variable 2",
"Type": "String",
"Default": ""
},
"MYCONTAINERVAR3" : {
"Description" : "Application Environment Variable 3",
"Type" : "String",
"Default" : ""
},
"HOSTPORT" : {
"Description" : "Host port",
"Type" : "String",
"Default" : ""
},
"CLUSTERNAME" : {
"Description" : "The name of the cluster to use",
"Type" : "String",
"Default" : ""
},
"IMAGENAME" : {
"Description" : "The name of the dockerhub image. i.e. example/service:tag",
"Type" : "String",
"Default" : ""
},
"CONTAINERNAME" : {
"Description" : "The name of the docker container",
"Type" : "String",
"Default" : ""
},
"DNSPREFIX" : {
"Description" : "(Optional) [DNS Record] Prefix for the ELB DNS Record",
"Type" : "String",
"Default" : ""
},
"DNSZONE" : {
"Description" : "(Optional) [DNS Record] Route53-hosted zone to use for the ELB's DNS record (<prefix>.<zone>)",
"Type" : "String",
"Default" : ""
},
"TASKDESIREDCOUNT" : {
"Description" : "[Task] Desired number of running tasks",
"Type" : "String",
"Default" : ""
},
"LOADBALANCERSUBNETS" : {
"Description" : "(Required) [Load Balancer] List of subnets",
"Type" : "List<AWS::EC2::Subnet::Id>"
},
"SERVICEROLE" : {
"Description" : "[Service] Name of the role",
"Type" : "String"
},
"LOADBALANCERSECURITYGROUP" : {
"Description" : "(Required) [Load Balancer] The security group of the load balancer",
"Type" : "AWS::EC2::SecurityGroup::Id"
},
"CONTAINERPORT" : {
"Description" : "[Service] The port on the container",
"Type" : "String",
"Default" : ""
},
"LBSSLCERT" : {
"Description" : "[Load Balancer] SSL Certificate ARN",
"Type" : "String"
},
"REQUIREDCPU" : {
"Description" : "[TaskDef] The required CPU usage based on a 1-1024 scale",
"Type" : "String",
"Default" : "10"
},
"REQUIREDMEMORY" : {
"Description" : "[TaskDef] The requried memory needed in MB",
"Type" : "String",
"Default" : "100"
}
},
"Conditions" : {
"CreateDnsEntry" : { "Fn::And" : [
{ "Fn::Not" : [{ "Fn::Equals" : [{ "Ref" : "DNSPREFIX" }, ""]}]},
{ "Fn::Not" : [{ "Fn::Equals" : [{ "Ref" : "DNSZONE" }, ""]}]}
]}
},
"Resources" : {
"TaskName" : {
"Type" : "AWS::ECS::TaskDefinition",
"Properties" : {
"ContainerDefinitions" : [
{
"Cpu" : { "Ref" : "REQUIREDCPU" },
"Environment" : [{
"Name": "VAR1",
"Value" : { "Ref" : "MYCONTAINERVAR1" }
},{
"Name" : "VAR2",
"Value" : { "Ref" : "MYCONTAINERVAR2" }
},{
"Name" : "VAR3",
"Value" : { "Ref" : "MYCONTAINERVAR3" }
}
],
"Essential" : true,
"Image" : { "Ref" : "IMAGENAME" },
"Memory" : { "Ref" : "REQUIREDMEMORY" },
"Name" : { "Ref" : "CONTAINERNAME" },
"PortMappings" : [
{
"ContainerPort" : { "Ref" : "CONTAINERPORT" },
"HostPort" : {"Ref" : "HOSTPORT"}
}
]
}
],
"Volumes" : []
}
},
"ServiceName" : {
"Type" : "AWS::ECS::Service",
"Properties" : {
"Cluster" : { "Ref" : "CLUSTERNAME" },
"DesiredCount" : { "Ref" : "TASKDESIREDCOUNT" },
"TaskDefinition" : { "Ref" : "TaskName" },
"LoadBalancers" : [{
"LoadBalancerName" : { "Ref" : "ServiceLoadBalancer" },
"ContainerPort" : { "Ref" : "CONTAINERPORT" },
"ContainerName" : { "Ref" : "CONTAINERNAME" }
}],
"Role" : { "Ref" : "SERVICEROLE" }
}
},
"ServiceLoadBalancer" : {
"Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
"Properties" : {
"Subnets" : { "Ref" : "LOADBALANCERSUBNETS" },
"HealthCheck" : {
"Target" : { "Fn::Join" : [ "", [ "HTTP:", { "Ref" : "HOSTPORT" }, "/healthcheck" ]]},
"HealthyThreshold" : "3",
"UnhealthyThreshold" : "5",
"Interval" : "30",
"Timeout" : "10"
},
"SecurityGroups" : [
{ "Ref" : "LOADBALANCERSECURITYGROUP" }
],
"Listeners" : [
{
"InstancePort" : { "Ref" : "HOSTPORT" },
"LoadBalancerPort" : "443",
"Protocol" : "HTTPS",
"SSLCertificateId" : { "Ref" : "LBSSLCERT" }
}]
}
},
"DNSRecord" : {
"Condition" : "CreateDnsEntry",
"Type" : "AWS::Route53::RecordSet",
"Properties" : {
"AliasTarget" : {
"HostedZoneId" : { "Fn::GetAtt" : [ "ServiceLoadBalancer", "CanonicalHostedZoneNameID" ] },
"DNSName" : { "Fn::GetAtt" : [ "ServiceLoadBalancer", "CanonicalHostedZoneName" ] }
},
"HostedZoneName" : { "Fn::Join" : [ "", [ { "Ref" : "DNSZONE" }, "."]] },
"Name" : { "Fn::Join" : [ "", [ {"Ref" : "DNSPREFIX" }, ".", { "Ref" : "DNSZONE" }, "." ]]},
"Type" : "A"
}
}
},
"Outputs" : {
"ServiceARN" : {
"Description" : "The name of the created Service",
"Value" : { "Ref" : "ServiceName"}
}
}
}