Amazon Cognito
Developer Guide

Post Confirmation Lambda Trigger

Amazon Cognito invokes this trigger after a new user is confirmed, allowing you to send custom messages or to add custom logic. For example, you could use this trigger to gather new user data.

The request contains the current attributes for the confirmed user.

Post Confirmation Lambda Flows

Client Confirm Sign-up Flow


                        Client confirm sign-up flow

Server Confirm Sign-up Flow


                        Server confirm sign-up

Confirm Forgot Password Flow


                    Confirm forgot password flow

Post Confirmation Lambda Trigger Parameters

These are the parameters required by this Lambda function in addition to the common parameters.

JSON
JSON
{ "request": { "userAttributes": { "string": "string", .... } }, "response": {} }

Post Confirmation Request Parameters

userAttributes

One or more name-value pairs representing user attributes.

Post Confirmation Response Parameters

No additional return information is expected in the response.

User Confirmation Tutorials

The post confirmation Lambda function is triggered just after Amazon Cognito confirms a new user. See these user confirmation tutorials for JavaScript, Android, and iOS.

Platform Tutorial
JavaScript Identity SDK Confirm users with JavaScript
Android Identity SDK Confirm users with Android
iOS Identity SDK Confirm users with iOS

Post Confirmation Example

This example Lambda function sends a confirmation email message to your user using Amazon SES. For more information see Amazon Simple Email Service Developer Guide.

Node.js
Node.js
var aws = require('aws-sdk'); var ses = new aws.SES(); exports.handler = (event, context, callback) => { console.log(event); if (event.request.userAttributes.email) { sendEmail(event.request.userAttributes.email, "Congratulations " + event.userName + ", you have been confirmed: ", function(status) { // Return to Amazon Cognito callback(null, event); }); } else { // Nothing to do, the user's email ID is unknown callback(null, event); } }; function sendEmail(to, body, completedCallback) { var eParams = { Destination: { ToAddresses: [to] }, Message: { Body: { Text: { Data: body } }, Subject: { Data: "Cognito Identity Provider registration completed" } }, // Replace source_email with your SES validated email address Source: "<source_email>" }; var email = ses.sendEmail(eParams, function(err, data){ if (err) { console.log(err); } else { console.log("===EMAIL SENT==="); } completedCallback('Email sent'); }); console.log("EMAIL CODE END"); };

Amazon Cognito passes event information to your Lambda function. The function then returns the same event object back to Amazon Cognito, with any changes in the response. In the Lambda console, you can set up a test event with data that’s relevant to your Lambda trigger. The following is a test event for this code sample:

JSON
JSON
{ "request": { "userAttributes": { "email": "user@example.com", "email_verified": true } }, "response": {} }