Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda error on Cognito User Pool trigger

I'm trying to insert a record into DynamoDB invoking "Pre sign-up" trigger of Cognito User Pool.

Lambda function is pretty simple for testing purposes but there is always an error in client application on AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool.signUp call

Use case 1

Lambda body:

console.log('Received event:', JSON.stringify(event, null, 2));

Result:

InvalidLambdaResponseException: Invalid lambda function output : Invalid JSON

Use case 2

Lambda body:

callback("null", "success");

Result:

InvalidLambdaResponseException: Invalid lambda function output : Invalid JSON

Use case 3

Lambda body:

new AWS.DynamoDB.DocumentClient().put(params, callback);

Result:

InvalidLambdaResponseException: Invalid cognito sign in version. Version should be 1

So, any ideas what might be wrong?

Could the latest error might be related to the beta status of Cognito User Pool?

P.S. I will provide more details if needed. Thanks in advance.

like image 995
Stanislau Avatar asked May 24 '16 21:05

Stanislau


People also ask

How do you connect Lambda to Cognito?

Go to the Amazon Cognito console , and then choose User Pools. Choose an existing user pool from the list, or create a user pool. Choose the User pool properties tab and locate Lambda triggers. Choose Add a Lambda trigger.

How do I allow API users to run AWS Lambda with their Amazon Cognito permissions?

To allow users to run Lambda with their Amazon Cognito permissions, follow these steps: Use the API Gateway console to establish your Amazon Cognito user pool as an authorizer. Then, assign the Amazon Cognito user pool as the authorizer for the method of your API.

How do you trigger a lambda function?

You can invoke Lambda functions directly using the Lambda console, a function URL HTTP(S) endpoint, the Lambda API, an AWS SDK, the AWS Command Line Interface (AWS CLI), and AWS toolkits.

Why does AWS Lambda timeout?

There are three reasons why retry and timeout issues occur when invoking a Lambda function with an AWS SDK: A remote API is unreachable or takes too long to respond to an API call. The API call doesn't get a response within the socket timeout.


1 Answers

You are doing this in node.js and the error indicates you are not returning the service expected event source.

You should call context.done() when your lambda function finishes execution. Also, in any of the trigger sources which Cognito User Pool service generates, you can only edit the "response" part of the the source. For example, "autoConfirmUser" flag in PreSignUp trigger source.

Look at the examples in our developer guide for more details on this.

like image 135
Chetan Mehta Avatar answered Sep 25 '22 17:09

Chetan Mehta