-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
232 lines (221 loc) · 6.87 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
service: todos-app-cognito-dynamodb
frameworkVersion: "3"
provider:
name: aws
runtime: nodejs18.x # Set the desired version
region: us-west-2 # Set the desired region
stage: dev
environment:
accountId: ${AWS::AccountId}
COGNITO_ID: !Ref CognitoUserPool
COGNITO_USER_POOL_CLIENT_ID: !Ref CognitoUserPoolClient
# JWT_SECRET:
DYNAMODB_TABLE: ${self:custom.todosTableName}
TODOS_TABLE_NAME: ${self:custom.todosTableName}
custom:
todosTableName: todos #Set the desired dynamodb table name in lower case, without spaces and special chars
# jwtSecret: ${environment:JWT_SECRET}
webpack:
webpackConfig: "webpack.config.js" # Name of webpack configuration file
includeModules: true # Node modules configuration for packaging
# forceExclude:
# - aws-sdk
packager: "npm" # Packager that will be used to package your external modules
excludeFiles: src/**/*.test.js # Provide a glob for files to ignore
plugins:
- serverless-plugin-scripts
- serverless-webpack
- aws-cognito-idp-userpool-domain
functions:
create:
handler: todos/create.handler
events:
- http:
method: post
path: /todos
private: true
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
get:
handler: todos/get.handler
events:
- http:
method: get
path: /todos/{id}
private: true
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
list:
handler: todos/list.handler
events:
- http:
method: get
path: /todos
private: true
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
update:
handler: todos/update.handler
events:
- http:
method: put
path: /todos/{id}
private: true
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
delete:
handler: todos/delete.handler
events:
- http:
method: delete
path: /todos/{id}
private: true
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer
signup:
handler: auth/signup.handler
events:
- http:
method: post
path: /auth/signup
cors: true
login:
handler: auth/login.handler
events:
- http:
method: post
path: /auth/login
cors: true
resources:
Resources:
TodosTable:
Type: "AWS::DynamoDB::Table"
Properties:
TableName: ${self:custom.todosTableName}
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
BillingMode: PAY_PER_REQUEST #Set the desired mode
CognitoUserPool:
Type: "AWS::Cognito::UserPool"
Properties:
UserPoolName: ${self:service}-user-pool
AutoVerifiedAttributes:
- email
EmailVerificationSubject: Your verification code
EmailVerificationMessage: Your verification code is {####}.
AdminCreateUserConfig:
AllowAdminCreateUserOnly: false
InviteMessageTemplate:
EmailMessage: Your username is {username} and temporary password is {####}. Please sign in using this temporary password and change your password.
EmailSubject: Your temporary password
Policies:
PasswordPolicy:
MinimumLength: 14
RequireLowercase: true
RequireNumbers: true
RequireSymbols: true
RequireUppercase: true
MfaConfiguration: OFF #If want to enable MFA, do it manually, deploying with it enabled, may cause issues.
EmailConfiguration:
EmailSendingAccount: COGNITO_DEFAULT
Schema:
- AttributeDataType: String
- Name: email
Required: true
- AttributeDataType: String
- Name: name
Required: true
UsernameAttributes:
- email
AccountRecoverySetting:
RecoveryMechanisms:
- Name: verified_email
Priority: 1
CognitoUserPoolClient:
Type: "AWS::Cognito::UserPoolClient"
Properties:
UserPoolId: !Ref CognitoUserPool
ClientName: ${self:service}-user-pool-client
GenerateSecret: false
ExplicitAuthFlows:
- USER_PASSWORD_AUTH
CallbackURLs: # Type your desired callback URLs below
- https://example.com/callback
LogoutURLs: #Type your desired allowed sign-out URLs
- https://example.com/logout
AllowedOAuthFlowsUserPoolClient: True
SupportedIdentityProviders:
- COGNITO
AllowedOAuthFlows:
- code
AllowedOAuthScopes:
- email
- openid
- phone
- profile
AccessTokenValidity: 8
IdTokenValidity: 8
ApiGatewayAuthorizer:
Type: "AWS::ApiGateway::Authorizer"
Properties:
Name: cognito-authorizer
IdentitySource: method.request.header.Authorization
RestApiId:
Ref: "ApiGatewayRestApi"
Type: COGNITO_USER_POOLS
ProviderARNs:
- !GetAtt CognitoUserPool.Arn
AuthorizerResultTtlInSeconds: 300
CognitoUserPoolDomain:
Type: "AWS::Cognito::UserPoolDomain"
Properties:
Domain: ${self:custom.todosTableName} # Type your custom Cognito Hosted subdomain here
UserPoolId: !Ref CognitoUserPool
# Direct your users to https://<your_domain>.auth.<region>/login?response_type=token&client_id=<your_app_client_id>&redirect_uri=<your_callback_url>
# To create a new account, go to: https://<your_domain>.auth.<region>/signup?response_type=token&client_id=<your_app_client_id>&redirect_uri=<your_callback_url>
# Can configure at Cognito user pool App client.
# Outputs to use in future improvements
Outputs:
TodosTableArn:
Value:
Ref: TodosTable
Export:
Name: ${self:service}-${self:custom.todosTableName}-Arn
TodosTableName:
Value: ${self:custom.todosTableName}
Export:
Name: ${self:service}-${self:custom.todosTableName}-Name
UserPoolId:
Value:
Ref: CognitoUserPool
Export:
Name: ${self:service}-user-pool-id
UserPoolClientId:
Value:
Ref: CognitoUserPoolClient
Export:
Name: ${self:service}-user-pool-client-id
UserPoolClientArn:
Value:
Ref: CognitoUserPoolClient
Export:
Name: ${self:service}-user-pool-client-arn
# UserPoolClientDomain:
# Value:
# Ref: CognitoUserPoolClientDomain
# Export:
# Name: ${self:service}-user-pool-client-domain