-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathservice.yaml
136 lines (119 loc) · 4.41 KB
/
service.yaml
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
Description: >
This is an example of a long-running ECS service that serves a JSON API of products.
Parameters:
Cluster:
Description: Please provide the ECS Cluster ID that this service should run on
Type: String
DesiredCount:
Default: 2
Description: How many instances of this task should we run across our cluster?
Type: Number
ECSTaskExecutionRole:
Description: The ECS Task Execution Role
Type: String
Listener:
Description: The Application Load Balancer listener to register with
Type: String
Path:
Default: /products
Description: The path to register with the Application Load Balancer
Type: String
SecurityGroup:
Description: Select the Security Group to use for the ECS cluster hosts
Type: AWS::EC2::SecurityGroup::Id
Subnets:
Description: Choose which subnets this ECS cluster should be deployed to
Type: List<AWS::EC2::Subnet::Id>
# Use !Select to choose 0 and 1 from subnet array, e.g. !Select [ 0, !Ref Subnets ]
TaskCpu:
Default: 512
Description: How much CPU to give the ECS task, in CPU units (where 1,024 units is 1 CPU) or vCPUs
Type: Number
TaskMemory:
Default: 1024
Description: How much memory to give the ECS task in megabytes
Type: Number
VPC:
Description: The VPC that the ECS cluster is deployed to
Type: AWS::EC2::VPC::Id
Resources:
Service:
Type: AWS::ECS::Service
DependsOn: ListenerRule
Properties:
Cluster: !Ref Cluster
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 100
DesiredCount: !Ref DesiredCount
LaunchType: FARGATE
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
SecurityGroups:
- !Ref SecurityGroup
Subnets:
- !Select [ 0, !Ref Subnets ]
- !Select [ 1, !Ref Subnets ]
TaskDefinition: !Ref TaskDefinition
LoadBalancers:
- ContainerName: "product-service"
ContainerPort: 8001
TargetGroupArn: !Ref TargetGroup
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: product-service
Cpu: !Ref 'TaskCpu'
Memory: !Ref 'TaskMemory'
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: !Ref ECSTaskExecutionRole
ContainerDefinitions:
- Name: product-service
Essential: true
Image: 275396840892.dkr.ecr.us-east-1.amazonaws.com/ecs-refarch-cloudformation/product-service:1.0.0
# CPU and Memory reservations are set to 50% of the default values specified above
Cpu: 256
Memory: 1024
MemoryReservation: 512
PortMappings:
- ContainerPort: 8001
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref AWS::StackName
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: !Ref AWS::StackName
CloudWatchLogsGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Ref AWS::StackName
RetentionInDays: 365
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
VpcId: !Ref VPC
Port: 80
Protocol: HTTP
TargetType: ip
Matcher:
HttpCode: 200-299
HealthCheckIntervalSeconds: 10
HealthCheckPath: /products
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 2
ListenerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
ListenerArn: !Ref Listener
Priority: 2
Conditions:
- Field: path-pattern
Values:
- !Ref Path
Actions:
- TargetGroupArn: !Ref TargetGroup
Type: forward