-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
166 lines (162 loc) · 4.68 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
service: apigw-workshop
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs14.x
region: eu-west-1
environment:
REGION: "eu-west-1"
TODO_LIST_TABLE: "TODO_LIST_TABLE_${opt:stage, self:provider.stage, 'default'}"
# https://www.serverless.com/framework/docs/providers/aws/guide/iam#the-default-iam-role
iam:
role:
name: apigw-workshop-lambdaRole
statements:
- Effect: Allow
Action: 'dynamodb:*'
Resource:
- "Fn::GetAtt": [DynamoDBTasksTable, Arn]
- "Fn::Join": ["", [Fn::GetAtt: [DynamoDBTasksTable, Arn], "/*"]]
functions:
hello:
handler: handler.hello
events:
- http:
path: /hello
method: get
cors: true
authorized_hello:
handler: src/services/hello/authorized_handler.handler
events:
- http:
path: /hello/user
method: get
cors: true
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
createTask:
handler: src/services/toDoList/functions/createTask/createTask.handler
events:
- http:
path: /tasks
method: post
cors: true
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
getTask:
handler: src/services/toDoList/functions/getTask/getTask.handler
events:
- http:
path: /tasks/{id}
method: get
cors: true
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
listTasks:
handler: src/services/toDoList/functions/listTasks/listTasks.handler
events:
- http:
path: /tasks
method: get
cors: true
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
updateTaskStatus:
handler: src/services/toDoList/functions/updateTaskStatus/updateTaskStatus.handler
events:
- http:
path: /tasks/{id}
method: put
cors: true
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
removeTask:
handler: src/services/toDoList/functions/removeTask/removeTask.handler
events:
- http:
path: /tasks/{id}
method: delete
cors: true
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
resources:
Resources:
CognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
MfaConfiguration: OFF
UserPoolName: "todo-list-pool-${opt:stage, self:provider.stage, 'default'}"
UsernameAttributes:
- "email"
Policies:
PasswordPolicy:
MinimumLength: 6
RequireLowercase: False
RequireNumbers: True
RequireSymbols: False
RequireUppercase: True
AccountRecoverySetting:
RecoveryMechanisms:
- Name: "verified_email"
Priority: 1
AutoVerifiedAttributes:
- "email"
CognitoUserPoolClient:
Type: AWS::Cognito::UserPoolClient
Properties:
ClientName: "todo-list-client-${opt:stage, self:provider.stage, 'default'}"
GenerateSecret: False
UserPoolId:
Ref: CognitoUserPool
ApiGatewayAuthorizer:
DependsOn:
- ApiGatewayRestApi
Type: AWS::ApiGateway::Authorizer
Properties:
Name: cognito-authorizer
IdentitySource: method.request.header.Authorization
RestApiId:
Ref: ApiGatewayRestApi
Type: COGNITO_USER_POOLS
ProviderARNs:
- Fn::GetAtt: [CognitoUserPool, Arn]
DynamoDBTasksTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: "TODO_LIST_TABLE_${opt:stage, self:provider.stage, 'default'}"
AttributeDefinitions:
- AttributeName: "PK"
AttributeType: "S"
- AttributeName: "SK"
AttributeType: "S"
- AttributeName: "taskId"
AttributeType: "S"
- AttributeName: "type"
AttributeType: "S"
KeySchema:
- AttributeName: "PK"
KeyType: "HASH"
- AttributeName: "SK"
KeyType: "RANGE"
GlobalSecondaryIndexes:
- IndexName: "GSI1-PK"
KeySchema:
- AttributeName: "type"
KeyType: "HASH"
- AttributeName: "taskId"
KeyType: "RANGE"
Projection:
ProjectionType: "ALL"
BillingMode: "PAY_PER_REQUEST"