-
Notifications
You must be signed in to change notification settings - Fork 0
/
fargate_from_scratch.yml
148 lines (139 loc) · 4.48 KB
/
fargate_from_scratch.yml
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
AWSTemplateFormatVersion: '2010-09-09'
Description: Docker Core App service
Parameters:
ServiceName:
Type: String
Default: coreapi
Description: A name for the service
ImageUrl:
Type: String
Default: "500986409600.dkr.ecr.us-east-1.amazonaws.com/dotnet-my-api-new:latest"
Description: The url of a docker image that contains the application process that
will handle the traffic for this service
ContainerPort:
Type: Number
Default: 80
Description: What port number the application inside the docker container is binding to
TaskMemory:
Type: Number
Default: 512
Description: How much memory in megabytes to give the container
TaskCpu:
Type: Number
Default: 256
Description: How much cpu in megabytes to give the container
ContainerMemory:
Type: Number
Default: 128
Description: How much memory in megabytes to give the Task
ContainerCpu:
Type: Number
Default: 125
Description: How much CPU to give the container.
DesiredCount:
Type: Number
Default: 2
Description: How many copies of the service task to run
VpcId:
Type: String
Default: vpc-55229a2e
Description: vpcid
ListenerArn:
Type: String
Default: arn:aws:elasticloadbalancing:us-east-1:500986409600:listener/app/alb/df6eb1585a92add3/6108294b441007b6
Description: listener arn of the ALB
Path:
Type: String
Default: "/v0/*"
Description: A path on the public load balancer that this service should be connected to.
Resources:
# A log group for storing the container logs for this service
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Ref 'ServiceName'
# The task definition. This is a simple metadata description of what
# container to run, and what resource requirements it has.
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Ref 'ServiceName'
Cpu: !Ref 'TaskCpu'
Memory: !Ref 'TaskMemory'
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: arn:aws:iam::500986409600:role/ecsTaskExecutionRole
TaskRoleArn: arn:aws:iam::500986409600:role/ecsTaskExecutionRole
ContainerDefinitions:
- Name: !Ref 'ServiceName'
Cpu: !Ref 'ContainerCpu'
Memory: !Ref 'ContainerMemory'
Image: !Ref 'ImageUrl'
PortMappings:
- ContainerPort: !Ref 'ContainerPort'
LogConfiguration:
LogDriver: 'awslogs'
Options:
awslogs-group: !Ref 'LogGroup'
awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: !Ref 'ServiceName'
Service:
Type: AWS::ECS::Service
DependsOn: LoadBalancerRule
Properties:
ServiceName: !Ref 'ServiceName'
Cluster: coreapp
LaunchType: FARGATE
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 50
DesiredCount: !Ref 'DesiredCount'
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: DISABLED
SecurityGroups:
- sg-483aa03e
Subnets:
- subnet-1be61a51
- subnet-22fbf146
TaskDefinition: !Ref 'TaskDefinition'
LoadBalancers:
- ContainerName: !Ref 'ServiceName'
ContainerPort: !Ref 'ContainerPort'
TargetGroupArn: !Ref 'TargetGroup'
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 6
HealthCheckPath: /v0/api/mama
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 2
TargetType: ip
Name: !Ref 'ServiceName'
Port: !Ref 'ContainerPort'
Protocol: HTTP
UnhealthyThresholdCount: 2
TargetGroupAttributes:
- Key: stickiness.enabled
Value: true
- Key: deregistration_delay.timeout_seconds
Value: 30
VpcId: !Ref 'VpcId'
# Fn::ImportValue:
# !Join [':', [!Ref 'EnvironmentName', 'VPCId']]
# Create a rule on the load balancer for routing traffic to the target group
LoadBalancerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Actions:
- TargetGroupArn: !Ref 'TargetGroup'
Type: 'forward'
Conditions:
- Field: path-pattern
Values: [!Ref 'Path']
ListenerArn: !Ref 'ListenerArn'
# Fn::ImportValue:
# !Join [':', [!Ref 'EnvironmentName', 'PublicListener']]
Priority: 0