How can we delete all users from a specific user pool in AWS Cognito using AWS CLI?
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.
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.
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.
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
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 %"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With