Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unrecognizable Lambda Output Cognito

I am trying to implement an auto confirm mechanism in AWS, I'm getting an error due to the Lambda response. I can't find the correct return type in the docs.

Lambda:

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

Exception:

Unrecognizable lambda output (Service: AWSCognitoIdentityProviderService; Status Code: 400; Error Code: InvalidLambdaResponseException; Request ID: 5c7a2436-0515-11e7-b971-41a89adf53ea)

like image 882
KnowHoper Avatar asked Mar 09 '17 22:03

KnowHoper


3 Answers

As shown in the PreSignUp trigger example in Cognito developer guide, you should use context.done(null, event); or context.succeed(event); at the end of your trigger.

Cognito expects the complete event source back in response from your lambda triggers being invoked as part of different Cognito User Pools flows.

like image 87
Chetan Mehta Avatar answered Nov 17 '22 04:11

Chetan Mehta


Ruby lambda people, all cognito wants back is the event object.

def lambda_handler(event:, context:)
    # TODO implement
    return event
end
like image 23
Chris Avatar answered Nov 17 '22 02:11

Chris


Is very simple.

  1. Create a Lambda Function with this code : 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);
    };
    

Note: Role: Lambda basic execution

  1. Create the trigger from cognito console and select the function lambda.

TEST 3. Create the user with the API and DONE.

like image 3
Roberto Carlos Reyes Fernandez Avatar answered Nov 17 '22 04:11

Roberto Carlos Reyes Fernandez