What are the pros and cons of using Cognito-id (Cognito sub) as a primary key?


I am currently building a Django app that uses AWS Cognito for auth.

I am having a hard time understanding the pros and cons of using Cognito-sub as the primary key for my user table versus using a generic uuid4 + cognitio_id field.

What are some edge cases that might make this a bad idea? One thing came to mind is if I accidentally deleted my Cognito User Pool it would be very hard to recover my user db.

asked 3 months ago20 views
1 Answer


You have basically identified the primary reason not to use the Sub attribute. If you need to migrate user pools, replicate users to another region, restore expected users, etc. the sub would be different so therefore it's typically a bad idea to use it as a key. A UUID with the Cognito ID provides more protection against this. The only downside of this is that you still have to create the unique key yourself but it avoids any issues in the event you have to recover the pool.

Thanks, Owen

answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions