In this tutorial, I will share how to automatically confirm users in your application without sending the confirmation code.
When users signup in for your application normally you will send a confirmation code in their email or phone to confirm their account.
This tutorial will be helpful if you are using AWS Cognito. Assuming you want to auto-confirm your user’s email and phone numbers. This can be done using a Lambda function.
STEPS
- Create a Lambda function name it confirmSignUp. For this tutorial, I will use runtime Node.js 18.x.
- Copy the following and paste it in the index.mjs file.
export const handler = (event, context, callback) => {
// Confirm the user
event.response.autoConfirmUser = true;
// Set the email as verified if it is in the request
if (event.request.userAttributes.hasOwnProperty("email")) {
event.response.autoVerifyEmail = true;
}
// Set the phone number as verified if it is in the request
if (event.request.userAttributes.hasOwnProperty("phone_number")) {
event.response.autoVerifyPhone = true;
}
// Return to Amazon Cognito
callback(null, event);
};
- Save the Lambda function and go back to AWS Cognito dashboard.
- Select user pool and go to User pool properties and click Add Lambda trigger.

- Under Lambda triggers Select Sign-up as Trigger type and under sign-up select Pre sign-up trigger option. Pre sign-up trigger will be disabled once you add lambda for this option.

- Finally select your Lambda function and click Add Lambda trigger button.
