-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yml
249 lines (229 loc) · 7.55 KB
/
template.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
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Amazon Cognito User Pool with Passwordless Facial Recognition Auth configured
Metadata:
AWS::ServerlessRepo::Application:
Name: amazon-cognito-passwordless-facial-rekognition-auth
Description: >
An Amazon Cognito user pool, pre-configured with AWS Lambda triggers to implement passwordless facial recognition auth using Amazon Rekognition
Author: Enrico Bergamo
SpdxLicenseId: MIT-0
LicenseUrl: LICENSE
ReadmeUrl: README.md
Labels: ['cognito', 'passwordless', 'authentication', 'rekognition', 'facial', 'recognition', 'auth', 'sample']
HomepageUrl: https://github.com/aws-samples/amazon-cognito-facial-recognition-auth/tree/master/
SemanticVersion: 1.0.2
SourceCodeUrl: https://github.com/aws-samples/amazon-cognito-facial-recognition-auth/tree/master/
Parameters:
UserPoolName:
Type: String
Description: The name you want the Amazon Cognito User Pool to be created with
CollectionName:
Type: String
Description: The custom Amazon Rekognition collection to index user faces
DocumentUploadBucketName:
Type: String
Description: The S3 bucket name for uploading custom documents when users sign up
SignInUploadBucketName:
Type: String
Description: The S3 bucket name for uploading user photos when signing in for comparison
Globals:
Function:
Environment:
Variables:
COLLECTION_NAME: !Ref CollectionName
BUCKET_SIGN_UP: !Ref DocumentUploadBucketName
Resources:
IndexFaces:
Type: AWS::Serverless::Function
Properties:
CodeUri: rekognition/index-faces/
Handler: index-faces.handler
Runtime: python3.6
Policies:
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- rekognition:IndexFaces
Resource: "*"
CreateRekognitionCollectionLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: rekognition/create-collection/
Handler: create-collection.handler
Runtime: python3.6
Policies:
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- rekognition:CreateCollection
- rekognition:DeleteCollection
Resource: "*"
DefineAuthChallenge:
Type: AWS::Serverless::Function
Properties:
CodeUri: cognito-triggers/define-auth-challenge/
Handler: define-auth-challenge.handler
Runtime: nodejs16.x
CreateAuthChallenge:
Type: AWS::Serverless::Function
Properties:
CodeUri: cognito-triggers/create-auth-challenge/
Handler: create-auth-challenge.handler
Runtime: nodejs16.x
Policies:
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- dynamodb:Query
Resource: "*"
VerifyAuthChallengeResponse:
Type: AWS::Serverless::Function
Properties:
CodeUri: cognito-triggers/verify-auth-challenge-response/
Handler: verify-auth-challenge-response.handler
Runtime: nodejs16.x
Policies:
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:getObject
- rekognition:SearchFacesByImage
Resource: "*"
PreSignUp:
Type: AWS::Serverless::Function
Properties:
CodeUri: cognito-triggers/pre-sign-up/
Handler: pre-sign-up.handler
Runtime: nodejs16.x
RekognitionCollection:
Type: Custom::CustomResource
Properties:
ServiceToken: !GetAtt 'CreateRekognitionCollectionLambda.Arn'
BucketSignUp:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: !Ref DocumentUploadBucketName
BucketSignIn:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: !Ref SignInUploadBucketName
CollectionTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: RekognitionId
AttributeType: S
- AttributeName: FullName
AttributeType: S
KeySchema:
- AttributeName: RekognitionId
KeyType: HASH
- AttributeName: FullName
KeyType: RANGE
GlobalSecondaryIndexes:
-
IndexName: FullName-index
KeySchema:
- AttributeName: FullName
KeyType: HASH
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
TableName: !Ref CollectionName
DefineAuthChallengeInvocationPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt DefineAuthChallenge.Arn
Principal: cognito-idp.amazonaws.com
SourceArn: !GetAtt UserPool.Arn
CreateAuthChallengeInvocationPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt CreateAuthChallenge.Arn
Principal: cognito-idp.amazonaws.com
SourceArn: !GetAtt UserPool.Arn
VerifyAuthChallengeResponseInvocationPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt VerifyAuthChallengeResponse.Arn
Principal: cognito-idp.amazonaws.com
SourceArn: !GetAtt UserPool.Arn
PreSignUpInvocationPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt PreSignUp.Arn
Principal: cognito-idp.amazonaws.com
SourceArn: !GetAtt UserPool.Arn
UserPool:
Type: "AWS::Cognito::UserPool"
Properties:
UserPoolName: !Ref UserPoolName
Schema:
- Name: name
AttributeDataType: String
Mutable: true
Required: true
- Name: email
AttributeDataType: String
Mutable: true
Required: true
- Name: s3-image-object
AttributeDataType: String
Mutable: true
Policies:
PasswordPolicy:
MinimumLength: 8
RequireLowercase: false
RequireNumbers: false
RequireSymbols: false
RequireUppercase: false
UsernameAttributes:
- email
MfaConfiguration: "OFF"
LambdaConfig:
CreateAuthChallenge: !GetAtt CreateAuthChallenge.Arn
DefineAuthChallenge: !GetAtt DefineAuthChallenge.Arn
PreSignUp: !GetAtt PreSignUp.Arn
VerifyAuthChallengeResponse: !GetAtt VerifyAuthChallengeResponse.Arn
UserPoolClient:
Type: "AWS::Cognito::UserPoolClient"
Properties:
ClientName: rekognition-auth-client
GenerateSecret: false
UserPoolId: !Ref UserPool
ExplicitAuthFlows:
- CUSTOM_AUTH_FLOW_ONLY
Outputs:
RekognitionCollectionArn:
Description: The Amazon Rekognition Custom Collection ARN.
Value: !GetAtt 'RekognitionCollection.Message'
SignUpBucketName:
Value: !Ref 'BucketSignUp'
Description: Name of the sign up Amazon S3 bucket.
SignInBucketName:
Value: !Ref 'BucketSignIn'
Description: Name of the sign in Amazon S3 bucket.
TableName:
Value: !Ref 'CollectionTable'
Description: Name of the DynamoDB table containing Rekognition metadata for each Cognito user
UserPoolId:
Value: !Ref 'UserPool'
Description: ID of the Cognito User Pool
UserPoolWebClientId:
Value: !Ref 'UserPoolClient'
Description: ID of the Cognito User Pool Client for Front-End Subscription