import { CognitoUserPoolTriggerEvent } from "aws-lambda" ; import { CognitoIdentityServiceProvider } from "aws-sdk" ; param event return export async function handler ( event ) { const { Users } = await new CognitoIdentityServiceProvider ( { apiVersion : "2016-04-18" } ) . listUsers ( { UserPoolId : event . userPoolId , Filter : `email="${ event . request . userAttributes . email }"` } ) . promise ( ) ; if ( Users ! . length ) throw new Error ( "Email address already registered" ) ; return event ; }