-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
258 lines (243 loc) · 6.51 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
service: serverless-framework-app
package:
individually: true
patterns:
- "!*/**"
- "!eslint.config.mjs"
- "src/constants.js"
- "src/lib/dynamodb.js"
- "src/utils/unwrapTypes.js"
provider:
name: aws
runtime: nodejs20.x
iam:
role:
statements:
- Effect: Allow
Action:
- 'dynamodb:Scan'
- 'dynamodb:GetItem'
- 'dynamodb:PutItem'
- 'dynamodb:UpdateItem'
- 'dynamodb:DeleteItem'
Resource: !GetAtt DynamoDB.Arn
- Effect: Allow
Action:
- 's3:GetObject'
- 's3:PutObject'
Resource: !Sub ${S3Bucket.Arn}/*
apiGateway:
apiKeys:
- serverless-framework-app
environment:
SECRET_KEY: ${ssm:/SECRET_KEY}
plugins:
- serverless-lift
- serverless-plugin-typescript
- serverless-apigateway-service-proxy
layers:
nodejs:
name: "nodejs-sls-app-layer"
compatibleRuntimes:
- ${self:provider.runtime}
package:
artifact: layer-artifacts/nodejs.zip
functions:
get-user:
handler: src/functions/get-user/index.handler
description: Returns the information of a single user
package:
patterns:
- "src/functions/get-user/*"
events:
- http:
private: true
path: users/{id}
method: GET
request:
parameters:
paths:
id: true
get-users:
handler: src/functions/get-users/index.handler
description: Returns a list of users
package:
patterns:
- "src/functions/get-users/*"
events:
- http:
private: true
path: users
method: GET
request:
parameters:
querystrings:
lastKey: false
create-user:
handler: src/functions/create-user/index.handler
description: Allows to register a new user into the application
package:
patterns:
- "src/functions/create-user/*"
events:
- http:
path: users
method: POST
authorizer:
name: custom-authorizer
resultTtlInSeconds: 15
request:
schemas:
application/json: ${file(src/schemas/user.json)}
update-user:
handler: src/functions/update-user/index.handler
description: Allows to update a user record
package:
patterns:
- "src/functions/update-user/*"
events:
- http:
path: users/{id}
method: PUT
authorizer:
name: custom-authorizer
resultTtlInSeconds: 15
request:
parameters:
paths:
id: true
schemas:
application/json:
schema: ${file(src/schemas/user.json)}
name: PostCreateModel
description: 'Validation model for creating users'
delete-user:
handler: src/functions/delete-user/index.handler
description: Allows to delete a user record
package:
patterns:
- "src/functions/delete-user/*"
events:
- http:
path: users/{id}
method: DELETE
authorizer:
name: custom-authorizer
resultTtlInSeconds: 15
request:
parameters:
paths:
id: true
create-signed-upload-url:
handler: src/functions/create-signed-upload-url/index.handler
description: Returns a signed S3 URL to upload an image
package:
patterns:
- "src/functions/create-signed-upload-url/*"
- "src/lib/s3.js"
- "!src/lib/dynamodb.js"
- "!src/utils/unwrapTypes.js"
environment:
AWS_S3_BUCKET_NAME: ${self:custom.aws-bucket-name}
events:
- http:
path: signed-url
method: POST
authorizer:
name: custom-authorizer
resultTtlInSeconds: 15
request:
schemas:
application/json: ${file(src/schemas/signed-url.json)}
thumbnail-generator:
handler: src/functions/thumbnail-generator/index.handler
layers:
- { Ref: NodejsLambdaLayer }
package:
patterns:
- "!src/lib/dynamodb.js"
- "!src/utils/unwrapTypes.js"
- "src/functions/thumbnail-generator/*"
- "src/lib/s3.js"
events:
- s3:
bucket: ${self:custom.aws-bucket-name}
event: s3:ObjectCreated:*
existing: true
rules:
- prefix: upload/
custom-authorizer:
handler: src/functions/authorizer/index.handler
package:
patterns:
- "!src/lib/dynamodb.js"
- "src/functions/authorizer/*"
custom:
aws-bucket-name: serverless-framework-app-janr-test-1-dev
apiGatewayServiceProxies:
- sqs:
path: /like-user
method: POST
queueName: like-user-queue
cors: true
response:
template:
success: |-
{ "message": "accepted" }
clientError: |-
{ "message": "there is an error in your request" }
serverError: |-
{ "message": "there was an error handling your request" }
constructs:
sqs-queue:
type: queue
worker:
handler: src/functions/like-user/index.handler
package:
patterns:
- "!src/utils/*"
- "src/functions/like-user/*"
extensions:
queue:
Properties:
QueueName: like-user-queue
resources:
Resources:
DynamoDB:
Type: AWS::DynamoDB::Table
Properties:
TableName: usersTable
AttributeDefinitions:
- AttributeName: pk
AttributeType: S
KeySchema:
- AttributeName: pk
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
S3Bucket:
Type: AWS::S3::Bucket
Properties:
PublicAccessBlockConfiguration:
RestrictPublicBuckets: false
IgnorePublicAcls: false
BlockPublicPolicy: false
BlockPublicAcls: false
BucketName: ${self:custom.aws-bucket-name}
OwnershipControls:
Rules:
- ObjectOwnership: BucketOwnerPreferred
S3BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref S3Bucket
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: statement1
Resource: !Sub ${S3Bucket.Arn}/*
Effect: "Allow"
Principal: "*"
Action:
- "s3:GetObject"