1

我的注册前触发 lambda 失败并出现 InvalidLambdaResponseException。使用节点。用户注册无需触发器即可工作。

我尝试了几乎所有关于如何处理此触发器的建议的解决方案。我尝试用 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。尝试了最后两行中的一个或两个。

更新:为 Post Confirm 触发器获得相同的异常。按原样使用 aws doc 示例。使用运行时 NodeJs 10.x。也试过8.10。

各位高手,请大家帮忙!

4

1 回答 1

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。But callback(null, event);is insideif语句,因此没有执行,因为event.triggerSourceis not "CustomMessage_ForgotPassword"

通过将语句放在callback(null, event);外部来if解决这个问题解决了整个问题。

如果它们最后总是执行,我建议检查你的其他 lambda callback(null, event),因为错误可能是由与你预期不同的 lambda 引起的。

于 2020-01-09T14:23:32.647 回答