【问题标题】:Aws Cognito Presignup trigger fails with InvalidLambdaResponseExceptionAws Cognito Presignup 触发器因 InvalidLambdaResponseException 而失败
【发布时间】:2019-10-28 14:32:12
【问题描述】:

我的注册前触发 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。尝试了最后两行中的一个或两个。

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

请各位高手帮忙!

【问题讨论】:

    标签: amazon-cognito amazon-cognito-triggers


    【解决方案1】:

    我遇到了同样的问题,结果发现错误是由我的 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 语句之外来解决这个问题,解决了整个问题。

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

    【讨论】:

      猜你喜欢
      • 2021-11-05
      • 2018-06-17
      • 2020-07-02
      • 2019-05-15
      • 2017-10-24
      • 1970-01-01
      • 2020-12-31
      • 2021-09-21
      • 2023-01-01
      相关资源
      最近更新 更多