AWS Code Sample
Catalog

lambda-trigger-post-confirmation.js

This example Lambda function sends a confirmation email message to your user using Amazon SES.

// Copyright 2010-2019 Amazon.com, 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 // // http://aws.amazon.com/apache2.0/ // // 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. 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"); };

Sample Details

Service: cognito-idp

Last tested: 2019-01-30

Author: AWS

Type: full-example

On this page: