-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
283 lines (265 loc) · 9.32 KB
/
serverless.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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# TODO cleanup by extracting vars to custom.locals.xy
service: youareawesomeapp
# app and org for use with dashboard.serverless.com
app: youareawesomeapp
org: prosingularity
# https://www.serverless.com/plugins/
plugins:
- serverless-plugin-typescript
- serverless-offline # must come after typescript
- serverless-s3-sync
- serverless-iam-roles-per-function
- serverless-plugin-aws-alerts
# only deploy with specific Serverless version
frameworkVersion: ^3.22.0
configValidationMode: error
useDotenv: true
provider:
name: aws
runtime: nodejs16.x
region: ${opt:region, "eu-central-1"}
stage: ${opt:stage, "prod"}
profile: serverless
functions:
reportInappropriate:
handler: src/report-inappropriate/index.handler
events:
- http:
path: "/reportinappropriate/"
method: post
request:
schemas:
application/json:
schema: ${file(src/report-inappropriate/schema.json)}
name: PostReportSchema
description: "Validation model to report inappropriate content"
environment:
SMTP_HOST: ${env:SMTP_HOST}
SMTP_USERNAME: ${env:SMTP_USERNAME}
SMTP_PASSWORD: ${env:SMTP_PASSWORD}
SMTP_PORT: ${env:SMTP_PORT}
USE_SSL: ${env:USE_SSL}
TO_EMAILS_CSV: ${env:TO_EMAILS_CSV}
FROM_ADDRESS: ${env:FROM_ADDRESS}
writeContributionToGsheet:
handler: src/contributions/index.writeContributionToGsheet
events:
- http:
path: contributions
method: post
request:
schemas:
application/json:
schema: ${file(src/contributions/contributions.schema.json)}
name: PostContributionSchema
description: "Validation model for Creating a Contribution"
environment:
CONTRIBUTIONS_SPREADSHEET_ID: ${env:CONTRIBUTIONS_SPREADSHEET_ID}
CONTRIBUTIONS_GOOGLE_EMAIL: ${env:CONTRIBUTIONS_GOOGLE_EMAIL}
CONTRIBUTIONS_GOOGLE_PRIVATE_KEY: ${env:CONTRIBUTIONS_GOOGLE_PRIVATE_KEY}
subscribePushNotif:
handler: src/push-notifications/subscribe.handler
events:
- http:
path: push-notifications/subscribe
method: put
request:
schemas:
application/json:
schema: ${file(src/push-notifications/subscribe.schema.json)}
name: PutPushNotifSubscriptionv2
description: "Validation model for Creating or Updating Push Notification Subscriptions"
environment:
SUBSCRIPTION_TABLE: ${self:resources.Resources.PushNotifSubsTable.Properties.TableName}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:PutItem
Resource:
- Fn::GetAtt: [PushNotifSubsTable, Arn]
unsubPushNotif:
handler: src/push-notifications/unsubscribe.handler
events:
- http:
path: push-notifications/unsubscribe
method: post
request:
schemas:
application/json:
schema: ${file(src/push-notifications/unsubscribe.schema.json)}
name: PostPushNotifUnsubscribe
description: "Validation model for Deleting Push Notification Subscriptions"
environment:
SUBSCRIPTION_TABLE: ${self:resources.Resources.PushNotifSubsTable.Properties.TableName}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DeleteItem
Resource:
- Fn::GetAtt: [PushNotifSubsTable, Arn]
sendPushNotif2:
handler: src/push-notifications/send.handler
events:
- schedule:
rate: rate(1 minute)
description: Trigger lambda to send push notifications for the event time
enabled: true
environment:
SUBSCRIPTION_TABLE: ${self:resources.Resources.PushNotifSubsTable.Properties.TableName}
TICKET_TABLE: ${self:resources.Resources.PushNotifTicketsTable.Properties.TableName}
AWESOME_MESSAGES_URI: "https://youareawesomeapp-current-message.s3.eu-central-1.amazonaws.com/messages.json"
SUBSCRIPTIONS_BY_TIME_INDEX: ${self:resources.Resources.PushNotifSubsTable.Properties.GlobalSecondaryIndexes.0.IndexName}
EXPO_PUSH_NOTIFICATIONS_API_TOKEN: ${env:EXPO_PUSH_NOTIFICATIONS_API_TOKEN}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:BatchWriteItem
Resource:
- Fn::GetAtt: [PushNotifTicketsTable, Arn]
- Effect: Allow
Action:
- dynamodb:Query
Resource:
- Fn::GetAtt: [PushNotifSubsTable, Arn]
- Fn::Join:
- "/"
- - Fn::GetAtt: [PushNotifSubsTable, Arn]
- index
- ${self:resources.Resources.PushNotifSubsTable.Properties.GlobalSecondaryIndexes.0.IndexName}
exchangeTicketsForReceipts:
handler: src/push-notifications/exchangeTicketsForReceipts.handler
description: Read expo push notification success-tickets from dynamodb, exchange tickets for receipts with expo, write back error receipts and delete exchanged success tickets.
events:
- schedule:
rate: rate(6 hours)
description: Invoke lambda exchangeTicketsForReceipts
enabled: true
environment:
TICKET_TABLE: ${self:resources.Resources.PushNotifTicketsTable.Properties.TableName}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:BatchWriteItem
Resource:
- Fn::GetAtt: [PushNotifTicketsTable, Arn]
# Dnr = device not registered. had to shorten for iam
handleDnrReceipts:
handler: src/push-notifications/handleDeviceNotRegisteredReceipts.handler
description: Read DeviceNotRegistered receipts from dynamodb and delete corresponding subscriptions. Finally delete handled receipts.
events:
- schedule:
rate: rate(1 day)
description: Invoke lambda handleDeviceNotRegisteredReceipts
enabled: true
environment:
SUBSCRIPTION_TABLE: ${self:resources.Resources.PushNotifSubsTable.Properties.TableName}
TICKET_TABLE: ${self:resources.Resources.PushNotifTicketsTable.Properties.TableName}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:BatchWriteItem
Resource:
- Fn::GetAtt: [PushNotifTicketsTable, Arn]
- Effect: Allow
Action:
- dynamodb:BatchWriteItem
Resource:
- Fn::GetAtt: [PushNotifSubsTable, Arn]
exportMessagesToS3:
handler: src/messages/export-to-s3.handler
environment:
MESSAGES_SPREADSHEET_PUBLIC_ID: "2PACX-1vR83yDqRha4RaBeqzPnX6xh1I9PqndL2E_p8Ks9AzUp7KFae5fxlgWxDcVN4f8G41x3BtKQwz5M_ujM"
BUCKET_NAME: ${self:service}-current-message
events:
- schedule:
rate: rate(1 day)
description: "Invoke export of Awesome Messages to S3 ${self:service}-current-messages"
iamRoleStatements:
- Effect: Allow
Action:
- s3:PutObject*
Resource:
- Fn::Join:
- ""
- - Fn::GetAtt: [CurrentMessageBucket, Arn]
- "/*"
# https://www.serverless.com/framework/docs/providers/aws/guide/resources/
resources:
Resources:
CurrentMessageBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:service}-current-message
legal:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:service}-legal
VersioningConfiguration:
Status: Enabled
PushNotifTicketsTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Delete
Properties:
TableName: NotificationTickets-${self:provider.stage}
AttributeDefinitions:
- AttributeName: type
AttributeType: S
- AttributeName: uuid
AttributeType: S
KeySchema:
- AttributeName: type
KeyType: HASH
- AttributeName: uuid
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
PushNotifSubsTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Delete
Properties:
TableName: PushNotifSubs-${self:provider.stage}
AttributeDefinitions:
- AttributeName: expoPushToken
AttributeType: S
- AttributeName: time
AttributeType: S
KeySchema:
- AttributeName: expoPushToken
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 3
WriteCapacityUnits: 3
GlobalSecondaryIndexes:
- IndexName: TimeIndex
KeySchema:
- AttributeName: time
KeyType: HASH
- AttributeName: expoPushToken
KeyType: RANGE
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 3
WriteCapacityUnits: 3
custom:
# https://www.serverless.com/plugins/serverless-s3-sync
s3Sync:
- bucketName: ${self:service}-legal
localDir: assets
acl: public-read
followSymlinks: false
# https://www.serverless.com/plugins/serverless-plugin-aws-alerts
alerts:
stages:
- prod
topics:
alarm:
topic: ${self:service}-${self:provider.stage}-alerts-alarm
notifications:
- protocol: email
endpoint: ${env:ALERT_EMAIL}
alarms:
- functionErrors