0

웹 페이지에서 Cognito에 로그인하면 작동 토큰 백 및 ID 토큰을 모두받습니다. 이제 로그인 할 때 람다 (Lambda) 함수를 실행하고 사용자의 일부 데이터에 액세스하려고합니다. 그러나 여기에서는 실패합니다. 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"아래에서 람다 함수를 선택했습니다. 나는 로그인 (최신 업데이트를 참조하십시오) 자바 스크립트를 사용하여 –

답변

1

당신이 점점 오류에 따라 :

public class LambdaFunctionHandler implements RequestHandler<CognitoEvent, CognitoEvent> { 

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

    return event; 
} 

} 

자바 스크립트 :

자바 람다 코드는 바로 이것이다 다시 나는 triggerSource 값 중 하나에 값이없는 것으로 생각 :

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

우리는 문서에있는 사후 인증의 예를 시도해 볼 수 있으며 동일한 오류가 발생하는지 확인하십시오. –