AWS Code Sample


This is a sample Lambda trigger called just before sign-up with the user pool pre sign-up Lambda trigger. It uses a custom attribute custom:domain to automatically confirm new users from a particular email domain. Any new users not in the custom domain will be added to the user pool, but not automatically confirmed.

// Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. // // This file is licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. A copy of // the License is located at // // // // This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. exports.handler = (event, context, callback) => { // Set the user pool autoConfirmUser flag after validating the email domain event.response.autoConfirmUser = false; // Split the email address so we can compare domains var address ="@") // This example uses a custom attribute "custom:domain" if (event.request.userAttributes.hasOwnProperty("custom:domain")) { if ( event.request.userAttributes['custom:domain'] === address[1]) { event.response.autoConfirmUser = true; } } // Return to Amazon Cognito callback(null, event); };

Sample Details

Service: cognito-idp

Last tested: 2019-01-30

Author: AWS

Type: full-example

On this page: