Created
September 22, 2023 12:50
-
-
Save leandro-hermes/1e70ea0c67c4c0d5c94a68e00374922c to your computer and use it in GitHub Desktop.
Delete Cognito users from a pool, filtering by testing e-mails
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/sh | |
USER_POOL_ID=XXXXXXXXXX | |
REGION=us-east-1 | |
PROFILE=XXXXXXXXXX | |
EMAIL_SUFFIX=@uorak.com | |
USERS=$(aws \ | |
--profile $PROFILE \ | |
--region $REGION \ | |
cognito-idp list-users \ | |
--user-pool-id $USER_POOL_ID \ | |
--output json \ | |
| jq -r '.Users[] | select(.Attributes[] | select(.Name == "email").Value | endswith("'"$EMAIL_SUFFIX"'")) | .Username' | |
) | |
for USER in $USERS; do | |
# delete users | |
aws \ | |
--profile $PROFILE \ | |
--region $REGION \ | |
cognito-idp admin-delete-user \ | |
--user-pool-id $USER_POOL_ID \ | |
--username $USER | |
echo "Deleted user: $USER" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment