-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathserverless.yml
executable file
·169 lines (156 loc) · 4.23 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
service: poc-magic-links
frameworkVersion: '2'
# Attaching handlers
functions:
# 0. Initiates sign-in
login:
handler: api/login.handler
events:
- http:
path: /login
method: post
cors: true
# 1. Define auth challenge (letting Cognito know that we have a custom challenge)
define-auth-challenge:
handler: api/define-auth-challenge.handler
events:
- cognitoUserPool:
pool: ${self:custom.userPoolName}
trigger: DefineAuthChallenge
existing: true
# 2. Create the actual auth challenge
create-auth-challenge:
handler: api/create-auth-challenge.handler
events:
- cognitoUserPool:
pool: ${self:custom.userPoolName}
trigger: CreateAuthChallenge
existing: true
# 3. Verify auth challenge
verify-auth-challenge:
handler: api/verify-auth-challenge.handler
events:
- cognitoUserPool:
pool: ${self:custom.userPoolName}
trigger: VerifyAuthChallengeResponse
existing: true
# Set up Cognito & S3
resources:
Resources:
UserPool:
Type: "AWS::Cognito::UserPool"
Properties:
MfaConfiguration: OFF
UserPoolName: ${self:custom.userPoolName}
AutoVerifiedAttributes:
- email
UsernameAttributes:
- email
Schema:
- Name: email
Mutable: true
Required: true
- Name: name
Mutable: true
- Name: authChallenge
AttributeDataType: String
Mutable: true
Policies:
PasswordPolicy:
MinimumLength: 6
RequireLowercase: False
RequireNumbers: True
RequireSymbols: False
RequireUppercase: True
UserPoolClient:
Type: "AWS::Cognito::UserPoolClient"
Properties:
ClientName: ${self:custom.userPoolClientName}
UserPoolId:
Ref: UserPool
ExplicitAuthFlows:
- ADMIN_NO_SRP_AUTH
GenerateSecret: false
AllowedOAuthFlows:
- implicit
AllowedOAuthScopes:
- phone
- email
- openid
SupportedIdentityProviders:
- COGNITO
CallbackURLs:
- http://localhost:3001/auth/callback
DefaultRedirectURI: http://localhost:3001/auth/callback
WebBucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: ${self:custom.webBucketName}
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: index.html
Outputs:
UserPoolId:
Value: !Ref UserPool
UserPoolClientId:
Value: !Ref UserPoolClient
# Default serverless stuff
provider:
name: aws
runtime: nodejs10.x
region: eu-west-1
stage: ${self:custom.stage}
environment:
URL: {"Fn::Join": ["", ["https://", {"Ref": "ApiGatewayRestApi"}, ".execute-api.${self:provider.region}.amazonaws.com/${self:provider.stage}"]]}
USER_POOL_ID: {"Ref": "UserPool"}
iamRoleStatements:
- Effect: "Allow"
Action:
- cognito-idp:AdminGetUser
- cognito-idp:AdminUpdateUserAttributes
Resource:
- {"Fn::GetAtt": [UserPool, Arn]}
plugins:
- serverless-apigateway-service-proxy
- serverless-s3-sync
package:
exclude:
- frontend/**
- node_modules/aws-sdk/**
custom:
stage: ${opt:stage, 'dev'}
userPoolName: sls-magic-link-poc-user-pool-${self:custom.stage}
userPoolClientName: sls-magic-link-poc-pool-client-${self:custom.stage}
webBucketName: sls-magic-link-poc-web-${self:custom.stage}
apiGatewayServiceProxies:
- s3:
path: /
method: get
action: GetObject
bucket:
Ref: WebBucket
key: index.html
cors: true
- s3:
path: /sign-in/{challenge}
method: get
action: GetObject
bucket:
Ref: WebBucket
key: index.html
cors: true
- s3:
path: /{myPath+}
method: get
action: GetObject
key:
pathParam: myPath
bucket:
Ref: WebBucket
cors: true
s3Sync:
- bucketName: ${self:custom.webBucketName}
localDir: frontend/build/
acl: public-read
followSymlinks: true
defaultContentType: text/html