AWS Cognito with Lambda用于自定义验证

时间:2017-08-18 14:16:59

标签: aws-lambda aws-cognito

将AWS Lambda与Cognito一起使用,我们可以使用以下代码自动验证电子邮件。

event.response.autoConfirmUser = true;
event.response.autoVerifyEmail = true;

如何在此处进行自定义请求验证?

如果我想在Cognito注册时发送PROMO CODE,那么我是否可以使用代码验证此促销代码并拒绝注册请求(如果它是无效的promocode)。

2 个答案:

答案 0 :(得分:4)

搞定了: - )

exports.handler = (event, context, callback) => {
    //Auto confirming user and verifying emaail
    event.response.autoConfirmUser = true;
    event.response.autoVerifyEmail = true;
    //Extract Registration code from user attributes 
    var rCode = event.request.userAttributes["custom:rCode"];
    var validRCode = "abcdef";
    if (rCode && rCode.toLowerCase() != validRCode) {
         //If registration code is available and it is not equal to validRCode then throw error message
         var error = new Error(': Invalid registration code used.');
         context.done(error, event);
    } else {
      context.done(null, event);
    }
};

答案 1 :(得分:0)

您可以设置触发器来自定义UserPool工作流程:http://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html

在您的情况下,设置预注册触发器应该没问题。