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)
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.
Ruby lambda people, all cognito wants back is the event object.
def lambda_handler(event:, context:)
# TODO implement
return event
end
Is very simple.
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
TEST 3. Create the user with the API and DONE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With