github.com/Foodji/aws-lambda-go@v1.20.2/events/README_Cognito_UserPools_CustomAuthLambdaTriggers.md (about) 1 # Sample Function 2 3 The following is a sample Lambda functions that are used for custom authentication with Cognito User Pools. 4 These Lambda triggers issue and verify their own challenges as part of a user pool [custom authentication flow](https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html#amazon-cognito-user-pools-custom-authentication-flow). 5 6 Please see instructions for setting up the Cognito triggers at https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-challenge.html 7 8 Define Auth Challenge Lambda Trigger: 9 ```go 10 package main 11 12 import ( 13 "fmt" 14 15 "github.com/aws/aws-lambda-go/lambda" 16 "github.com/aws/aws-lambda-go/events" 17 ) 18 19 func handler(event *events.CognitoEventUserPoolsDefineAuthChallenge) (*events.CognitoEventUserPoolsDefineAuthChallenge, error) { 20 fmt.Printf("Define Auth Challenge: %+v\n", event) 21 return event, nil 22 } 23 24 func main() { 25 lambda.Start(handler) 26 } 27 ``` 28 29 Create Auth Challenge Lambda Trigger: 30 ```go 31 package main 32 33 import ( 34 "fmt" 35 36 "github.com/aws/aws-lambda-go/lambda" 37 "github.com/aws/aws-lambda-go/events" 38 ) 39 40 func handler(event *events.CognitoEventUserPoolsCreateAuthChallenge) (*events.CognitoEventUserPoolsCreateAuthChallenge, error) { 41 fmt.Printf("Create Auth Challenge: %+v\n", event) 42 return event, nil 43 } 44 45 func main() { 46 lambda.Start(handler) 47 } 48 ``` 49 50 Verify Auth Challenge Response Lambda Trigger: 51 ```go 52 package main 53 54 import ( 55 "fmt" 56 57 "github.com/aws/aws-lambda-go/lambda" 58 "github.com/aws/aws-lambda-go/events" 59 ) 60 61 func handler(event *events.CognitoEventUserPoolsVerifyAuthChallenge) (*events.CognitoEventUserPoolsVerifyAuthChallenge, error) { 62 fmt.Printf("Verify Auth Challenge: %+v\n", event) 63 return event, nil 64 } 65 66 func main() { 67 lambda.Start(handler) 68 } 69 ```