AWS Cognito user pool - total users count and querying

Viewed 1364

I am working on an application which uses Cognito as the identity provider.

I have a requirement to get the total count of users from Cognito to display on UI. But the problem is Cognito doesn't provide total number of users, it does however give estimated number of users from describe user pool api. What I don't understand is why the "estimated" count and not the exact? Is it because of federated users?

Anyone if using an identity provider, will not have users in their own application (or will they?). So why the querying capability of Cognito is so basic ? For handling such scenarios should one have a copy of users in their own application as well? But in this case the challenge is how to sync the users? App Sync is there for identity pool only but not user pool.

2 Answers

I have had the same doubt as yours. What I've seen is that the Cognito API doesn't have an endpoint to specifically meet your need.

What you should (in a traditional way) is to use a ListUser (you may have to use it several times) and when you get all the users then the length of your array will be the total number of users.

The solution I found is:

  1. Create a table in my Database where I can keep that statistic, that is, a counter with the number of confirmed or registered users (it depends on your requirements) of my User Pool.
  2. Launch a trigger every time a user is Confirmed and in the associated lambda I modify the counter (increment it) in the aforementioned table. The trigger can be configured from the User Pool itself, in the Triggers section.

You can get the total user count using the DescribeUserPool API provided by AWS SDK. The user count is denoted by the key EstimatedNumberOfUsers in the result

You can find more details here - DescribeUserPool AWS SDK

Related