-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
254 lines (241 loc) · 7.22 KB
/
template.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: valorant-match-schedule
Parameters:
ApplicationName:
Description: resource prefix
Type: String
Default: valorant-match-schedule
APIEndpointDomainName:
Description: Domain name of API endpoint URL of dima (matches API)
Type: String
AllowedPattern: ^([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]*\.)+[a-zA-Z]{2,}$
ConstraintDescription: should be appropriate domain format
GoogleServiceAccountId:
Type: String
CalendarIdAmericas:
Type: String
CalendarIdChina:
Type: String
CalendarIdEmea:
Type: String
CalendarIdPacific:
Type: String
CalendarIdInternational:
Type: String
CalendarIdApac:
Type: String
CalendarIdBrLatam:
Type: String
CalendarIdEastAsia:
Type: String
CalendarIdNa:
Type: String
ScheduleExpression:
Description: schedule expression for the eventbridge event
Type: String
Default: rate(3 hours)
DaysToGet:
Description: days to get match info starting from today
Type: Number
Default: 30
DaysToRetainLogs:
Description: days to retain logs in CloudWatch
Type: Number
Default: 30
Resources:
GoogleAuthLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: !Sub ${ApplicationName}-google-auth
ContentUri: layer/google-auth/
CompatibleRuntimes:
- python3.12
CompatibleArchitectures:
- x86_64
Metadata:
BuildMethod: python3.12
BuildArchitecture: x86_64
GoogleApiPythonClientLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: !Sub ${ApplicationName}-google-api-python-client
ContentUri: layer/google-api-python-client/
CompatibleRuntimes:
- python3.12
CompatibleArchitectures:
- x86_64
Metadata:
BuildMethod: python3.12
BuildArchitecture: x86_64
RequestsLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: !Sub ${ApplicationName}-requests
ContentUri: layer/requests/
CompatibleRuntimes:
- python3.12
CompatibleArchitectures:
- x86_64
Metadata:
BuildMethod: python3.12
BuildArchitecture: x86_64
AddGcalEventFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${ApplicationName}-add-gcal-event
CodeUri: function/add-gcal-event/
Description: "add valorant match to google calendar as a event"
Handler: index.lambda_handler
Runtime: python3.12
Architectures:
- x86_64
MemorySize: 128
Timeout: 30
Policies:
- AWSLambdaDynamoDBExecutionRole
- AmazonDynamoDBFullAccess
Environment:
Variables:
OUTBOX_TABLE: !Ref OutboxTable
GOOGLE_SERVICE_ACCOUNT_ID: !Ref GoogleServiceAccountId
CALENDAR_ID_AMERICAS: !Ref CalendarIdAmericas
CALENDAR_ID_CHINA: !Ref CalendarIdChina
CALENDAR_ID_EMEA: !Ref CalendarIdEmea
CALENDAR_ID_PACIFIC: !Ref CalendarIdPacific
CALENDAR_ID_INTERNATIONAL: !Ref CalendarIdInternational
CALENDAR_ID_APAC: !Ref CalendarIdApac
CALENDAR_ID_BR_LATAM: !Ref CalendarIdBrLatam
CALENDAR_ID_EAST_ASIA: !Ref CalendarIdEastAsia
CALENDAR_ID_NA: !Ref CalendarIdNa
Layers:
- !Ref GoogleAuthLayer
- !Ref GoogleApiPythonClientLayer
Events:
Stream:
Type: DynamoDB
Properties:
Stream: !GetAtt MatchListTable.StreamArn
BatchSize: 1
BisectBatchOnFunctionError: true
Enabled: true
StartingPosition: TRIM_HORIZON
AddGCalFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${AddGcalEventFunction}
RetentionInDays: !Ref DaysToRetainLogs
GetMatchListFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${ApplicationName}-get-match-list
CodeUri: function/get-match-list/
Description: "invoke fetch-daily-matches function via SQS queue publishing"
Handler: index.lambda_handler
Runtime: python3.12
Architectures:
- x86_64
MemorySize: 128
Timeout: 180
Policies:
- AmazonSQSFullAccess
Environment:
Variables:
FETCH_DAILY_MATCHES_QUEUE_URL: !Ref FetchDailyMatchesQueue
BASE_DELAY_SECONDS: 30
DAYS_TO_GET: !Ref DaysToGet
Events:
CloudWatchEvent:
Type: Schedule
Properties:
Schedule: !Ref ScheduleExpression
GetMatchListFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${GetMatchListFunction}
RetentionInDays: !Ref DaysToRetainLogs
FetchDailyMatchesFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${ApplicationName}-fetch-daily-matches
CodeUri: function/fetch-daily-matches/
Description: "fetch daily valorant matches"
Handler: index.lambda_handler
Runtime: python3.12
Architectures:
- x86_64
MemorySize: 128
Timeout: 900
Policies:
- AmazonDynamoDBFullAccess
Environment:
Variables:
API_DOMAIN_NAME: !Ref APIEndpointDomainName
MATCHLIST_TABLE: !Ref MatchListTable
Layers:
- !Ref RequestsLayer
Events:
MySQSEvent:
Type: SQS
Properties:
Queue: !GetAtt FetchDailyMatchesQueue.Arn
BatchSize: 1
ScalingConfig:
MaximumConcurrency: 2
FetchDailyMatchesFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${FetchDailyMatchesFunction}
RetentionInDays: !Ref DaysToRetainLogs
FetchDailyMatchesQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: !Sub ${ApplicationName}-fetch-daily-matches-queue
DelaySeconds: 10
VisibilityTimeout: 1000
MatchListTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
TableName: !Sub ${ApplicationName}-fetched
AttributeDefinitions:
- AttributeName: match_id
AttributeType: N
BillingMode: PROVISIONED
DeletionProtectionEnabled: True
KeySchema:
- AttributeName: match_id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
TimeToLiveSpecification:
AttributeName: ttl
Enabled: true
OutboxTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
TableName: !Sub ${ApplicationName}-published
AttributeDefinitions:
- AttributeName: match_id
AttributeType: N
- AttributeName: calendar_id
AttributeType: S
BillingMode: PROVISIONED
DeletionProtectionEnabled: True
KeySchema:
- AttributeName: match_id
KeyType: HASH
- AttributeName: calendar_id
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TimeToLiveSpecification:
AttributeName: ttl
Enabled: true