This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
cloudformation-template-service.yaml
111 lines (100 loc) · 3.12 KB
/
cloudformation-template-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
Parameters:
ServiceImage:
Type: String
Description: The repository URI of the application image
Default: mmitrofan/whoami:latest
ApplicationName:
Type: String
Description: The application Name
Default: whoami
Environment:
Type: String
AllowedValues:
- dev
- staging
- prod
Default: dev
EcsCluster:
Type: String
Default: services-cluster
Description: The cluster in which to deploy this service
Domain:
Type: String
Description: Domain in which tasks should be registered to - MUST already exist as a zone in Route53
Default: example.com
TraefikStack:
Type: String
Description: The name of the CloudFormation stack which contains the traefik service
Default: traefik-srv
Resources:
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName:
Fn::Sub: ${AWS::StackName}-LogGroup
RetentionInDays: 14
TaskDef:
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Name: !Ref ApplicationName
Image: !Ref ServiceImage
PortMappings:
- ContainerPort: 80
Memory: 512
MemoryReservation: 256
DockerLabels:
traefik.frontend.rule: !Join
- .
- - !Join [ "-", [ !Sub "Host: ${ApplicationName}", !Select ["1", !Split [":", !Ref ServiceImage]] ] ]
- !Ref Environment
- !Ref Domain
traefik.enable: "true"
traefik.protocol: "http"
traefik.backend.loadbalancer.method: "wrr"
traefik.backend.loadbalancer.stickiness: "true"
traefik.backend.loadbalancer.stickiness.cookieName: !Join
- .
- - cookie
- !Join [ "-", [ !Sub "${ApplicationName}", !Select ["1", !Split [":", !Ref ServiceImage]] ] ]
- !Ref Environment
- !Ref Domain
traefik.backend.loadbalancer.stickiness.cookieName: "true"
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-region:
Ref: AWS::Region
awslogs-group: !Ref LogGroup
awslogs-stream-prefix:
Ref: AWS::StackName
Ulimits:
- HardLimit: 65536
SoftLimit: 10240
Name: nofile
Service:
Type: AWS::ECS::Service
Properties:
Cluster: !Ref EcsCluster
TaskDefinition: !Ref TaskDef
DesiredCount: 1
PlacementStrategies:
- Field: attribute:ecs.availability-zone
Type: spread
- Field: instanceId
Type: spread
DnsRecord:
Type: AWS::Route53::RecordSet
Properties:
Name: !Join
- .
- - !Join [ "-", [ !Sub "${ApplicationName}", !Select ["1", !Split [":", !Ref ServiceImage]] ] ]
- !Ref Environment
- !Ref Domain
HostedZoneName: !Sub "${Domain}."
Type: A
AliasTarget:
DNSName:
Fn::ImportValue: !Sub ${TraefikStack}-TraefikAlbDualstackName
HostedZoneId:
Fn::ImportValue: !Sub ${TraefikStack}-TraefikAlbHostedZone