简体   繁体   English

AWS Java Lambda Cognito-无效的lambda触发源

[英]AWS Java Lambda Cognito - Invalid lambda trigger source

Logging in to Cognito from a web page works, I get both access token back and id token. 从网页登录到Cognito可行,我同时获得了访问令牌和id令牌。 Now I want to run a Lambda function upon login and access some data on the user, but here it fails.. I get InvalidLambdaResponseException: Invalid lambda trigger source . 现在,我想在登录时运行Lambda函数并访问用户上的某些数据,但是这里失败了。我得到InvalidLambdaResponseException: Invalid lambda trigger source

Any ideas on what's causing this? 关于什么原因的任何想法?

The Java Lambda code is just this: 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: 使用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);
            }
        });
    }

Without knowing too much about the specifics of what you are trying to do and based on the error you are getting back I believe that the triggerSource does not have a value in one of the value: 在不了解您要做什么的细节以及基于错误的情况下,您会回来的,我相信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 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,AuthenticAuthChallenge_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 http://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html#cognito-user-pools-lambda-trigger-syntax-共享

Now the reason this does not work is that the CognitoEvent is a template (example) for the CognitoSync service and not for the userPools that you use. 现在,这样做不起作用的原因是CognitoEventCognitoSync服务而不是您使用的userPool的模板(示例)。 Currently we do not provide a JAVA example of the input event. 当前,我们没有提供输入事件的JAVA示例。

To make it work, you need to have an input object that can serialize the following JSON 要使其工作,您需要具有一个可以序列化以下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": {}
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM