【问题标题】:Unrecognizable Lambda Output Cognito无法识别的 Lambda 输出认知
【发布时间】:2017-07-31 02:52:57
【问题描述】:

我正在尝试在 AWS 中实施自动确认机制,但由于 Lambda 响应而出现错误。我在文档中找不到正确的返回类型。

拉姆达:

exports.handler = (event, context, callback) => {
    event.response.autoConfirmUser = true;
    context.succeed(event.response);
};

例外:

无法识别的 lambda 输出(服务: AWSCognitoIdentityProviderService;状态码:400;错误代码: 无效的Lambda响应异常;请求编号: 5c7a2436-0515-11e7-b971-41a89adf53ea)

【问题讨论】:

    标签: aws-lambda amazon-cognito


    【解决方案1】:

    如 Cognito 开发者指南中的PreSignUp trigger example 所示,您应该在触发器末尾使用context.done(null, event);context.succeed(event);

    Cognito 期望返回完整的事件源,以响应作为不同 Cognito 用户池流的一部分调用的 lambda 触发器。

    【讨论】:

    • @Chetan Java 中的等价物是什么?
    • @Chetan,Java 中有这方面的例子吗?
    • 我在这个问题上需要帮助stackoverflow.com/questions/49002115/…
    • dotnet core 中的等价物是什么?
    • 我在 api 调用中收到此错误 - 我的 lambda 应该更改忘记密码 - 我正在使用 Java sdk - 请帮助
    【解决方案2】:

    Ruby lambda 人,所有 cognito 想要的只是事件对象。

    def lambda_handler(event:, context:)
        # TODO implement
        return event
    end

    【讨论】:

    • 与python相同。
    • 知道如何传回错误消息吗?我正在使用 python 并返回事件以表示成功,但不确定如何传回错误消息。对事件的任何更改都会导致“无法识别的 lambda 输出”错误。 *我正在使用 Cognito 托管的 UI 选项,这就是为什么将显示在注册页面上的有意义的错误消息传回对我来说很重要的原因。 @BLang
    • @Stasv 在此处查看我对您问题的回答:stackoverflow.com/questions/50661422/…
    【解决方案3】:

    很简单。

    1. 使用此代码创建一个 Lambda 函数:example

      exports.handler = function(event, context) {
      
      /* This Lambda function returns a flag to indicate if a user should be auto-confirmed.
      Perform any necessary validations.Impose a condition that the minimum length of the
      username of 5 is imposed on all user pools. */
      
         if (event.userName.length < 5) {
            var error = new Error('failed!');
            context.done(error, event);
         }
      
      /* Access your resource which contains the list of emails of users who were invited to
      sign up. Compare the list of email IDs from the request to the approved list */
      
         if(event.userPoolId === "yourSpecialUserPool") {
            if (event.request.userAttributes.email in listOfEmailsInvited) {
                 event.response.autoConfirmUser = true;
            }
         }
      
         // Return result to Cognito
         context.done(null, event);
      };
      

    注意:作用:Lambda基本执行

    1. 从 cognito 控制台创建触发器并选择函数 lambda。

    测试 3. 使用 API 创建用户并完成。

    【讨论】:

      猜你喜欢
      • 2020-11-06
      • 2022-01-15
      • 2020-04-26
      • 1970-01-01
      • 2013-06-12
      • 1970-01-01
      • 2023-03-15
      • 2019-03-15
      • 1970-01-01
      相关资源
      最近更新 更多