Aws Cognito 预注册触发器失败并出现 InvalidLambdaResponseException

问题描述 投票:0回答:2

我的预注册触发 lambda 失败并出现 InvalidLambdaResponseException。使用nodejs。用户注册无需触发器即可进行。

我尝试了几乎所有关于如何处理此触发器建议的解决方案。我尝试用 context.done(null, event) 和 callback(null, event) 结束 lambda。测试脚本有效。 值得一提的是,我有大约 10 个用户属性,其中包括 7 个自定义属性。

exports.handler = (event, context, callback) => {

// Check if business phone exists
event.response.autoConfirmEmail = false;
// This example uses a custom attribute "custom:domain"
if (event.request.userAttributes.hasOwnProperty("custom:business_phone")) {
    if ( event.request.userAttributes["custom:business_phone"] !== null
    && event.request.userAttributes["custom:business_phone"] !== "") {
        event.response.autoConfirmEmail = true;
    }
}

// Return to Amazon Cognito
callback(null, event);

//context.done(null, event);    
};

测试事件有效,但浏览器中的用户注册返回 InvalidLambdaResponseException。尝试了最后两行之一或全部。

更新: 后确认触发器出现相同的异常。按原样使用 aws 文档示例。使用运行时 NodeJs 10.x。也试过8.10。

请各位专家帮忙!

amazon-cognito amazon-cognito-triggers
2个回答
0
投票

我遇到了同样的问题,结果发现错误是由我的cloudformation中的另一个 lambda引起的:

exports.handler = (event, context, callback) => {
  if (event.triggerSource === "CustomMessage_ForgotPassword") {
    event.response.emailSubject = "Reset your password for blah";
    event.response.emailMessage = "Blah blah";
    callback(null, event);
  }
};

当注册发送电子邮件时,它也在执行上述 lambda。但是

callback(null, event);
位于
if
语句内,因此未执行,因为
event.triggerSource
不是
"CustomMessage_ForgotPassword"

通过将

callback(null, event);
放在
if
语句之外解决这个问题,解决了整个问题。

我建议检查您的其他 lambda 是否最终总是执行

callback(null, event)
,因为错误可能是由与您预期不同的 lambda 引起的。


0
投票

就我而言,我忘记在处理函数定义中使用async。看来你也这么做了。

当前开发者指南的链接: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-sign-up.html#aws-lambda-triggers-pre-registration-example-2

© www.soinside.com 2019 - 2024. All rights reserved.