Skip to content

// auth and identity

Via API

Amazon Cognito email verification with pingutil

Cognito user pools will create and send confirmation codes to any address, including temp-mail inboxes that confirm in seconds. The Pre sign-up Lambda trigger runs before Cognito creates the user; throwing an error there after a fast pingutil lookup denies disposable and randomized addresses.

Where it connects: Amazon Cognito user pool Pre sign-up Lambda trigger

What goes wrong without it

  • Our Cognito user pool is full of UNCONFIRMED users at domains we have never heard of.
  • Temp-mail users confirm the code and get straight into our free tier.
  • Every confirmation email Cognito sends to a fake address costs us SES reputation.

What you can do with Amazon Cognito and pingutil

  • Deny disposable sign-ups

    Throw an Error when verdict.is_spam is true. Cognito returns it as "PreSignUp failed with error ..." and the user is not created.

  • Skip admin-created and federated users

    Check event.triggerSource and only screen PreSignUp_SignUp. Leave PreSignUp_AdminCreateUser and PreSignUp_ExternalProvider alone or apply a lighter rule.

  • Protect the email you send from Cognito

    Every blocked throwaway is one fewer confirmation email sent, which keeps bounces and complaints off your sending identity.

Set it up

  1. 1

    Create a Node.js Lambda function with the code below and set PINGUTIL_KEY as an environment variable (or read it from Secrets Manager at cold start).

  2. 2

    In the Cognito console, open the user pool, go to Extensions > Lambda triggers, add a Sign-up trigger of type Pre sign-up and select the function.

  3. 3

    Set the Lambda timeout to 5 seconds or less, since Cognito will not wait longer.

  4. 4

    Sign up through managed login or the SignUp API with a disposable address and confirm the error.

Pre sign-up Lambda (Node.js)
import type { PreSignUpTriggerHandler } from 'aws-lambda';

export const handler: PreSignUpTriggerHandler = async (event) => {
  // Only screen self-service sign-ups.
  if (event.triggerSource !== 'PreSignUp_SignUp') return event;

  const email = event.request.userAttributes.email;
  if (!email) return event;

  let data;
  try {
    const res = await fetch('https://pingutil.com/v1/lookup', {
      method: 'POST',
      headers: {
        authorization: 'Bearer ' + process.env.PINGUTIL_KEY,
        'content-type': 'application/json',
      },
      body: JSON.stringify({ input: email, skip_enrichment: true }),
      signal: AbortSignal.timeout(2500), // Cognito waits 5 s, not configurable
    });
    if (!res.ok) return event; // fail open
    data = await res.json();
  } catch {
    return event;
  }

  if (data.verdict.is_spam) {
    // Shown to the user, so keep it short and non-technical.
    throw new Error('Please sign up with a permanent email address.');
  }
  return event;
};

What to do with each result

pingutil resultAction in Amazon Cognito
verdict.is_spam: trueThrow an Error; Cognito does not create the user
verdict.low_trust: trueReturn the event; log the reason to CloudWatch for review
category: "company"Return the event; optionally set autoConfirmUser for trusted domains you list
Timeout, 429 or 5xxReturn the event unchanged (fail open)

Limits to plan for

  • Cognito invokes the trigger synchronously and expects a response within 5 seconds; AWS says this cannot be changed and Cognito may retry. Fast mode fits; a full mailbox check does not reliably fit.
  • Cognito returns trigger errors in the form "PreSignUp failed with error <your text>". Only put text in the error that you want users to read.
  • Fast mode does not detect dead mailboxes. Cognito will still send the confirmation code to a mistyped address.

Amazon Cognito documentation

Amazon Cognito is a trademark of its owner. This integration uses Amazon Cognito's documented extension points; it is not an official Amazon Cognito app.

Common questions

Will the check run for users I create with AdminCreateUser?
The trigger fires with triggerSource PreSignUp_AdminCreateUser. The snippet returns early for anything except PreSignUp_SignUp, so admin-created and federated users are not screened.
Can I verify the mailbox in the Pre sign-up trigger?
Not reliably within 5 seconds. Use fast mode in the trigger, and call /v1/verify from a Post confirmation trigger or a queue if you need mailbox status.

Stop bad addresses in Amazon Cognito today

Sign in with your email, create an API key and paste it into the step above. Test on a few real addresses first: the live demo shows exactly what your Amazon Cognito setup will receive.