Cognito UserPool Sub or IdentityPool ID as the User ID?

/r/serverless/comments/gei5kp/cognito_userpool_sub_or_identitypool_id_as_the/

Is there a reason why you want to store the basket of a guest user on DynamoDB instead of the sessionStorage/localStorage? If it’s a guest user, how do you expect to find the basket over multiple sessions?

Use the sub.

You can use cognito triggers to move the data over to DynamoDB at the right times. Not perfect.

In short, use the sub.

Some pitfalls:

  • As far as I know, you can’t tell Cognito to use a sub that you provide. It is generated at signup.
  • There are limits to how many times you can query the Cognito API to get profile informations from a sub.

A solution could be to store your basket in a DynamoDB who’s key is a UUID that you have made. When the user signup, you would, with a “Post confirmation” trigger, associate the sub provided by Cognito to the UUID that you’ve made in that same table.

You’d then be able to access the basket either by sub (in an index) or your own ID (as primary key).