Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito delete all users from a user pool

How can we delete all users from a specific user pool in AWS Cognito using AWS CLI?

like image 793
ajilpm Avatar asked Mar 04 '20 06:03

ajilpm


People also ask

How do I delete all users on Cognito user pool?

You must have jq installed and remember to make the script executable: chmod +x deleteAllUsers.sh . The user pool id can be provided as a command line argument: ./deleteAllUsers.sh COGNITO_USER_POOL_ID . Thanks, this is perfect.

How do I delete an unconfirmed user on Cognito?

You can delete the unconfirmed users by calling a lambda function every 7 days using CloudWatch event trigger. In the lambda function you can use listUsers api to list all the cognito users and adminDeleteUser api to delete the unconfirmed users.

What is the main difference between Cognito user pool and Cognito identity pool?

With a user pool, your app users can sign in through the user pool or federate through a third-party identity provider (IdP). Identity pools are for authorization (access control). You can use identity pools to create unique identities for users and give them access to other AWS services.


2 Answers

try with below:

aws cognito-idp list-users --user-pool-id $COGNITO_USER_POOL_ID |
jq -r '.Users | .[] | .Username' |
while read uname1; do
  echo "Deleting $uname1";
  aws cognito-idp admin-delete-user --user-pool-id $COGNITO_USER_POOL_ID --username $uname1;
done
like image 196
GRVPrasad Avatar answered Sep 29 '22 23:09

GRVPrasad


In order to speed up deletion, I modified @GRVPrasad's answer to use xargs -P which will farm deletions out to multiple processes.

aws cognito-idp list-users --user-pool-id $COGNITO_USER_POOL_ID | jq -r '.Users | .[] | .Username' | xargs -n 1 -P 5 -I % bash -c "echo Deleting %; aws cognito-idp admin-delete-user --user-pool-id $COGNITO_USER_POOL_ID --username %"
like image 26
Richard Nienaber Avatar answered Sep 30 '22 01:09

Richard Nienaber