2017-09-29 45 views
0

WebページからCognitoにログインすると、アクセストークンバックとIDトークンの両方が取得されます。今私はログイン時にラムダ関数を実行し、ユーザーのデータにアクセスしたいが、ここでは失敗する。 InvalidLambdaResponseException: Invalid lambda trigger sourceが得られる。AWS Java Lambda Cognito - 無効なラムダトリガソース

これを引き起こす原因に関するアイデアはありますか?あなたがやろうとしているとエラーに基づいて、あなたが取得しているかの詳細についてはあまり知らない

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); 
      } 
     }); 
    } 
+0

をシリアル化することができ、入力オブジェクトを持っている必要がありますか?リクエストID、aws地域、タイムスタンプがありますか? –

+0

@VasileiosLekakisユーザープール/ "my pool"/Triggersでは、 "Post authentication"の下でラムダ機能を選択しました。私はログインするためにjavascriptを使用しています(最新のアップデートを参照) –

答えて

1

public class LambdaFunctionHandler implements RequestHandler<CognitoEvent, CognitoEvent> { 

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

    return event; 
} 

} 

Javascriptを:

Javaのラムダ・コードは、単にこれです私は、triggerSourceが値の1つに値を持たないと信じています:

PreSignUp_SignUp、PostConfirmation_ConfirmSignUp、PostConfirmation_ConfirmForgotPasswor D、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

は今、これが動作しない理由は、(CognitoEventがテンプレートであるということですたとえば、CognitoSyncサービスで、使用しているuserPoolsでは使用できません。現在、入力イベントのJAVAの例は提供していません。

それを動作させるには、次のJSONあなたが使用しているものCognitoラムダトリガー

{ 
    "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": {} 
}; 
+0

リクエストに「PostAuthentication_Authentication」などのサンプルを送信する必要がありますか? ...意味があります:) –

+0

"triggerSourceには値がありません"という意味が不明です。ポリシー?ラムダ?私はまだ同じエラーが発生しています –

+0

あなたは私たちがマニュアルで持っている事後認証の例を試してみて、あなたが同じエラーを受けているかどうか確認できますか? –

関連する問題