0

I want to store my users after they sign up in a mongodb database. I am using aws cognito. I found that you can create a lamda function that can run after "post confirmation". can anyone tell me how can I do that? from what I understand:

  1. I can create a api endpoint(node js) that saves users in mongodb.
  2. this endpoint will send the user data using aws lamda after "post confirmation".

I am looking for solutions.

Sajib Hossain
  • 81
  • 2
  • 8

1 Answers1

0
  1. Create a new Lambda function that can save data into your MongoDB
  2. Set this Lambda as the Post confirmation Lambda trigger in your Cognito User Pool
  3. Implement the Lambda to use the event Cognito passes to your Lambda function to save the data into your database

Your Lambda function will look like

const { MongoClient } = require('mongodb');

exports.handler = (event, context, callback) => {
    // Get user attributes from the event
    const email = event.request.userAttributes.email;
    
    // Connect to MongoDB and save the user
    
    // Return to Amazon Cognito
    callback(null, event);
};

See: See: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-post-confirmation.html

Brian
  • 1,056
  • 9
  • 15
  • Thank you Brian. can you tell me about how will this lamda function look like? 1.I can create an api endpoint(node js) that saves users in mongodb. 2. this endpoint will send the user data using aws lamda after "post confirmation". – Sajib Hossain Dec 27 '22 at 07:45
  • Added an example Lambda function. You can find more details in the doc I linked. – Brian Dec 27 '22 at 07:50