Created
August 21, 2020 17:21
-
-
Save johnestima/57b543fa62565e7332690fa293734448 to your computer and use it in GitHub Desktop.
Cognito delete all users from user pool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USER_POOL_ID=POOL_ID | |
RUN=1 | |
until [ $RUN -eq 0 ] ; do | |
echo "Listing users" | |
USERS=`aws cognito-idp list-users --user-pool-id ${USER_POOL_ID} | grep Username | awk -F: '{print $2}' | sed -e 's/\"//g' | sed -e 's/,//g'` | |
if [ ! "x$USERS" = "x" ] ; then | |
for user in $USERS; do | |
echo "Deleting user $user" | |
aws cognito-idp admin-delete-user --user-pool-id ${USER_POOL_ID} --username ${user} | |
echo "Result code: $?" | |
echo "Done" | |
done | |
else | |
echo "Done, no more users" | |
RUN=0 | |
fi | |
done |
Hi,
To make it work:
add --output json to the list-users command if not set.
aws cognito-idp list-users --user-pool-id ${USER_POOL_ID} --output json
Thanks, man, it helped!
Great work!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, this worked perfectly!