Skip to content

Instantly share code, notes, and snippets.

@johnestima
Created August 21, 2020 17:21
Show Gist options
  • Save johnestima/57b543fa62565e7332690fa293734448 to your computer and use it in GitHub Desktop.
Save johnestima/57b543fa62565e7332690fa293734448 to your computer and use it in GitHub Desktop.
Cognito delete all users from user pool
#!/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
@drilonibrahimi
Copy link

Thanks, this worked perfectly!

@wadinj
Copy link

wadinj commented Jun 28, 2021

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

@MoinuddinOps
Copy link

Thanks, man, it helped!

@ShivamJoker
Copy link

Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment