【问题标题】:AWS Java Lambda Cognito - Invalid lambda trigger sourceAWS Java Lambda Cognito - 无效的 lambda 触发器源
【发布时间】:2018-03-11 08:15:00
【问题描述】:

从网页登录到 Cognito 有效,我得到了访问令牌和 id 令牌。现在我想在登录时运行一个 Lambda 函数并访问用户的一些数据,但在这里它失败了.. 我得到InvalidLambdaResponseException: Invalid lambda trigger source

关于造成这种情况的任何想法?

Java Lambda 代码是这样的:

public class LambdaFunctionHandler implements RequestHandler<CognitoEvent, CognitoEvent> {

@Override
public CognitoEvent handleRequest(CognitoEvent event, Context context) 
{
    context.getLogger().log("Input: " + event);

   return event;
}

}

Javascript:

function loginCognito()
    {
        AWSCognito.config.region = 'us-east-1';
        var authenticationData = {
            Username : '***',
            Password : '***',
        };
        var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
        var poolData = { UserPoolId : 'us-east-1*********',
            ClientId : '*******************'
        };
        var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
        var userData = {
            Username : '***',
            Pool : userPool
        };
        var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
        cognitoUser.authenticateUser(authenticationDetails, 
        {
            onSuccess: function (result) {
                /* ... */
            },
            onFailure: function(err) {
                alert(err);
            }
        });
    }

【问题讨论】:

  • 您使用什么 Cognito Lambda 触发器?您有任何可用的请求 ID、AWS 区域和时间戳吗?
  • @VasileiosLekakis 在用户池/“我的池”/触发器中,我在“身份验证后”下选择了我的 lambda 函数。我使用 javascript 登录(查看最新更新)

标签: java amazon-web-services lambda aws-lambda amazon-cognito


【解决方案1】:

在不太了解您正在尝试执行的操作的具体细节的情况下,并且根据您返回的错误,我相信 triggerSource 在以下值之一中没有值:

PreSignUp_SignUp、PostConfirmation_ConfirmSignUp、PostConfirmation_ConfirmForgotPassword、PreAuthentication_Authentication、 PostAuthentication_Authentication、CustomMessage_SignUp、CustomMessage_AdminCreateUser、CustomMessage_ResendCode、CustomMessage_ForgotPassword、CustomMessage_UpdateUserAttribute、CustomMessage_VerifyUserAttribute、CustomMessage_Authentication、DefineAuthChallenge_Authentication、CreateAuthChallenge_Authentication、VerifyAuthChallengeResponse_Authentication

http://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html#cognito-user-pools-lambda-trigger-syntax-shared

现在这不起作用的原因是CognitoEventCognitoSync 服务的模板(示例),而不是您使用的用户池。目前我们不提供输入事件的 JAVA 示例。

要让它工作,你需要有一个可以序列化以下 JSON 的输入对象

{
  "version": 1,
  "triggerSource": "PostAuthentication_Authentication",
  "region": "<region>",
  "userPoolId": "<userPoolId>",
  "userName": "<userName>",
  "callerContext": {
      "awsSdk": "<calling aws sdk with version>",
      "clientId": "<apps client id>",
      ...
  },
  "request": {
      "userAttributes": {
          "phone_number_verified": true,
          "email_verified": true,
          ... //all custom attributes
      }
  },
  "response": {}
};

【讨论】:

  • 所以我应该在请求中发送例如“PostAuthentication_Authentication”? ...这是有道理的:)
  • 不确定“triggerSource 没有值”是什么意思。政策?拉姆达?我仍然有同样的错误
  • 你能试试我们在文档中的认证后的例子,看看你是否得到同样的错误?
  • 我得到“未定义出口”
  • 当然!我加入了你的聊天
猜你喜欢
  • 2023-01-01
  • 2019-06-12
  • 2020-08-15
  • 2018-03-10
  • 2018-06-17
  • 2018-03-04
  • 2018-04-02
  • 2019-01-11
  • 2016-09-22
相关资源
最近更新 更多