-
Notifications
You must be signed in to change notification settings - Fork 3
/
serverless.yml
280 lines (255 loc) · 7.43 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
service: saas-identity-cognito-lambda
frameworkVersion: ">=1.1.0 <2.0.0"
plugins:
- serverless-dynamodb-local
- serverless-offline
- serverless-offline-sns
custom:
dynamodb:
start:
port: 8000
migrate: true
inMemory: true
migration:
dir: offline/migrations
serverless-offline-sns:
port: 4002
debug: true
serverless-offline:
noAuth: true
provider:
name: aws
runtime: nodejs8.10
stage: test
environment:
ACCESS_CONTROL_ALLOW_ORIGIN: "*"
TENANT_DYNAMODB_TABLE: ${self:service}-tenant-${opt:stage, self:provider.stage}
USER_DYNAMODB_TABLE: ${self:service}-user-${opt:stage, self:provider.stage}
IDENTITY_TOPIC: identity-${opt:stage, self:provider.stage}
COGNITO_DOMAIN_PREFIX: harman-telematics-${opt:stage, self:provider.stage}
COGNITO_CLIENT_CALLBACK_URLS: https://d337wujqerfaz5.cloudfront.net/admin, http://localhost:3000
COGNITO_SNS_ARN:
{
Fn::Join:
[
"",
[
"arn:aws:sns:${self:provider.region}:",
{ "Ref": "AWS::AccountId" },
":${self:provider.environment.IDENTITY_TOPIC}",
],
],
}
POST_CONFIRMATION_LAMBDA_ARN:
{
Fn::Join:
[
"",
[
"arn:aws:lambda:${self:provider.region}:",
{ "Ref": "AWS::AccountId" },
":function:${self:service}-${opt:stage, self:provider.stage}-postConfirmationHandler",
],
],
}
STAGE: ${opt:stage, self:provider.stage}
iamRoleStatements:
- Effect: Allow
Action:
- cognito-idp:*
Resource: "*"
- Effect: Allow
Action:
- dynamodb:*
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/*"
- Effect: Allow
Action:
- sns:*
Resource: "arn:aws:sns:${opt:region, self:provider.region}:*:*"
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource: "*"
deploymentBucket:
name: ${cf:cloud-deploy-${opt:stage, self:provider.stage}.ServerlessDeploymentBucketName}
apiGateway:
restApiId: ${cf:cloud-deploy-${opt:stage, self:provider.stage}.ApiGatewayRestApiId}
restApiRootResourceId: ${cf:cloud-deploy-${opt:stage, self:provider.stage}.ApiGatewayRootResourceId}
functions:
listTenants:
handler: src/lambda/tenant.list
events:
- http:
path: tenants
method: get
cors: true
getTenant:
handler: src/lambda/tenant.get
events:
- http:
path: tenants/{tenantId}
method: get
cors: true
createTenant:
handler: src/lambda/tenant.create
events:
- http:
path: tenants/{tenantId}
method: post
cors: true
updateTenant:
handler: src/lambda/tenant.update
events:
- http:
path: tenants/{tenantId}
method: put
cors: true
deleteTenant:
handler: src/lambda/tenant.delete
events:
- http:
path: tenants/{tenantId}
method: delete
cors: true
# This lambda arn is registered on new user pool creation and gets triggered by cognito on new user signup.
postConfirmationHandler:
handler: src/lambda/tenant.postUserRegistration
getToken:
handler: src/lambda/tenant.getToken
events:
- http:
path: tenants/{tenantId}/token
method: post
cors: true
updateToken:
handler: src/lambda/tenant.updateToken
events:
- http:
path: tenants/{tenantId}/token
method: put
cors: true
createUser:
handler: src/lambda/user.create
events:
- http:
path: users/{userId}
method: post
cors: true
authorizer: ${self:custom.authorizers.${self:custom.authorizers.status}.AdminAuthorizer}
# This lambda is called from tenant service on user sign-up from UI
createUserPostSignUp:
handler: src/lambda/user.createUserPostSignUp
listUsers:
handler: src/lambda/user.list
events:
- http:
path: users
method: get
cors: true
authorizer: ${self:custom.authorizers.${self:custom.authorizers.status}.AdminAuthorizer}
getUser:
handler: src/lambda/user.get
events:
- http:
path: users/{userId}
method: get
cors: true
authorizer: ${self:custom.authorizers.${self:custom.authorizers.status}.UserAuthorizer}
updateUser:
handler: src/lambda/user.update
events:
- http:
path: users/{userId}
method: put
cors: true
authorizer: ${self:custom.authorizers.${self:custom.authorizers.status}.UserAuthorizer}
deleteUser:
handler: src/lambda/user.delete
events:
- http:
path: users/{userId}
method: delete
cors: true
authorizer: ${self:custom.authorizers.${self:custom.authorizers.status}.AdminAuthorizer}
deleteAllUsers:
handler: src/lambda/user.deleteAll
events:
- http:
path: users
method: delete
cors: true
authorizer: ${self:custom.authorizers.${self:custom.authorizers.status}.AdminAuthorizer}
loginUser:
handler: src/lambda/user.login
events:
- http:
path: users/{userId}/login
method: post
cors: true
resources:
Resources:
UserDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.environment.USER_DYNAMODB_TABLE}
AttributeDefinitions:
- AttributeName: tenantId
AttributeType: S
- AttributeName: userId
AttributeType: S
KeySchema:
- AttributeName: tenantId
KeyType: HASH
- AttributeName: userId
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 10
WriteCapacityUnits: 10
GlobalSecondaryIndexes:
- IndexName: UserIdIndex
KeySchema:
- AttributeName: userId
KeyType: HASH
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 10
WriteCapacityUnits: 10
TenantTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
Properties:
TableName: ${self:provider.environment.TENANT_DYNAMODB_TABLE}
AttributeDefinitions:
- AttributeName: tenantId
AttributeType: S
KeySchema:
- AttributeName: tenantId
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 10
WriteCapacityUnits: 10
IdentityTopic:
Type: "AWS::SNS::Topic"
Properties:
DisplayName: ${self:provider.environment.IDENTITY_TOPIC}
TopicName: ${self:provider.environment.IDENTITY_TOPIC}
PostSignupTriggerInvokePermission:
Type: AWS::Lambda::Permission
DependsOn: PostConfirmationHandlerLambdaFunction
Properties:
Action: lambda:InvokeFunction
Principal: cognito-idp.amazonaws.com
FunctionName: ${self:service}-${opt:stage, self:provider.stage}-postConfirmationHandler
SourceArn:
{
"Fn::Join":
[
":",
[
"arn:aws:cognito-idp:${self:provider.region}",
{ "Ref": "AWS::AccountId" },
"userpool/*",
],
],
}