简体   繁体   中英

How can I store aws cognito user after sign up in a mongodb database?

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.

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM