Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito - run another lambda after migration lambda has run

Cognito has a migration lambda that allows us to confirm a user in our db. They send the email and PW to Cognito, the lambda fires, we verify matches, and the user is entered into Cognito.

At this point - behind the scenes - Cognito generates a username of some kind (UUID). The problem is, I need a way to get this username into our existing database, because our systems going forward will no longer rely on email and instead rely on this username.

Ideal flow:

  • Sign In
  • Migration Succeeds
  • Cognito generates username
  • Username is sent to our server.

Now because we have email set to auto-verified, no post-confirmation lambda can be called. The only way I see to do this with Cognito as-is is to either:

  1. Ask users who already exist in our system to confirm their email again. This is a non-starter
  2. Create a post-auth lambda, check user login count through a custom attribute, and if 0 (or if not already registered with the service, etc.) migrate the username to the new service.

If there is any other way to do this, please let me know.

like image 414
JapanRob Avatar asked Nov 16 '25 13:11

JapanRob


1 Answers

After the user migration lambda is called your pre sign-up lambda will be called, assuming you have implemented it. The parameters received by your lambda will include username with the value being the UID you referenced. Parameters will also include user attributes containing email. You can use this information to update your database.

like image 107
Alex Avatar answered Nov 18 '25 08:11

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!