-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
170 lines (142 loc) · 4.25 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
service: serverless-shortlinker-api
frameworkVersion: '3'
plugins:
- serverless-plugin-typescript
provider:
name: aws
runtime: nodejs18.x
stage: dev
region: eu-central-1
httpApi:
cors: true
authorizers:
customAuthorizerUsers:
type: request
functionName: authorizerUsers
environment:
USERS_TABLE: ${self:service}-${opt:stage, self:provider.stage}-USERS_TABLE
LINKS_TABLE: ${self:service}-${opt:stage, self:provider.stage}-LINKS_TABLE
#DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}
#https://udhcf9fhw2.execute-api.eu-central-1.amazonaws.com/links/d0f280
BASE_URL: !GetAtt HttpApi.ApiEndpoint
# SQS_DEACTIVATION_QUEUE_URL: !Ref DeactivationQueue
SECRET_ACCESS_TOKEN: ${file(./secrets.json):SECRET_ACCESS_TOKEN}
SECRET_REFRESH_TOKEN: ${file(./secrets.json):SECRET_REFRESH_TOKEN}
SES_EMAIL: ${file(./secrets.json):SES_EMAIL}
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource:
- 'arn:aws:dynamodb:${aws:region}:*:table/${self:provider.environment.USERS_TABLE}'
- 'arn:aws:dynamodb:${aws:region}:*:table/${self:provider.environment.LINKS_TABLE}'
# - 'arn:aws:dynamodb:${aws:region}:*:table/${self:provider.environment.DYNAMODB_TABLE}'
# - { 'Fn::GetAtt': ['TableUsers', 'Arn'] }
# - { 'Fn::GetAtt': ['TableLinks', 'Arn'] }
functions:
authorizerUsers:
handler: src/functions/authorizer.users
signUp:
handler: src/functions/auth.signUp
events:
- httpApi:
path: /auth/sign-up
method: post
signIn:
handler: src/functions/auth.signIn
events:
- httpApi:
path: /auth/sign-in
method: post
usersList:
handler: src/functions/auth.usersList
events:
- httpApi:
path: /auth/list
method: get
createNewLink:
handler: src/functions/links.createNewLink
events:
- httpApi:
path: /links/create-new-link
method: post
authorizer:
name: customAuthorizerUsers
linksList:
handler: src/functions/links.linksList
events:
- httpApi:
path: /links/list
method: get
authorizer:
name: customAuthorizerUsers
redirectToOriginalLink:
handler: src/functions/links.redirectToOriginalLink
events:
- httpApi:
path: /links/{linkMarker}
method: get
deactivateLink:
handler: src/functions/links.deactivateLink
events:
- httpApi:
path: /links/deactivate/{linkID}
method: patch
authorizer:
name: customAuthorizerUsers
deactivateLinkCron:
handler: src/functions/links.deactivateLinkCron
events:
# - schedule: "cron(0 0 * * *)"
- httpApi:
path: /links/deactivate
method: get
authorizer:
name: customAuthorizerUsers
# ses-services:
# handler: src/services/ses.sendEmailsForDeactivatedLinks
# event:
# - sqs:
# arn: !GetAtt DeactivationQueue.Arn
# batchSize: 10
resources:
Resources:
TableUsers:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: ${self:provider.environment.USERS_TABLE}
AttributeDefinitions:
- AttributeName: userID
AttributeType: S
KeySchema:
- AttributeName: userID
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
TableLinks:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: ${self:provider.environment.LINKS_TABLE}
AttributeDefinitions:
- AttributeName: linkID
AttributeType: S
KeySchema:
- AttributeName: linkID
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
# DeactivationQueue:
# Type: AWS::SQS::Queue
# Properties:
# QueueName: deactivation-queue
# VisibilityTimeout: 900
# MessageRetentionPeriod: 86400