-
Notifications
You must be signed in to change notification settings - Fork 227
/
fargate-service.json
149 lines (147 loc) · 5.13 KB
/
fargate-service.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
{
"Description": "Container Fargate Service (fdp-1p5s1037g)",
"Metadata" : {
"Source":"https://github.com/awslabs/aws-cloudformation-templates/blob/master/aws/services/ECS/FargateLaunchType/services/private-subnet-public-service.yml"
},
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"ECRImageURI": {
"Type": "String",
"Description" : "URI for the container from Amazon Elastic Container Registry."
},
"TaskDefinitionName": {
"Type": "String",
"Description" : "This will set the Container, Task Definition, and Service name in Fargate."
},
"ContainerPort": {
"Type":"Number",
"Description" : "port number exposed from the container image.",
"Default":80
},
"ContainerSize": {
"Type":"String",
"Description" : "Size of container for Fargate task.",
"Default":"Small",
"AllowedValues": ["Small","Medium","Large"]
}
},
"Mappings" : {
"MapContainerSize" : {
"Small" : {
"cpu" : "512" ,
"mem" : "1024"
},
"Medium" : {
"cpu" : "1024",
"mem" : "2048"
},
"Large" : {
"cpu" : "4096",
"mem" : "8192"
}
}
},
"Resources": {
"TaskLogGroup": {
"Type" : "AWS::Logs::LogGroup",
"Properties" : {
"LogGroupName" : {"Fn::Sub":"/ecs/${TaskDefinitionName}"},
"RetentionInDays" : 30
}
},
"taskdefinition": {
"Type": "AWS::ECS::TaskDefinition",
"Properties" : {
"ExecutionRoleArn": {"Fn::ImportValue": "ECSTaskExecutionRole"},
"RequiresCompatibilities": [
"FARGATE"
],
"Memory": { "Fn::FindInMap" : [ "MapContainerSize", { "Ref" : "ContainerSize" }, "mem"]},
"Family": {"Ref":"TaskDefinitionName"},
"NetworkMode": "awsvpc",
"Cpu": { "Fn::FindInMap" : [ "MapContainerSize", { "Ref" : "ContainerSize" }, "cpu"]},
"ContainerDefinitions" : [
{
"PortMappings": [
{ "ContainerPort": {"Ref": "ContainerPort"} }
],
"LogConfiguration": {
"LogDriver": "awslogs",
"Options": {
"awslogs-group": {"Ref":"TaskLogGroup"},
"awslogs-region": {"Ref":"AWS::Region"},
"awslogs-stream-prefix": "ecs"
}
},
"Environment": [
{
"Name": "AWS_REGION",
"Value": {"Ref":"AWS::Region"}
}
],
"Image": {"Ref":"ECRImageURI"},
"Name": {"Ref":"TaskDefinitionName"}
}
]
}
},
"ecsservice" : {
"Type" : "AWS::ECS::Service",
"DependsOn": ["PublicLoadBalancerListener"],
"Properties" : {
"TaskDefinition" : { "Ref" : "taskdefinition" },
"DesiredCount" : "1",
"LoadBalancers" : [{
"TargetGroupArn" : { "Ref" : "TargetGroup" },
"ContainerPort" : { "Ref" : "ContainerPort" },
"ContainerName" : {"Ref":"TaskDefinitionName"}
}],
"Cluster" : { "Fn::ImportValue" : "FargateClusterName" },
"LaunchType": "FARGATE",
"ServiceName": {"Ref":"TaskDefinitionName"},
"NetworkConfiguration":{
"AwsvpcConfiguration" : {
"AssignPublicIp": "DISABLED",
"SecurityGroups":[
{"Fn::ImportValue": "ECSFargateContainerSecurityGroup" }
],
"Subnets": [
{ "Fn::ImportValue": "ECSPrivateSubnetOne"},
{ "Fn::ImportValue": "ECSPrivateSubnetTwo"}
]
}}
}
},
"TargetGroup" : {
"Type" : "AWS::ElasticLoadBalancingV2::TargetGroup",
"Properties" : {
"HealthCheckIntervalSeconds" : 30,
"HealthCheckPath" : "/",
"HealthCheckProtocol" : "HTTP",
"HealthCheckTimeoutSeconds" : 5,
"HealthyThresholdCount" : 2,
"TargetType" : "ip",
"Name" : { "Ref": "TaskDefinitionName" },
"Port" : { "Ref": "ContainerPort"},
"Protocol" : "HTTP",
"UnhealthyThresholdCount" : 2,
"VpcId" : { "Fn::ImportValue" : "FargateClusterVPCId" }
}
},
"PublicLoadBalancerListener" : {
"Type" : "AWS::ElasticLoadBalancingV2::Listener",
"Properties" : {
"DefaultActions" : [
{ "TargetGroupArn" : {"Ref":"TargetGroup"} ,
"Type" : "forward" }
],
"LoadBalancerArn" : { "Fn::ImportValue" :"ECSPublicLoadBalancer"},
"Port" : {"Ref": "ContainerPort"},
"Protocol" : "HTTP"
}
}
},
"Outputs": {
"FargateService":{"Value": { "Ref":"ecsservice" } }
}
}