Migrating Users from one AWS Cognito Pool to another keeping the CognitoId/Sub value

Viewed 1642

A recent-ish release of AWS Cognito has now allowed for case insensitivity for username input however you can't enable it on a current User Pool and requires to create a new User Pool and then migrate the users to it...

So, I've created a new user pool and have a Migration lambda working successfully but I've hit one final issue. We use the CognitoId as a Primary Key within our other systems and now when I migrate the from UserPool A to UserPool B, it creates a new CognitoId and it doesn't seem possible (from what I can see) to manually set the CognitoId / Sub as the value from the previous pool in the new pool.

Has anyone come across this before and have a work around as it's not easily feasible to update all references to a new key. (The new CognitoId isn't returned to any function in the process either)

1 Answers

Cognito Sub is generated internally by the service when the user is created. It is immutable and cannot be assigned a new value. One approach to store "sub" from the old userpool could be to store it in a custom attribute of new userpool. You can check for the custom attribute claim in the ID token to access the user data from your existing system.

Custom attribute is only available in Cognito ID token. If you are currently using Cognito access token with your other systems, this approach won't work for you.

Related