如何将个性化参数嵌入到Amazon Cognito验证邮件中

时间:2016-11-15 12:51:32

标签: amazon-cognito

Amazon Cognito会针对忘记密码请求发送验证电子邮件。 如何使用个性化参数更新此验证电子邮件,使其包含以下参数:(用户名/电子邮件)。

1 个答案:

答案 0 :(得分:1)

您可以将lambda函数用于类似于下面的自定义消息。可以在lambda控制台中输入lambda函数的代码,并通过用户池中的Triggers面板进行配置。

您需要检查event.triggerSource以确保它是forgotPassword事件,并且您可以访问电子邮件和用户名作为event.request.userAttributes.email和event.userName

exports.handler = function(event, context) {
    // 
    if(event.userPoolId === "theSpecialUserPool") {
        // Identify why was this function invoked
        if(event.triggerSource === "CustomMessage_ForgotPassword") {
            // Ensure that your message contains event.request.codeParameter. This is the placeholder for code that will be sent
            event.response.smsMessage = "You requested to reset your password " + event.request.codeParameter;
            event.response.emailSubject = "You requested to reset your password " + event.request.userAttributes.email + " " + event.request.userName;
            event.response.emailMessage = "Thank you for signing up. " + event.request.codeParameter + " is your verification code " + event.request.userAttributes.email + " " + event.request.userName;
        }
        // Create custom message for other events
    }
    // Customize messages for other user pools

   //

   // Return result to Cognito
   context.done(null, event);
};